Skip to content

Commit

Permalink
Implemented method to get private watchedAddressesLeafKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed May 12, 2022
1 parent 24058dc commit aa3fa24
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions statediff/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions statediff/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions statediff/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit aa3fa24

Please sign in to comment.