Skip to content

Commit

Permalink
Added waitgroup to reset so Qi and Quai are added concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed May 13, 2024
1 parent 6173e9a commit 78965ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ func (pool *TxPool) addQiTxsLocked(txs types.Transactions) []error {
for _, tx := range txs {

pool.stateMu.RLock()
fee, _, _, err := ProcessQiTx(tx, pool.chain, false, true, pool.chain.CurrentBlock(), pool.currentState, &gp, new(uint64), pool.signer, pool.chainconfig.Location, *pool.chainconfig.ChainID, &etxRLimit, &etxPLimit)
fee, _, err := ProcessQiTx(tx, pool.chain, false, true, pool.chain.CurrentBlock(), pool.currentState, &gp, new(uint64), pool.signer, pool.chainconfig.Location, *pool.chainconfig.ChainID, &etxRLimit, &etxPLimit)
if err != nil {
pool.stateMu.RUnlock()
pool.logger.WithFields(logrus.Fields{
Expand Down Expand Up @@ -1774,13 +1774,20 @@ func (pool *TxPool) reset(oldHead, newHead *types.WorkObject) {
qiTxs = append(qiTxs, tx)
}
}
pool.mu.Unlock() // Don't lock the pool mutex while holding the qiMu lock
pool.qiMu.Lock()
pool.addQiTxsLocked(qiTxs)
pool.qiMu.Unlock()
pool.mu.Lock()

pool.addTxsLocked(reinject, false)
var wg sync.WaitGroup
wg.Add(1)
go func() {
pool.addTxsLocked(reinject, false)
wg.Done()
}()
wg.Add(1)
go func() {
pool.qiMu.Lock()
pool.addQiTxsLocked(qiTxs)
pool.qiMu.Unlock()
wg.Done()
}()
wg.Wait()
if pool.reOrgCounter == c_reorgCounterThreshold {
pool.logger.WithField("time", common.PrettyDuration(time.Since(start))).Debug("Time taken to resetTxPool")
}
Expand Down
2 changes: 1 addition & 1 deletion quai/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
// c_recentBlockReqTimeout is the timeout for the recent block requests cache
c_recentBlockReqTimeout = 1 * time.Minute
// c_broadcastTransactionsInterval is the interval for broadcasting transactions
c_broadcastTransactionsInterval = 5 * time.Second
c_broadcastTransactionsInterval = 2 * time.Second
// c_maxTxBatchSize is the maximum number of transactions to broadcast at once
c_maxTxBatchSize = 100
)
Expand Down

0 comments on commit 78965ef

Please sign in to comment.