@@ -170,7 +170,8 @@ func New(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params
170170 var db sql.Database
171171 var err error
172172 quitCh := make (chan bool )
173- if params .IndexerConfig != nil {
173+ indexerConfigAvailable := params .IndexerConfig != nil
174+ if indexerConfigAvailable {
174175 info := nodeinfo.Info {
175176 GenesisBlock : blockChain .Genesis ().Hash ().Hex (),
176177 NetworkID : strconv .FormatUint (cfg .NetworkId , 10 ),
@@ -201,11 +202,13 @@ func New(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params
201202 statediffMetrics : statediffMetrics ,
202203 sqlFileWaitingForWrite : false ,
203204 }
204- if params .IndexerConfig .Type () == shared .POSTGRES {
205- knownGaps .checkForGaps = true
206- } else {
207- log .Info ("We are not going to check for gaps on start up since we are not connected to Postgres!" )
208- knownGaps .checkForGaps = false
205+ if indexerConfigAvailable {
206+ if params .IndexerConfig .Type () == shared .POSTGRES {
207+ knownGaps .checkForGaps = true
208+ } else {
209+ log .Info ("We are not going to check for gaps on start up since we are not connected to Postgres!" )
210+ knownGaps .checkForGaps = false
211+ }
209212 }
210213 sds := & Service {
211214 Mutex : sync.Mutex {},
@@ -226,9 +229,11 @@ func New(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params
226229 stack .RegisterLifecycle (sds )
227230 stack .RegisterAPIs (sds .APIs ())
228231
229- err = loadWatchedAddresses (indexer )
230- if err != nil {
231- return err
232+ if indexerConfigAvailable {
233+ err = loadWatchedAddresses (indexer )
234+ if err != nil {
235+ return err
236+ }
232237 }
233238
234239 return nil
@@ -477,6 +482,13 @@ func (sds *Service) StateDiffAt(blockNumber uint64, params Params) (*Payload, er
477482 currentBlock := sds .BlockChain .GetBlockByNumber (blockNumber )
478483 log .Info ("sending state diff" , "block height" , blockNumber )
479484
485+ // use watched addresses from statediffing write loop if not provided
486+ if params .WatchedAddresses == nil && writeLoopParams .WatchedAddresses != nil {
487+ writeLoopParams .RLock ()
488+ params .WatchedAddresses = make ([]common.Address , len (writeLoopParams .WatchedAddresses ))
489+ copy (params .WatchedAddresses , writeLoopParams .WatchedAddresses )
490+ writeLoopParams .RUnlock ()
491+ }
480492 // compute leaf paths of watched addresses in the params
481493 params .ComputeWatchedAddressesLeafPaths ()
482494
@@ -493,6 +505,13 @@ func (sds *Service) StateDiffFor(blockHash common.Hash, params Params) (*Payload
493505 currentBlock := sds .BlockChain .GetBlockByHash (blockHash )
494506 log .Info ("sending state diff" , "block hash" , blockHash )
495507
508+ // use watched addresses from statediffing write loop if not provided
509+ if params .WatchedAddresses == nil && writeLoopParams .WatchedAddresses != nil {
510+ writeLoopParams .RLock ()
511+ params .WatchedAddresses = make ([]common.Address , len (writeLoopParams .WatchedAddresses ))
512+ copy (params .WatchedAddresses , writeLoopParams .WatchedAddresses )
513+ writeLoopParams .RUnlock ()
514+ }
496515 // compute leaf paths of watched addresses in the params
497516 params .ComputeWatchedAddressesLeafPaths ()
498517
@@ -777,6 +796,15 @@ func (sds *Service) StreamCodeAndCodeHash(blockNumber uint64, outChan chan<- typ
777796// This operation cannot be performed back past the point of db pruning; it requires an archival node
778797// for historical data
779798func (sds * Service ) WriteStateDiffAt (blockNumber uint64 , params Params ) error {
799+ log .Info ("writing state diff at" , "block height" , blockNumber )
800+
801+ // use watched addresses from statediffing write loop if not provided
802+ if params .WatchedAddresses == nil && writeLoopParams .WatchedAddresses != nil {
803+ writeLoopParams .RLock ()
804+ params .WatchedAddresses = make ([]common.Address , len (writeLoopParams .WatchedAddresses ))
805+ copy (params .WatchedAddresses , writeLoopParams .WatchedAddresses )
806+ writeLoopParams .RUnlock ()
807+ }
780808 // compute leaf paths of watched addresses in the params
781809 params .ComputeWatchedAddressesLeafPaths ()
782810
@@ -793,6 +821,15 @@ func (sds *Service) WriteStateDiffAt(blockNumber uint64, params Params) error {
793821// This operation cannot be performed back past the point of db pruning; it requires an archival node
794822// for historical data
795823func (sds * Service ) WriteStateDiffFor (blockHash common.Hash , params Params ) error {
824+ log .Info ("writing state diff for" , "block hash" , blockHash )
825+
826+ // use watched addresses from statediffing write loop if not provided
827+ if params .WatchedAddresses == nil && writeLoopParams .WatchedAddresses != nil {
828+ writeLoopParams .RLock ()
829+ params .WatchedAddresses = make ([]common.Address , len (writeLoopParams .WatchedAddresses ))
830+ copy (params .WatchedAddresses , writeLoopParams .WatchedAddresses )
831+ writeLoopParams .RUnlock ()
832+ }
796833 // compute leaf paths of watched addresses in the params
797834 params .ComputeWatchedAddressesLeafPaths ()
798835
@@ -895,9 +932,11 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W
895932 }
896933
897934 // update the db
898- err = sds .indexer .InsertWatchedAddresses (filteredArgs , currentBlockNumber )
899- if err != nil {
900- return err
935+ if sds .indexer != nil {
936+ err = sds .indexer .InsertWatchedAddresses (filteredArgs , currentBlockNumber )
937+ if err != nil {
938+ return err
939+ }
901940 }
902941
903942 // update in-memory params
@@ -917,9 +956,11 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W
917956 }
918957
919958 // update the db
920- err = sds .indexer .RemoveWatchedAddresses (args )
921- if err != nil {
922- return err
959+ if sds .indexer != nil {
960+ err = sds .indexer .RemoveWatchedAddresses (args )
961+ if err != nil {
962+ return err
963+ }
923964 }
924965
925966 // update in-memory params
@@ -933,19 +974,23 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W
933974 }
934975
935976 // update the db
936- err = sds .indexer .SetWatchedAddresses (args , currentBlockNumber )
937- if err != nil {
938- return err
977+ if sds .indexer != nil {
978+ err = sds .indexer .SetWatchedAddresses (args , currentBlockNumber )
979+ if err != nil {
980+ return err
981+ }
939982 }
940983
941984 // update in-memory params
942985 writeLoopParams .WatchedAddresses = argAddresses
943986 writeLoopParams .ComputeWatchedAddressesLeafPaths ()
944987 case types2 .Clear :
945988 // update the db
946- err := sds .indexer .ClearWatchedAddresses ()
947- if err != nil {
948- return err
989+ if sds .indexer != nil {
990+ err := sds .indexer .ClearWatchedAddresses ()
991+ if err != nil {
992+ return err
993+ }
949994 }
950995
951996 // update in-memory params
0 commit comments