Skip to content

Commit

Permalink
Changes to index intermediate nodes for watched addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Jun 15, 2022
1 parent 29e267d commit 37c3c59
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/oleiade/lane v1.0.1 h1:hXofkn7GEOubzTwNpeL9MaNy8WxolCYb9cInAIeqShU=
github.com/oleiade/lane v1.0.1/go.mod h1:IyTkraa4maLfjq/GmHR+Dxb4kCMtEGeb+qmhlrQ5Mk4=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down Expand Up @@ -775,8 +777,6 @@ github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPU
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/vulcanize/go-eth-state-node-iterator v1.1.0 h1:wbOpP9BnqDcN8OWbuOw/QvR7Mde5JuuI15SGfLil0ZE=
github.com/vulcanize/go-eth-state-node-iterator v1.1.0/go.mod h1:a1aRW1/fEmcpY8AAU47p9TNL3QNjpeqCJd/hLtFKVL8=
github.com/vulcanize/go-ethereum v1.10.18-statediff-4.0.2-alpha h1:gTcfBHoaRpsRbP1/dnurg5LFUaqsQMTNqs4R4S2wm9U=
github.com/vulcanize/go-ethereum v1.10.18-statediff-4.0.2-alpha/go.mod h1:HelXH7UT1uWdb+St6UAj4pPf93GOggjIV7pVbrWIZ3o=
github.com/vulcanize/leveldb-ethdb-rpc v0.1.2 h1:ws/CsvxsPQh6IOQGsUDCPaNuPzcDjtVW1sT8o20Nfg4=
github.com/vulcanize/leveldb-ethdb-rpc v0.1.2/go.mod h1:lksnBYanEe9GuDDeYMtpbc0JnPy4mOKImw4M8vkqJDw=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo=
Expand Down
5 changes: 5 additions & 0 deletions pkg/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func (sdb *builder) BuildStateDiffObject(args sd.Args, params sd.Params) (sdtype

// WriteStateDiffObject writes a statediff object to output callback
func (sdb *builder) WriteStateDiffObject(args sdtypes.StateRoots, params sd.Params, output sdtypes.StateNodeSink, codeOutput sdtypes.CodeSink) error {
// builder for watched addresses breaks when the trie iteration is split between num. of workers > 1
if len(params.WatchedAddresses) > 0 && sdb.numWorkers > 1 {
return fmt.Errorf("number of workers can't be more than 1 when having watched addresses")
}

// Load tries for old and new states
oldTrie, err := sdb.StateCache.OpenTrie(args.OldStateRoot)
if err != nil {
Expand Down
97 changes: 91 additions & 6 deletions pkg/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,9 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
block2 = blocks[1]
block3 = blocks[2]
params := statediff.Params{
WatchedAddresses: []common.Address{test_helpers.Account1Addr, test_helpers.ContractAddr},
IntermediateStateNodes: true,
IntermediateStorageNodes: true,
WatchedAddresses: []common.Address{test_helpers.Account1Addr, test_helpers.ContractAddr},
}
params.ComputeWatchedAddressesLeafKeys()

Expand Down Expand Up @@ -1052,6 +1054,12 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
BlockNumber: block1.Number(),
BlockHash: block1.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block1BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x0e'},
NodeType: sdtypes.Leaf,
Expand All @@ -1076,12 +1084,23 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
BlockNumber: block2.Number(),
BlockHash: block2.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block2BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x06'},
NodeType: sdtypes.Leaf,
LeafKey: contractLeafKey,
NodeValue: contractAccountAtBlock2LeafNode,
StorageNodes: []sdtypes.StorageNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block2StorageBranchRootNode,
},
{
Path: []byte{'\x02'},
NodeType: sdtypes.Leaf,
Expand Down Expand Up @@ -1126,12 +1145,23 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
BlockNumber: block3.Number(),
BlockHash: block3.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block3BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x06'},
NodeType: sdtypes.Leaf,
LeafKey: contractLeafKey,
NodeValue: contractAccountAtBlock3LeafNode,
StorageNodes: []sdtypes.StorageNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block3StorageBranchRootNode,
},
{
Path: []byte{'\x0c'},
NodeType: sdtypes.Leaf,
Expand All @@ -1145,7 +1175,7 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
},
}

for _, workers := range workerCounts {
for _, workers := range workerCounts[:2] {
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
for _, test := range tests {
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
Expand Down Expand Up @@ -1613,7 +1643,9 @@ func TestBuilderWithRemovedNonWatchedAccount(t *testing.T) {
block5 = blocks[4]
block6 = blocks[5]
params := statediff.Params{
WatchedAddresses: []common.Address{test_helpers.Account1Addr, test_helpers.Account2Addr},
IntermediateStateNodes: true,
IntermediateStorageNodes: true,
WatchedAddresses: []common.Address{test_helpers.Account1Addr, test_helpers.Account2Addr},
}
params.ComputeWatchedAddressesLeafKeys()

Expand All @@ -1634,6 +1666,12 @@ func TestBuilderWithRemovedNonWatchedAccount(t *testing.T) {
BlockNumber: block4.Number(),
BlockHash: block4.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block4BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x0c'},
NodeType: sdtypes.Leaf,
Expand All @@ -1656,6 +1694,12 @@ func TestBuilderWithRemovedNonWatchedAccount(t *testing.T) {
BlockNumber: block5.Number(),
BlockHash: block5.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block5BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x0e'},
NodeType: sdtypes.Leaf,
Expand All @@ -1678,6 +1722,12 @@ func TestBuilderWithRemovedNonWatchedAccount(t *testing.T) {
BlockNumber: block6.Number(),
BlockHash: block6.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block6BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x0c'},
NodeType: sdtypes.Leaf,
Expand All @@ -1697,7 +1747,7 @@ func TestBuilderWithRemovedNonWatchedAccount(t *testing.T) {
},
}

for _, workers := range workerCounts {
for _, workers := range workerCounts[:2] {
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
for _, test := range tests {
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
Expand Down Expand Up @@ -1731,7 +1781,9 @@ func TestBuilderWithRemovedWatchedAccount(t *testing.T) {
block5 = blocks[4]
block6 = blocks[5]
params := statediff.Params{
WatchedAddresses: []common.Address{test_helpers.Account1Addr, test_helpers.ContractAddr},
IntermediateStateNodes: true,
IntermediateStorageNodes: true,
WatchedAddresses: []common.Address{test_helpers.Account1Addr, test_helpers.ContractAddr},
}
params.ComputeWatchedAddressesLeafKeys()

Expand All @@ -1752,12 +1804,23 @@ func TestBuilderWithRemovedWatchedAccount(t *testing.T) {
BlockNumber: block4.Number(),
BlockHash: block4.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block4BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x06'},
NodeType: sdtypes.Leaf,
LeafKey: contractLeafKey,
NodeValue: contractAccountAtBlock4LeafNode,
StorageNodes: []sdtypes.StorageNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block4StorageBranchRootNode,
},
{
Path: []byte{'\x04'},
NodeType: sdtypes.Leaf,
Expand Down Expand Up @@ -1793,12 +1856,23 @@ func TestBuilderWithRemovedWatchedAccount(t *testing.T) {
BlockNumber: block5.Number(),
BlockHash: block5.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block5BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x06'},
NodeType: sdtypes.Leaf,
LeafKey: contractLeafKey,
NodeValue: contractAccountAtBlock5LeafNode,
StorageNodes: []sdtypes.StorageNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block5StorageBranchRootNode,
},
{
Path: []byte{'\x0c'},
NodeType: sdtypes.Leaf,
Expand Down Expand Up @@ -1835,12 +1909,23 @@ func TestBuilderWithRemovedWatchedAccount(t *testing.T) {
BlockNumber: block6.Number(),
BlockHash: block6.Hash(),
Nodes: []sdtypes.StateNode{
{
Path: []byte{},
NodeType: sdtypes.Branch,
NodeValue: block6BranchRootNode,
StorageNodes: emptyStorage,
},
{
Path: []byte{'\x06'},
NodeType: sdtypes.Removed,
LeafKey: contractLeafKey,
NodeValue: []byte{},
StorageNodes: []sdtypes.StorageNode{
{
Path: []byte{},
NodeType: sdtypes.Removed,
NodeValue: []byte{},
},
{
Path: []byte{'\x02'},
NodeType: sdtypes.Removed,
Expand All @@ -1867,7 +1952,7 @@ func TestBuilderWithRemovedWatchedAccount(t *testing.T) {
},
}

for _, workers := range workerCounts {
for _, workers := range workerCounts[:2] {
builder, _ = pkg.NewBuilder(chain.StateCache(), workers)
for _, test := range tests {
diff, err := builder.BuildStateDiffObject(test.startingArguments, params)
Expand Down

0 comments on commit 37c3c59

Please sign in to comment.