Avoid using indexer object when direct indexing is off

This commit is contained in:
Prathamesh Musale 2022-07-25 11:07:40 +05:30
parent 209f7d37c2
commit 155e6d2010

View File

@ -170,7 +170,8 @@ func New(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params
var db sql.Database var db sql.Database
var err error var err error
quitCh := make(chan bool) quitCh := make(chan bool)
if params.IndexerConfig != nil { indexerConfigAvailable := params.IndexerConfig != nil
if indexerConfigAvailable {
info := nodeinfo.Info{ info := nodeinfo.Info{
GenesisBlock: blockChain.Genesis().Hash().Hex(), GenesisBlock: blockChain.Genesis().Hash().Hex(),
NetworkID: strconv.FormatUint(cfg.NetworkId, 10), NetworkID: strconv.FormatUint(cfg.NetworkId, 10),
@ -201,12 +202,14 @@ func New(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params
statediffMetrics: statediffMetrics, statediffMetrics: statediffMetrics,
sqlFileWaitingForWrite: false, sqlFileWaitingForWrite: false,
} }
if indexerConfigAvailable {
if params.IndexerConfig.Type() == shared.POSTGRES { if params.IndexerConfig.Type() == shared.POSTGRES {
knownGaps.checkForGaps = true knownGaps.checkForGaps = true
} else { } else {
log.Info("We are not going to check for gaps on start up since we are not connected to Postgres!") log.Info("We are not going to check for gaps on start up since we are not connected to Postgres!")
knownGaps.checkForGaps = false knownGaps.checkForGaps = false
} }
}
sds := &Service{ sds := &Service{
Mutex: sync.Mutex{}, Mutex: sync.Mutex{},
BlockChain: blockChain, BlockChain: blockChain,
@ -226,10 +229,12 @@ func New(stack *node.Node, ethServ *eth.Ethereum, cfg *ethconfig.Config, params
stack.RegisterLifecycle(sds) stack.RegisterLifecycle(sds)
stack.RegisterAPIs(sds.APIs()) stack.RegisterAPIs(sds.APIs())
if indexerConfigAvailable {
err = loadWatchedAddresses(indexer) err = loadWatchedAddresses(indexer)
if err != nil { if err != nil {
return err return err
} }
}
return nil return nil
} }
@ -927,10 +932,12 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W
} }
// update the db // update the db
if sds.indexer != nil {
err = sds.indexer.InsertWatchedAddresses(filteredArgs, currentBlockNumber) err = sds.indexer.InsertWatchedAddresses(filteredArgs, currentBlockNumber)
if err != nil { if err != nil {
return err return err
} }
}
// update in-memory params // update in-memory params
writeLoopParams.WatchedAddresses = append(writeLoopParams.WatchedAddresses, filteredAddresses...) writeLoopParams.WatchedAddresses = append(writeLoopParams.WatchedAddresses, filteredAddresses...)
@ -949,10 +956,12 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W
} }
// update the db // update the db
if sds.indexer != nil {
err = sds.indexer.RemoveWatchedAddresses(args) err = sds.indexer.RemoveWatchedAddresses(args)
if err != nil { if err != nil {
return err return err
} }
}
// update in-memory params // update in-memory params
writeLoopParams.WatchedAddresses = addresses writeLoopParams.WatchedAddresses = addresses
@ -965,20 +974,24 @@ func (sds *Service) WatchAddress(operation types2.OperationType, args []types2.W
} }
// update the db // update the db
if sds.indexer != nil {
err = sds.indexer.SetWatchedAddresses(args, currentBlockNumber) err = sds.indexer.SetWatchedAddresses(args, currentBlockNumber)
if err != nil { if err != nil {
return err return err
} }
}
// update in-memory params // update in-memory params
writeLoopParams.WatchedAddresses = argAddresses writeLoopParams.WatchedAddresses = argAddresses
writeLoopParams.ComputeWatchedAddressesLeafPaths() writeLoopParams.ComputeWatchedAddressesLeafPaths()
case types2.Clear: case types2.Clear:
// update the db // update the db
if sds.indexer != nil {
err := sds.indexer.ClearWatchedAddresses() err := sds.indexer.ClearWatchedAddresses()
if err != nil { if err != nil {
return err return err
} }
}
// update in-memory params // update in-memory params
writeLoopParams.WatchedAddresses = []common.Address{} writeLoopParams.WatchedAddresses = []common.Address{}