From 24058dc9dfaed706df852bc5b925b4abd9e55859 Mon Sep 17 00:00:00 2001 From: nabarun Date: Wed, 11 May 2022 18:10:20 +0530 Subject: [PATCH 1/4] Export builder config param WatchedAddressesLeafKeys --- statediff/builder.go | 6 +++--- statediff/config.go | 6 +++--- statediff/service.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/statediff/builder.go b/statediff/builder.go index a89ec2773324..165e53b85d94 100644 --- a/statediff/builder.go +++ b/statediff/builder.go @@ -202,7 +202,7 @@ func (sdb *builder) buildStateDiffWithIntermediateStateNodes(args types2.StateRo // a map of their leafkey to all the accounts that were touched and exist at A diffAccountsAtA, err := sdb.deletedOrUpdatedState( oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}), - diffAccountsAtB, diffPathsAtB, params.watchedAddressesLeafKeys, + diffAccountsAtB, diffPathsAtB, params.WatchedAddressesLeafKeys, params.IntermediateStorageNodes, output) if err != nil { return fmt.Errorf("error collecting deletedOrUpdatedNodes: %v", err) @@ -248,7 +248,7 @@ func (sdb *builder) buildStateDiffWithoutIntermediateStateNodes(args types2.Stat // and a slice of all the paths for the nodes in both of the above sets diffAccountsAtB, diffPathsAtB, err := sdb.createdAndUpdatedState( oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}), - params.watchedAddressesLeafKeys) + params.WatchedAddressesLeafKeys) if err != nil { return fmt.Errorf("error collecting createdAndUpdatedNodes: %v", err) } @@ -257,7 +257,7 @@ func (sdb *builder) buildStateDiffWithoutIntermediateStateNodes(args types2.Stat // a map of their leafkey to all the accounts that were touched and exist at A diffAccountsAtA, err := sdb.deletedOrUpdatedState( oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}), - diffAccountsAtB, diffPathsAtB, params.watchedAddressesLeafKeys, + diffAccountsAtB, diffPathsAtB, params.WatchedAddressesLeafKeys, params.IntermediateStorageNodes, output) if err != nil { return fmt.Errorf("error collecting deletedOrUpdatedNodes: %v", err) diff --git a/statediff/config.go b/statediff/config.go index b4905ab5a75b..77dc8b09722b 100644 --- a/statediff/config.go +++ b/statediff/config.go @@ -55,14 +55,14 @@ type Params struct { IncludeTD bool IncludeCode bool WatchedAddresses []common.Address - watchedAddressesLeafKeys map[common.Hash]struct{} + WatchedAddressesLeafKeys map[common.Hash]struct{} } // ComputeWatchedAddressesLeafKeys populates a map with keys (Keccak256Hash) of each of the WatchedAddresses func (p *Params) ComputeWatchedAddressesLeafKeys() { - p.watchedAddressesLeafKeys = make(map[common.Hash]struct{}, len(p.WatchedAddresses)) + p.WatchedAddressesLeafKeys = make(map[common.Hash]struct{}, len(p.WatchedAddresses)) for _, address := range p.WatchedAddresses { - p.watchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} + p.WatchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} } } diff --git a/statediff/service.go b/statediff/service.go index 4bdb9bf50d29..eb19ea8cc2f5 100644 --- a/statediff/service.go +++ b/statediff/service.go @@ -903,7 +903,7 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W // update in-memory params writeLoopParams.WatchedAddresses = append(writeLoopParams.WatchedAddresses, filteredAddresses...) funk.ForEach(filteredAddresses, func(address common.Address) { - writeLoopParams.watchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} + writeLoopParams.WatchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} }) case types2.Remove: // get addresses from args @@ -927,7 +927,7 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W // update in-memory params writeLoopParams.WatchedAddresses = addresses funk.ForEach(argAddresses, func(address common.Address) { - delete(writeLoopParams.watchedAddressesLeafKeys, crypto.Keccak256Hash(address.Bytes())) + delete(writeLoopParams.WatchedAddressesLeafKeys, crypto.Keccak256Hash(address.Bytes())) }) case types2.Set: // get addresses from args From aa3fa24bef18e4f1299155a0950e797531797b07 Mon Sep 17 00:00:00 2001 From: nabarun Date: Thu, 12 May 2022 15:49:58 +0530 Subject: [PATCH 2/4] Implemented method to get private watchedAddressesLeafKeys --- statediff/builder.go | 6 +++--- statediff/config.go | 10 +++++++--- statediff/service.go | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/statediff/builder.go b/statediff/builder.go index 165e53b85d94..a89ec2773324 100644 --- a/statediff/builder.go +++ b/statediff/builder.go @@ -202,7 +202,7 @@ func (sdb *builder) buildStateDiffWithIntermediateStateNodes(args types2.StateRo // a map of their leafkey to all the accounts that were touched and exist at A diffAccountsAtA, err := sdb.deletedOrUpdatedState( oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}), - diffAccountsAtB, diffPathsAtB, params.WatchedAddressesLeafKeys, + diffAccountsAtB, diffPathsAtB, params.watchedAddressesLeafKeys, params.IntermediateStorageNodes, output) if err != nil { return fmt.Errorf("error collecting deletedOrUpdatedNodes: %v", err) @@ -248,7 +248,7 @@ func (sdb *builder) buildStateDiffWithoutIntermediateStateNodes(args types2.Stat // and a slice of all the paths for the nodes in both of the above sets diffAccountsAtB, diffPathsAtB, err := sdb.createdAndUpdatedState( oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}), - params.WatchedAddressesLeafKeys) + params.watchedAddressesLeafKeys) if err != nil { return fmt.Errorf("error collecting createdAndUpdatedNodes: %v", err) } @@ -257,7 +257,7 @@ func (sdb *builder) buildStateDiffWithoutIntermediateStateNodes(args types2.Stat // a map of their leafkey to all the accounts that were touched and exist at A diffAccountsAtA, err := sdb.deletedOrUpdatedState( oldTrie.NodeIterator([]byte{}), newTrie.NodeIterator([]byte{}), - diffAccountsAtB, diffPathsAtB, params.WatchedAddressesLeafKeys, + diffAccountsAtB, diffPathsAtB, params.watchedAddressesLeafKeys, params.IntermediateStorageNodes, output) if err != nil { return fmt.Errorf("error collecting deletedOrUpdatedNodes: %v", err) diff --git a/statediff/config.go b/statediff/config.go index 77dc8b09722b..c19473e27a44 100644 --- a/statediff/config.go +++ b/statediff/config.go @@ -55,17 +55,21 @@ type Params struct { IncludeTD bool IncludeCode bool WatchedAddresses []common.Address - WatchedAddressesLeafKeys map[common.Hash]struct{} + watchedAddressesLeafKeys map[common.Hash]struct{} } // ComputeWatchedAddressesLeafKeys populates a map with keys (Keccak256Hash) of each of the WatchedAddresses func (p *Params) ComputeWatchedAddressesLeafKeys() { - p.WatchedAddressesLeafKeys = make(map[common.Hash]struct{}, len(p.WatchedAddresses)) + p.watchedAddressesLeafKeys = make(map[common.Hash]struct{}, len(p.WatchedAddresses)) for _, address := range p.WatchedAddresses { - p.WatchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} + p.watchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} } } +func (p *Params) WatchedAddressesLeafKeys() map[common.Hash]struct{} { + return p.watchedAddressesLeafKeys +} + // ParamsWithMutex allows to lock the parameters while they are being updated | read from type ParamsWithMutex struct { Params diff --git a/statediff/service.go b/statediff/service.go index eb19ea8cc2f5..4bdb9bf50d29 100644 --- a/statediff/service.go +++ b/statediff/service.go @@ -903,7 +903,7 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W // update in-memory params writeLoopParams.WatchedAddresses = append(writeLoopParams.WatchedAddresses, filteredAddresses...) funk.ForEach(filteredAddresses, func(address common.Address) { - writeLoopParams.WatchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} + writeLoopParams.watchedAddressesLeafKeys[crypto.Keccak256Hash(address.Bytes())] = struct{}{} }) case types2.Remove: // get addresses from args @@ -927,7 +927,7 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W // update in-memory params writeLoopParams.WatchedAddresses = addresses funk.ForEach(argAddresses, func(address common.Address) { - delete(writeLoopParams.WatchedAddressesLeafKeys, crypto.Keccak256Hash(address.Bytes())) + delete(writeLoopParams.watchedAddressesLeafKeys, crypto.Keccak256Hash(address.Bytes())) }) case types2.Set: // get addresses from args From 4318911a5c57ebe546ec7627fe97b868f6382918 Mon Sep 17 00:00:00 2001 From: nabarun Date: Thu, 12 May 2022 19:27:14 +0530 Subject: [PATCH 3/4] Move over helper function for loading chain config --- go.sum | 5 ---- statediff/helpers.go | 65 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 statediff/helpers.go diff --git a/go.sum b/go.sum index a06c7ed9d692..4a146ba9a329 100644 --- a/go.sum +++ b/go.sum @@ -585,7 +585,6 @@ github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1 github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= @@ -734,10 +733,8 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 h1:uCLL3g5wH2xjxVREVuAbP9JM5PPKjRbXKRa6IBjkzmU= golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -792,8 +789,6 @@ golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200108203644-89082a384178/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/statediff/helpers.go b/statediff/helpers.go new file mode 100644 index 000000000000..1557eb227e94 --- /dev/null +++ b/statediff/helpers.go @@ -0,0 +1,65 @@ +// VulcanizeDB +// Copyright © 2022 Vulcanize + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package statediff + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/ethereum/go-ethereum/log" + + "github.com/ethereum/go-ethereum/params" +) + +// LoadConfig loads chain config from json file +func LoadConfig(chainConfigPath string) (*params.ChainConfig, error) { + file, err := os.Open(chainConfigPath) + if err != nil { + log.Error(fmt.Sprintf("Failed to read chain config file: %v", err)) + + return nil, err + } + defer file.Close() + + chainConfig := new(params.ChainConfig) + if err := json.NewDecoder(file).Decode(chainConfig); err != nil { + log.Error(fmt.Sprintf("invalid chain config file: %v", err)) + + return nil, err + } + + log.Info(fmt.Sprintf("Using chain config from %s file. Content %+v", chainConfigPath, chainConfig)) + + return chainConfig, nil +} + +// ChainConfig returns the appropriate ethereum chain config for the provided chain id +func ChainConfig(chainID uint64) (*params.ChainConfig, error) { + switch chainID { + case 1: + return params.MainnetChainConfig, nil + case 3: + return params.RopstenChainConfig, nil + case 4: + return params.RinkebyChainConfig, nil + case 5: + return params.GoerliChainConfig, nil + default: + return nil, fmt.Errorf("chain config for chainid %d not available", chainID) + } +} From 41c9ea064c923b4d2b4252ef62e5d77e66cf1bbc Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Mon, 16 May 2022 11:37:31 +0530 Subject: [PATCH 4/4] Add new target branch for github actions --- .github/workflows/on-master.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/on-master.yaml b/.github/workflows/on-master.yaml index df521cdb03e9..eacee594204f 100644 --- a/.github/workflows/on-master.yaml +++ b/.github/workflows/on-master.yaml @@ -7,6 +7,7 @@ on: - statediff - statediff-v2 - statediff-v3 + - v1.10.17-statediff-v4 - v1.10.17-statediff-v3 - v1.10.16-statediff-v3 - v1.10.15-statediff-v3