Skip to content

Commit

Permalink
Merge pull request #93 from vulcanize/v1.10.4-statediff-0.0.24
Browse files Browse the repository at this point in the history
Merge v1.10.4-statediff-0.0.24 to v1.10.4-statediff
  • Loading branch information
arijitAD authored Jul 1, 2021
2 parents 3abcc56 + 0f14f51 commit 9087770
Show file tree
Hide file tree
Showing 16 changed files with 393 additions and 80 deletions.
1 change: 1 addition & 0 deletions .github/workflows/on-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Docker Build and publish to Github
on:
push:
branches:
- v1.10.4-statediff
- v1.10.3-statediff
- v1.10.2-statediff
- v1.10.1-statediff
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/go-stack/stack v1.8.0
github.com/golang/protobuf v1.4.3
github.com/golang/snappy v0.0.3
github.com/google/go-cmp v0.5.4 // indirect
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa
github.com/google/uuid v1.1.5
github.com/gorilla/websocket v1.4.2
Expand Down Expand Up @@ -61,8 +62,10 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
github.com/prometheus/tsdb v0.7.1
github.com/r3labs/diff/v2 v2.13.1 // indirect
github.com/rjeczalik/notify v0.9.1
github.com/rs/cors v1.7.0
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
github.com/stretchr/testify v1.7.0
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/r3labs/diff/v2 v2.13.1 h1:o0mlcYwUKTeL6jVblu42vCnXS7gfArPKYJCs4qkwOw8=
github.com/r3labs/diff/v2 v2.13.1/go.mod h1:I8noH9Fc2fjSaMxqF3G2lhDdC0b+JXCfyx85tWFM9kc=
github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc=
github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE=
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
Expand All @@ -408,6 +410,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
Expand All @@ -428,6 +432,7 @@ github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 h1:xQdMZ1WLrgkkvOZ/LDQxjVxMLdby7osSh4ZEVa5sIjs=
Expand All @@ -440,6 +445,8 @@ github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZF
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef h1:wHSqTBrZW24CsNJDfeh9Ex6Pm0Rcpc7qrgKBiL44vF4=
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM=
github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
Expand Down Expand Up @@ -636,6 +643,8 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc=
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
VersionMajor = 1 // Major version component of the current release
VersionMinor = 10 // Minor version component of the current release
VersionPatch = 4 // Patch version component of the current release
VersionMeta = "statediff-0.0.23" // Version metadata to append to the version string
VersionMeta = "statediff-0.0.24" // Version metadata to append to the version string
)

// Version holds the textual version string.
Expand Down
48 changes: 24 additions & 24 deletions statediff/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,9 @@ var (
emptyStorage = make([]sdtypes.StorageNode, 0)
block0, block1, block2, block3, block4, block5, block6 *types.Block
builder statediff.Builder
miningReward = int64(2000000000000000000)
minerAddress = common.HexToAddress("0x0")
minerLeafKey = testhelpers.AddressToLeafKey(minerAddress)

balanceChange10000 = int64(10000)
balanceChange1000 = int64(1000)
block1BankBalance = int64(99990000)
block1Account1Balance = int64(10000)
block2Account2Balance = int64(1000)

slot0 = common.HexToHash("0")
slot1 = common.HexToHash("1")
slot2 = common.HexToHash("2")
Expand Down Expand Up @@ -129,7 +122,7 @@ var (

minerAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{
Nonce: 0,
Balance: big.NewInt(miningReward),
Balance: big.NewInt(2000002625000000000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -139,7 +132,7 @@ var (
})
minerAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{
Nonce: 0,
Balance: big.NewInt(miningReward + miningReward),
Balance: big.NewInt(4000111203461610525),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -150,7 +143,7 @@ var (

account1AtBlock1, _ = rlp.EncodeToBytes(state.Account{
Nonce: 0,
Balance: big.NewInt(balanceChange10000),
Balance: testhelpers.Block1Account1Balance,
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -160,7 +153,7 @@ var (
})
account1AtBlock2, _ = rlp.EncodeToBytes(state.Account{
Nonce: 2,
Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000),
Balance: big.NewInt(999555797000009000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -170,7 +163,7 @@ var (
})
account1AtBlock5, _ = rlp.EncodeToBytes(state.Account{
Nonce: 2,
Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000 + miningReward),
Balance: big.NewInt(2999566008847709960),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -180,7 +173,7 @@ var (
})
account1AtBlock6, _ = rlp.EncodeToBytes(state.Account{
Nonce: 3,
Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000 + miningReward),
Balance: big.NewInt(2999537516847709960),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -191,7 +184,7 @@ var (

account2AtBlock2, _ = rlp.EncodeToBytes(state.Account{
Nonce: 0,
Balance: big.NewInt(balanceChange1000),
Balance: big.NewInt(1000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -201,7 +194,7 @@ var (
})
account2AtBlock3, _ = rlp.EncodeToBytes(state.Account{
Nonce: 0,
Balance: big.NewInt(block2Account2Balance + miningReward),
Balance: big.NewInt(2000013574009435976),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -211,7 +204,7 @@ var (
})
account2AtBlock4, _ = rlp.EncodeToBytes(state.Account{
Nonce: 0,
Balance: big.NewInt(block2Account2Balance + miningReward*2),
Balance: big.NewInt(4000048088163070348),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -221,7 +214,7 @@ var (
})
account2AtBlock6, _ = rlp.EncodeToBytes(state.Account{
Nonce: 0,
Balance: big.NewInt(block2Account2Balance + miningReward*3),
Balance: big.NewInt(6000063293259748636),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -240,19 +233,23 @@ var (
common.Hex2Bytes("2000bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
bankAccountAtBlock0,
})

block1BankBalance = big.NewInt(testhelpers.TestBankFunds.Int64() - testhelpers.BalanceChange10000 - testhelpers.GasFees)
bankAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{
Nonce: 1,
Balance: big.NewInt(testhelpers.TestBankFunds.Int64() - balanceChange10000),
Balance: block1BankBalance,
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
bankAccountAtBlock1LeafNode, _ = rlp.EncodeToBytes([]interface{}{
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
bankAccountAtBlock1,
})

block2BankBalance = block1BankBalance.Int64() - testhelpers.BalanceChange1Ether - testhelpers.GasFees
bankAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{
Nonce: 2,
Balance: big.NewInt(block1BankBalance - balanceChange1000),
Balance: big.NewInt(block2BankBalance),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -262,7 +259,7 @@ var (
})
bankAccountAtBlock3, _ = rlp.EncodeToBytes(state.Account{
Nonce: 3,
Balance: big.NewInt(99989000),
Balance: big.NewInt(999914255999990000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -272,7 +269,7 @@ var (
})
bankAccountAtBlock4, _ = rlp.EncodeToBytes(state.Account{
Nonce: 6,
Balance: big.NewInt(99989000),
Balance: big.NewInt(999826859999990000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -282,7 +279,7 @@ var (
})
bankAccountAtBlock5, _ = rlp.EncodeToBytes(state.Account{
Nonce: 7,
Balance: big.NewInt(99989000),
Balance: big.NewInt(999805027999990000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand Down Expand Up @@ -1706,10 +1703,12 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
if err != nil {
t.Error(err)
}

expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
if err != nil {
t.Error(err)
}

sort.Slice(receivedStateDiffRlp, func(i, j int) bool { return receivedStateDiffRlp[i] < receivedStateDiffRlp[j] })
sort.Slice(expectedStateDiffRlp, func(i, j int) bool { return expectedStateDiffRlp[i] < expectedStateDiffRlp[j] })
if !bytes.Equal(receivedStateDiffRlp, expectedStateDiffRlp) {
Expand Down Expand Up @@ -1740,7 +1739,7 @@ var (

bankAccountAtBlock01, _ = rlp.EncodeToBytes(state.Account{
Nonce: 1,
Balance: big.NewInt(testhelpers.TestBankFunds.Int64() + miningReward),
Balance: big.NewInt(3999629697375000000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand All @@ -1750,7 +1749,7 @@ var (
})
bankAccountAtBlock02, _ = rlp.EncodeToBytes(state.Account{
Nonce: 2,
Balance: big.NewInt(testhelpers.TestBankFunds.Int64() + miningReward*2),
Balance: big.NewInt(5999607323457344852),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Root: testhelpers.EmptyContractRoot,
})
Expand Down Expand Up @@ -1926,6 +1925,7 @@ func TestBuilderWithMovedAccount(t *testing.T) {
if err != nil {
t.Error(err)
}

sort.Slice(receivedStateDiffRlp, func(i, j int) bool { return receivedStateDiffRlp[i] < receivedStateDiffRlp[j] })
sort.Slice(expectedStateDiffRlp, func(i, j int) bool { return expectedStateDiffRlp[i] < expectedStateDiffRlp[j] })
if !bytes.Equal(receivedStateDiffRlp, expectedStateDiffRlp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CREATE TABLE eth.header_cids (
bloom BYTEA NOT NULL,
timestamp NUMERIC NOT NULL,
times_validated INTEGER NOT NULL DEFAULT 1,
base_fee BIGINT DEFAULT 0,
UNIQUE (block_number, block_hash)
);

Expand Down
33 changes: 21 additions & 12 deletions statediff/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"math/big"
"time"

"github.com/lib/pq"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -119,7 +117,13 @@ func (sdi *StateDiffIndexer) PushBlock(block *types.Block, receipts types.Receip
return nil, fmt.Errorf("expected number of transactions (%d), transaction trie nodes (%d), receipts (%d), and receipt trie nodes (%d)to be equal", len(txNodes), len(txTrieNodes), len(rctNodes), len(rctTrieNodes))
}
// Calculate reward
reward := CalcEthBlockReward(block.Header(), block.Uncles(), block.Transactions(), receipts)
var reward *big.Int
// in PoA networks block reward is 0
if sdi.chainConfig.Clique != nil {
reward = big.NewInt(0)
} else {
reward = CalcEthBlockReward(block.Header(), block.Uncles(), block.Transactions(), receipts)
}
t = time.Now()
// Begin new db tx for everything
tx, err := sdi.dbWriter.db.Beginx()
Expand Down Expand Up @@ -214,6 +218,12 @@ func (sdi *StateDiffIndexer) processHeader(tx *sqlx.Tx, header *types.Header, he
if err := shared.PublishIPLD(tx, headerNode); err != nil {
return 0, fmt.Errorf("error publishing header IPLD: %v", err)
}

var baseFee int64
if header.BaseFee != nil {
baseFee = header.BaseFee.Int64()
}

// index header
return sdi.dbWriter.upsertHeaderCID(tx, models.HeaderModel{
CID: headerNode.Cid().String(),
Expand All @@ -229,6 +239,7 @@ func (sdi *StateDiffIndexer) processHeader(tx *sqlx.Tx, header *types.Header, he
TxRoot: header.TxHash.String(),
UncleRoot: header.UncleHash.String(),
Timestamp: header.Time,
BaseFee: baseFee,
})
}

Expand All @@ -238,7 +249,13 @@ func (sdi *StateDiffIndexer) processUncles(tx *sqlx.Tx, headerID int64, blockNum
if err := shared.PublishIPLD(tx, uncleNode); err != nil {
return fmt.Errorf("error publishing uncle IPLD: %v", err)
}
uncleReward := CalcUncleMinerReward(blockNumber, uncleNode.Number.Uint64())
var uncleReward *big.Int
// in PoA networks uncle reward is 0
if sdi.chainConfig.Clique != nil {
uncleReward = big.NewInt(0)
} else {
uncleReward = CalcUncleMinerReward(blockNumber, uncleNode.Number.Uint64())
}
uncle := models.UncleModel{
CID: uncleNode.Cid().String(),
MhKey: shared.MultihashKeyFromCID(uncleNode.Cid()),
Expand Down Expand Up @@ -334,14 +351,6 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *sqlx.Tx, args processArgs
return err
}

// AccessListEntryModel is the db model for eth.access_list_entry
type AccessListElementModel struct {
ID int64 `db:"id"`
Index int64 `db:"index"`
TxID int64 `db:"tx_id"`
Address string `db:"address"`
StorageKeys pq.StringArray `db:"storage_keys"`
}
// index access list if this is one
for j, accessListElement := range trx.AccessList() {
storageKeys := make([]string, len(accessListElement.StorageKeys))
Expand Down
Loading

0 comments on commit 9087770

Please sign in to comment.