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 {