diff --git a/metamorph/processor.go b/metamorph/processor.go index 4c159e661..14e9c022a 100644 --- a/metamorph/processor.go +++ b/metamorph/processor.go @@ -30,13 +30,15 @@ const ( // length of interval for checking transactions if they are seen on the network // if not we resend them again for a few times unseenTransactionRebroadcastingInterval = 60 - processExpiredSeenTxsIntervalDefault = 5 * time.Minute - mapExpiryTimeDefault = 24 * time.Hour - LogLevelDefault = slog.LevelInfo + + processCheckIfMinedIntervalDefault = 1 * time.Minute + checkIfMinedTimeRange = time.Minute * 60 + + mapExpiryTimeDefault = 24 * time.Hour + LogLevelDefault = slog.LevelInfo failedToUpdateStatus = "Failed to update status" dataRetentionPeriodDefault = 14 * 24 * time.Hour // 14 days - checkIfMinedTimeRange = time.Minute * 20 ) type Processor struct { @@ -50,8 +52,8 @@ type Processor struct { dataRetentionPeriod time.Duration now func() time.Time - processExpiredSeenTxsInterval time.Duration - processExpiredSeenTxsTicker *time.Ticker + processCheckIfMinedInterval time.Duration + processCheckIfMinedTicker *time.Ticker processExpiredTxsTicker *time.Ticker @@ -90,7 +92,7 @@ func NewProcessor(s store.MetamorphStore, pm p2p.PeerManagerI, btc blocktx.Clien now: time.Now, processExpiredTxsTicker: time.NewTicker(unseenTransactionRebroadcastingInterval * time.Second), - processExpiredSeenTxsInterval: processExpiredSeenTxsIntervalDefault, + processCheckIfMinedInterval: processCheckIfMinedIntervalDefault, stored: stat.NewAtomicStat(), announcedToNetwork: stat.NewAtomicStats(), @@ -111,7 +113,7 @@ func NewProcessor(s store.MetamorphStore, pm p2p.PeerManagerI, btc blocktx.Clien } p.ProcessorResponseMap = NewProcessorResponseMap(p.mapExpiryTime, WithLogFile(p.logFile), WithNowResponseMap(p.now)) - p.processExpiredSeenTxsTicker = time.NewTicker(p.processExpiredSeenTxsInterval) + p.processCheckIfMinedTicker = time.NewTicker(p.processCheckIfMinedInterval) p.logger.Info("Starting processor", slog.Duration("cacheExpiryTime", p.mapExpiryTime)) @@ -145,7 +147,7 @@ func (p *Processor) Shutdown() { if err != nil { p.logger.Error("Failed to unlock all hashes", slog.String("err", err.Error())) } - p.processExpiredSeenTxsTicker.Stop() + p.processCheckIfMinedTicker.Stop() p.processExpiredTxsTicker.Stop() p.ProcessorResponseMap.Close() } @@ -177,7 +179,7 @@ func (p *Processor) processCheckIfMined() { // Check transactions that have been seen on the network, but haven't been marked as mined // The Items() method will return a copy of the map, so we can iterate over it without locking - for range p.processExpiredSeenTxsTicker.C { + for range p.processCheckIfMinedTicker.C { expiredTransactionItems := p.ProcessorResponseMap.Items(filterFunc) if len(expiredTransactionItems) == 0 { continue diff --git a/metamorph/processor_options.go b/metamorph/processor_options.go index ebdb604a8..253503b3b 100644 --- a/metamorph/processor_options.go +++ b/metamorph/processor_options.go @@ -5,9 +5,9 @@ import ( "time" ) -func WithProcessExpiredSeenTxsInterval(d time.Duration) func(*Processor) { +func WithProcessCheckIfMinedInterval(d time.Duration) func(*Processor) { return func(p *Processor) { - p.processExpiredSeenTxsInterval = d + p.processCheckIfMinedInterval = d } } diff --git a/metamorph/processor_test.go b/metamorph/processor_test.go index 7be2c24ff..ef9aedd7b 100644 --- a/metamorph/processor_test.go +++ b/metamorph/processor_test.go @@ -79,7 +79,7 @@ func TestNewProcessor(t *testing.T) { processor, err := NewProcessor(tc.store, tc.pm, nil, WithCacheExpiryTime(time.Second*5), - WithProcessExpiredSeenTxsInterval(time.Second*5), + WithProcessCheckIfMinedInterval(time.Second*5), WithProcessorLogger(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: LogLevelDefault}))), ) if tc.expectedErrorStr != "" || err != nil { @@ -298,7 +298,7 @@ func TestLoadUnmined(t *testing.T) { } processor, err := NewProcessor(mtmStore, pm, btxMock, - WithProcessExpiredSeenTxsInterval(time.Hour*24), + WithProcessCheckIfMinedInterval(time.Hour*24), WithCacheExpiryTime(time.Hour*24), WithNow(func() time.Time { return storedAt.Add(1 * time.Hour) @@ -813,7 +813,7 @@ func TestProcessCheckIfMined(t *testing.T) { pm := p2p.NewPeerManagerMock() processor, err := NewProcessor(metamorphStore, pm, btxMock, - WithProcessExpiredSeenTxsInterval(20*time.Millisecond), + WithProcessCheckIfMinedInterval(20*time.Millisecond), WithProcessExpiredTxsInterval(time.Hour), ) require.NoError(t, err) @@ -862,7 +862,7 @@ func TestProcessExpiredTransactions(t *testing.T) { } pm := p2p.NewPeerManagerMock() processor, err := NewProcessor(metamorphStore, pm, nil, - WithProcessExpiredSeenTxsInterval(time.Hour), + WithProcessCheckIfMinedInterval(time.Hour), WithProcessExpiredTxsInterval(time.Millisecond*20), WithNow(func() time.Time { return time.Date(2033, 1, 1, 1, 0, 0, 0, time.UTC)