From 209f7d37c25a989b383953394c8bd9bc75b0844c Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Mon, 25 Jul 2022 10:45:19 +0530 Subject: [PATCH] Use watched addresses from direct indexing params in statediff APIs by default --- statediff/service.go | 32 ++++++++++++++++++++++++++++++++ statediff/service_test.go | 7 ++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/statediff/service.go b/statediff/service.go index 517ab3466..39e47c779 100644 --- a/statediff/service.go +++ b/statediff/service.go @@ -477,6 +477,13 @@ func (sds *Service) StateDiffAt(blockNumber uint64, params Params) (*Payload, er currentBlock := sds.BlockChain.GetBlockByNumber(blockNumber) log.Info("sending state diff", "block height", blockNumber) + // use watched addresses from statediffing write loop if not provided + if params.WatchedAddresses == nil { + writeLoopParams.RLock() + params.WatchedAddresses = make([]common.Address, len(writeLoopParams.WatchedAddresses)) + copy(params.WatchedAddresses, writeLoopParams.WatchedAddresses) + writeLoopParams.RUnlock() + } // compute leaf paths of watched addresses in the params params.ComputeWatchedAddressesLeafPaths() @@ -493,6 +500,13 @@ func (sds *Service) StateDiffFor(blockHash common.Hash, params Params) (*Payload currentBlock := sds.BlockChain.GetBlockByHash(blockHash) log.Info("sending state diff", "block hash", blockHash) + // use watched addresses from statediffing write loop if not provided + if params.WatchedAddresses == nil { + writeLoopParams.RLock() + params.WatchedAddresses = make([]common.Address, len(writeLoopParams.WatchedAddresses)) + copy(params.WatchedAddresses, writeLoopParams.WatchedAddresses) + writeLoopParams.RUnlock() + } // compute leaf paths of watched addresses in the params params.ComputeWatchedAddressesLeafPaths() @@ -777,6 +791,15 @@ func (sds *Service) StreamCodeAndCodeHash(blockNumber uint64, outChan chan<- typ // This operation cannot be performed back past the point of db pruning; it requires an archival node // for historical data func (sds *Service) WriteStateDiffAt(blockNumber uint64, params Params) error { + log.Info("writing state diff at", "block height", blockNumber) + + // use watched addresses from statediffing write loop if not provided + if params.WatchedAddresses == nil { + writeLoopParams.RLock() + params.WatchedAddresses = make([]common.Address, len(writeLoopParams.WatchedAddresses)) + copy(params.WatchedAddresses, writeLoopParams.WatchedAddresses) + writeLoopParams.RUnlock() + } // compute leaf paths of watched addresses in the params params.ComputeWatchedAddressesLeafPaths() @@ -793,6 +816,15 @@ func (sds *Service) WriteStateDiffAt(blockNumber uint64, params Params) error { // This operation cannot be performed back past the point of db pruning; it requires an archival node // for historical data func (sds *Service) WriteStateDiffFor(blockHash common.Hash, params Params) error { + log.Info("writing state diff for", "block hash", blockHash) + + // use watched addresses from statediffing write loop if not provided + if params.WatchedAddresses == nil { + writeLoopParams.RLock() + params.WatchedAddresses = make([]common.Address, len(writeLoopParams.WatchedAddresses)) + copy(params.WatchedAddresses, writeLoopParams.WatchedAddresses) + writeLoopParams.RUnlock() + } // compute leaf paths of watched addresses in the params params.ComputeWatchedAddressesLeafPaths() diff --git a/statediff/service_test.go b/statediff/service_test.go index 3f80f1d2e..ecf8bdadb 100644 --- a/statediff/service_test.go +++ b/statediff/service_test.go @@ -78,9 +78,10 @@ var ( event3 = core.ChainEvent{Block: testBlock3} defaultParams = statediff.Params{ - IncludeBlock: true, - IncludeReceipts: true, - IncludeTD: true, + IncludeBlock: true, + IncludeReceipts: true, + IncludeTD: true, + WatchedAddresses: []common.Address{}, } )