From c69b58f1d6f17f5e0f2ce0be7ef48dae9a06e739 Mon Sep 17 00:00:00 2001 From: tclemos Date: Fri, 1 Sep 2023 11:41:21 -0300 Subject: [PATCH] only RPC component will refresh blocked addresses --- cmd/run.go | 1 + pool/pool.go | 21 +++++++++++++-------- pool/pool_test.go | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index 673e68aadf..491771775f 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -195,6 +195,7 @@ func start(cliCtx *cli.Context) error { // Needed for rejecting transactions with too low gas price poolInstance.StartPollingMinSuggestedGasPrice(cliCtx.Context) } + poolInstance.StartRefreshingBlockedAddressesPeriodically() apis := map[string]bool{} for _, a := range cliCtx.StringSlice(config.FlagHTTPAPI) { apis[a] = true diff --git a/pool/pool.go b/pool/pool.go index bccda0dc7f..042d4a1047 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -80,14 +80,6 @@ func NewPool(cfg Config, batchConstraintsCfg state.BatchConstraintsCfg, s storag gasPricesMux: new(sync.RWMutex), } - p.refreshBlockedAddresses() - go func(cfg *Config, p *Pool) { - for { - time.Sleep(cfg.IntervalToRefreshBlockedAddresses.Duration) - p.refreshBlockedAddresses() - } - }(&cfg, p) - go func(cfg *Config, p *Pool) { for { p.refreshGasPrices() @@ -111,6 +103,19 @@ func (p *Pool) refreshGasPrices() { p.gasPricesMux.Unlock() } +// StartRefreshingBlockedAddressesPeriodically will make this instance of the pool +// to check periodically(accordingly to the configuration) for updates regarding +// the blocked address and update the in memory blocked addresses +func (p *Pool) StartRefreshingBlockedAddressesPeriodically() { + p.refreshBlockedAddresses() + go func(p *Pool) { + for { + time.Sleep(p.cfg.IntervalToRefreshBlockedAddresses.Duration) + p.refreshBlockedAddresses() + } + }(p) +} + // refreshBlockedAddresses refreshes the list of blocked addresses for the provided instance of pool func (p *Pool) refreshBlockedAddresses() { blockedAddresses, err := p.storage.GetAllAddressesBlocked(context.Background()) diff --git a/pool/pool_test.go b/pool/pool_test.go index 3ff62196cf..618428332c 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -1396,6 +1396,7 @@ func Test_BlockedAddress(t *testing.T) { } p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) + p.StartRefreshingBlockedAddressesPeriodically() gasPrices, err := p.GetGasPrices(ctx) require.NoError(t, err)