Skip to content

Commit

Permalink
Merge pull request #126 from vulcanize/v1.10.9-statediff-0.0.27
Browse files Browse the repository at this point in the history
Merge v1.10.9-statediff-0.0.27 to v1.10.9-statediff
  • Loading branch information
arijitAD authored Sep 30, 2021
2 parents 681d57a + 690eb15 commit aec0114
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ jobs:
linter-check:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: '1.16.x'
- uses: actions/checkout@v2
- name: Run linter
run: go run build/ci.go lint
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.9-statediff
- v1.10.8-statediff
- v1.10.7-statediff
- v1.10.6-statediff
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Run geth unit test
strategy:
matrix:
go-version: [ 1.15.x]
go-version: [ 1.16.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
env:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
GOPATH: /tmp/go
strategy:
matrix:
go-version: [ 1.15.x]
go-version: [ 1.16.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
8 changes: 4 additions & 4 deletions statediff/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (sdb *builder) buildStateTrie(it trie.NodeIterator) ([]StateNode, []CodeAnd
}
switch node.NodeType {
case Leaf:
var account state.Account
var account types.StateAccount
if err := rlp.DecodeBytes(nodeElements[1].([]byte), &account); err != nil {
return nil, nil, fmt.Errorf("error decoding account for leaf node at path %x nerror: %v", node.Path, err)
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func (sdb *builder) createdAndUpdatedState(a, b trie.NodeIterator, watchedAddres
if node.NodeType == Leaf {
// created vs updated is important for leaf nodes since we need to diff their storage
// so we need to map all changed accounts at B to their leafkey, since account can change pathes but not leafkey
var account state.Account
var account types.StateAccount
if err := rlp.DecodeBytes(nodeElements[1].([]byte), &account); err != nil {
return nil, nil, fmt.Errorf("error decoding account for leaf node at path %x nerror: %v", node.Path, err)
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func (sdb *builder) createdAndUpdatedStateWithIntermediateNodes(a, b trie.NodeIt
case Leaf:
// created vs updated is important for leaf nodes since we need to diff their storage
// so we need to map all changed accounts at B to their leafkey, since account can change paths but not leafkey
var account state.Account
var account types.StateAccount
if err := rlp.DecodeBytes(nodeElements[1].([]byte), &account); err != nil {
return nil, nil, fmt.Errorf("error decoding account for leaf node at path %x nerror: %v", node.Path, err)
}
Expand Down Expand Up @@ -401,7 +401,7 @@ func (sdb *builder) deletedOrUpdatedState(a, b trie.NodeIterator, diffPathsAtB m
switch node.NodeType {
case Leaf:
// map all different accounts at A to their leafkey
var account state.Account
var account types.StateAccount
if err := rlp.DecodeBytes(nodeElements[1].([]byte), &account); err != nil {
return nil, fmt.Errorf("error decoding account for leaf node at path %x nerror: %v", node.Path, err)
}
Expand Down
47 changes: 23 additions & 24 deletions statediff/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -79,7 +78,7 @@ var (
slot0StorageValue,
})

contractAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{
contractAccountAtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 1,
Balance: big.NewInt(0),
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
Expand All @@ -89,7 +88,7 @@ var (
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
contractAccountAtBlock2,
})
contractAccountAtBlock3, _ = rlp.EncodeToBytes(state.Account{
contractAccountAtBlock3, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 1,
Balance: big.NewInt(0),
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
Expand All @@ -99,7 +98,7 @@ var (
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
contractAccountAtBlock3,
})
contractAccountAtBlock4, _ = rlp.EncodeToBytes(state.Account{
contractAccountAtBlock4, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 1,
Balance: big.NewInt(0),
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
Expand All @@ -109,7 +108,7 @@ var (
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
contractAccountAtBlock4,
})
contractAccountAtBlock5, _ = rlp.EncodeToBytes(state.Account{
contractAccountAtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 1,
Balance: big.NewInt(0),
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
Expand All @@ -120,7 +119,7 @@ var (
contractAccountAtBlock5,
})

minerAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{
minerAccountAtBlock1, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: big.NewInt(2000002625000000000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -130,7 +129,7 @@ var (
common.Hex2Bytes("3380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a"),
minerAccountAtBlock1,
})
minerAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{
minerAccountAtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: big.NewInt(4000111203461610525),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -141,7 +140,7 @@ var (
minerAccountAtBlock2,
})

account1AtBlock1, _ = rlp.EncodeToBytes(state.Account{
account1AtBlock1, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: testhelpers.Block1Account1Balance,
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -151,7 +150,7 @@ var (
common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"),
account1AtBlock1,
})
account1AtBlock2, _ = rlp.EncodeToBytes(state.Account{
account1AtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 2,
Balance: big.NewInt(999555797000009000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -161,7 +160,7 @@ var (
common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"),
account1AtBlock2,
})
account1AtBlock5, _ = rlp.EncodeToBytes(state.Account{
account1AtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 2,
Balance: big.NewInt(2999566008847709960),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -171,7 +170,7 @@ var (
common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"),
account1AtBlock5,
})
account1AtBlock6, _ = rlp.EncodeToBytes(state.Account{
account1AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 3,
Balance: big.NewInt(2999537516847709960),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -182,7 +181,7 @@ var (
account1AtBlock6,
})

account2AtBlock2, _ = rlp.EncodeToBytes(state.Account{
account2AtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: big.NewInt(1000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -192,7 +191,7 @@ var (
common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"),
account2AtBlock2,
})
account2AtBlock3, _ = rlp.EncodeToBytes(state.Account{
account2AtBlock3, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: big.NewInt(2000013574009435976),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -202,7 +201,7 @@ var (
common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"),
account2AtBlock3,
})
account2AtBlock4, _ = rlp.EncodeToBytes(state.Account{
account2AtBlock4, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: big.NewInt(4000048088163070348),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -212,7 +211,7 @@ var (
common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"),
account2AtBlock4,
})
account2AtBlock6, _ = rlp.EncodeToBytes(state.Account{
account2AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: big.NewInt(6000063293259748636),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -223,7 +222,7 @@ var (
account2AtBlock6,
})

bankAccountAtBlock0, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock0, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 0,
Balance: big.NewInt(testhelpers.TestBankFunds.Int64()),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -235,7 +234,7 @@ var (
})

block1BankBalance = big.NewInt(testhelpers.TestBankFunds.Int64() - testhelpers.BalanceChange10000 - testhelpers.GasFees)
bankAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock1, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 1,
Balance: block1BankBalance,
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -247,7 +246,7 @@ var (
})

block2BankBalance = block1BankBalance.Int64() - testhelpers.BalanceChange1Ether - testhelpers.GasFees
bankAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 2,
Balance: big.NewInt(block2BankBalance),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -257,7 +256,7 @@ var (
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
bankAccountAtBlock2,
})
bankAccountAtBlock3, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock3, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 3,
Balance: big.NewInt(999914255999990000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -267,7 +266,7 @@ var (
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
bankAccountAtBlock3,
})
bankAccountAtBlock4, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock4, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 6,
Balance: big.NewInt(999826859999990000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -277,7 +276,7 @@ var (
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
bankAccountAtBlock4,
})
bankAccountAtBlock5, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 7,
Balance: big.NewInt(999805027999990000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand Down Expand Up @@ -1727,7 +1726,7 @@ var (
slot00StorageValue,
})

contractAccountAtBlock01, _ = rlp.EncodeToBytes(state.Account{
contractAccountAtBlock01, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 1,
Balance: big.NewInt(0),
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
Expand All @@ -1738,7 +1737,7 @@ var (
contractAccountAtBlock01,
})

bankAccountAtBlock01, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock01, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 1,
Balance: big.NewInt(3999629697375000000),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand All @@ -1748,7 +1747,7 @@ var (
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
bankAccountAtBlock01,
})
bankAccountAtBlock02, _ = rlp.EncodeToBytes(state.Account{
bankAccountAtBlock02, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: 2,
Balance: big.NewInt(5999607323457344852),
CodeHash: testhelpers.NullCodeHash.Bytes(),
Expand Down
12 changes: 6 additions & 6 deletions statediff/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ import (
"math/big"
"time"

"github.com/ipfs/go-cid"
node "github.com/ipfs/go-ipld-format"
"github.com/jmoiron/sqlx"
"github.com/multiformats/go-multihash"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -36,10 +40,6 @@ import (
"github.com/ethereum/go-ethereum/statediff/indexer/postgres"
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
"github.com/ipfs/go-cid"
node "github.com/ipfs/go-ipld-format"
"github.com/jmoiron/sqlx"
"github.com/multiformats/go-multihash"
)

var (
Expand Down Expand Up @@ -487,7 +487,7 @@ func (sdi *StateDiffIndexer) PushStateNode(tx *BlockTx, stateNode sdtypes.StateN
if len(i) != 2 {
return fmt.Errorf("eth IPLDPublisher expected state leaf node rlp to decode into two elements")
}
var account state.Account
var account types.StateAccount
if err := rlp.DecodeBytes(i[1].([]byte), &account); err != nil {
return fmt.Errorf("error decoding state account rlp: %s", err.Error())
}
Expand Down
7 changes: 4 additions & 3 deletions statediff/indexer/ipfs/ipld/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ import (
"bytes"
"errors"

"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
sdtrie "github.com/ethereum/go-ethereum/statediff/trie"
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
"github.com/ethereum/go-ethereum/trie"
"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
)

// IPLD Codecs for Ethereum
Expand Down Expand Up @@ -131,7 +132,7 @@ func (lt *localTrie) rootHash() []byte {
func (lt *localTrie) commit() error {
// commit trie nodes to trieDB
var err error
_, err = lt.trie.Commit(nil)
_, _, err = lt.trie.Commit(nil)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions statediff/indexer/mocks/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/trie"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -113,7 +112,7 @@ var (
ContractRoot = "0x821e2556a290c86405f8160a2d662042a431ba456b9db265c79bb837c04be5f0"
ContractCodeHash = common.HexToHash("0x753f98a8d4328b15636e46f66f2cb4bc860100aa17967cc145fcd17d1d4710ea")
ContractLeafKey = testhelpers.AddressToLeafKey(ContractAddress)
ContractAccount, _ = rlp.EncodeToBytes(state.Account{
ContractAccount, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: nonce1,
Balance: big.NewInt(0),
CodeHash: ContractCodeHash.Bytes(),
Expand All @@ -130,7 +129,7 @@ var (
AccountCodeHash = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
AccountLeafKey = testhelpers.Account2LeafKey
RemovedLeafKey = testhelpers.Account1LeafKey
Account, _ = rlp.EncodeToBytes(state.Account{
Account, _ = rlp.EncodeToBytes(types.StateAccount{
Nonce: nonce0,
Balance: big.NewInt(1000),
CodeHash: AccountCodeHash.Bytes(),
Expand Down
Loading

0 comments on commit aec0114

Please sign in to comment.