Skip to content

Commit

Permalink
Add 2 minute period unmined txs processing (#209)
Browse files Browse the repository at this point in the history
* Add 2 minute period unmined txs processing

* Fix ineffective control operator

* Move global var to constant
  • Loading branch information
nozim authored Dec 12, 2023
1 parent c5d6de6 commit 5390786
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions cmd/metamorph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5390786

Please sign in to comment.