From 539078617a705e67fd37c96084054ef2b43b34c9 Mon Sep 17 00:00:00 2001 From: Nozim Mehrubonov Date: Tue, 12 Dec 2023 11:40:17 +0000 Subject: [PATCH] Add 2 minute period unmined txs processing (#209) * Add 2 minute period unmined txs processing * Fix ineffective control operator * Move global var to constant --- cmd/metamorph.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/cmd/metamorph.go b/cmd/metamorph.go index ec655e12c..917196cbe 100644 --- a/cmd/metamorph.go +++ b/cmd/metamorph.go @@ -35,11 +35,12 @@ import ( ) const ( - DbModeBadger = "badger" - DbModeDynamoDB = "dynamodb" - DbModePostgres = "postgres" - DbModeSQLiteM = "sqlite_memory" - DbModeSQLite = "sqlite" + DbModeBadger = "badger" + DbModeDynamoDB = "dynamodb" + DbModePostgres = "postgres" + DbModeSQLiteM = "sqlite_memory" + DbModeSQLite = "sqlite" + unminedTxsPeriod = 2 * time.Minute ) func StartMetamorph(logger utils.Logger) (func(), error) { @@ -155,11 +156,18 @@ func StartMetamorph(logger utils.Logger) (func(), error) { // that can be deferred to reset the TTY when the program exits. defer metamorphProcessor.PrintStatsOnKeypress()() } + ticker := time.NewTimer(unminedTxsPeriod) + stopUnminedProcessor := make(chan bool) go func() { - // load all transactions into memory from disk that have not been seen on the network - // this will make sure they are re-broadcast until a response is received - metamorphProcessor.LoadUnmined() + for { + select { + case <-stopUnminedProcessor: + return + case <-ticker.C: + metamorphProcessor.LoadUnmined() + } + } }() // create a channel to receive mined block messages from the block tx service @@ -307,6 +315,8 @@ func StartMetamorph(logger utils.Logger) (func(), error) { return func() { logger.Infof("Shutting down metamorph") + + stopUnminedProcessor <- true metamorphProcessor.Shutdown() err = s.Close(context.Background()) if err != nil {