Skip to content

Commit

Permalink
Merge pull request #5003 from oasisprotocol/ptrus/fix/txpool-republish
Browse files Browse the repository at this point in the history
go/runtime/txpool: republish sooner if `maxRepublishTxs` is reached.
  • Loading branch information
ptrus authored Oct 28, 2022
2 parents a5b2c18 + f1906bf commit 3618947
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .changelog/5003.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/runtime/txpool: republish sooner if republish limit is reached

This fixes a case where some portion of a batch of transaction would take a
long time to be published if there are no new transactions incoming.
12 changes: 10 additions & 2 deletions go/runtime/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ const (
// abortTimeout is the maximum time the runtime can spend aborting.
abortTimeout = 5 * time.Second
// maxRepublishTxs is the maximum amount of transactions to republish.
maxRepublishTxs = 32
maxRepublishTxs = 128
// newBlockPublishDelay is the time to wait to publish any newly checked transactions after
// receiving a new block. It should be roughly the block propagation delay.
newBlockPublishDelay = 200 * time.Millisecond

// republishLimitReinvokeTimeout is the timeout to the next republish worker invocation in
// case when the maxRepublishTxs limit is reached. This should be much shorter than the
// RepublishInterval.
republishLimitReinvokeTimeout = 1 * time.Second
)

// Config is the transaction pool configuration.
Expand Down Expand Up @@ -806,7 +811,10 @@ func (t *txPool) republishWorker() {
_ = t.seenCache.Put(tx.Hash(), time.Now())

republishedCount++
if republishedCount > maxRepublishTxs {
if republishedCount >= maxRepublishTxs {
// If the limit of max republish transactions has been reached
// republish again sooner.
nextPendingRepublish = republishLimitReinvokeTimeout
break
}
}
Expand Down

0 comments on commit 3618947

Please sign in to comment.