From 5f85d25c1fa64f77aae8c2e44b5d9b8fb6a274bb Mon Sep 17 00:00:00 2001 From: charithabandi Date: Fri, 14 Feb 2025 08:52:41 -0600 Subject: [PATCH] concurrency access on the mempool from txquery and recheckTxs --- node/block_processor/processor.go | 2 +- node/consensus/block.go | 6 +----- node/mempool/mempool.go | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/node/block_processor/processor.go b/node/block_processor/processor.go index 603815a61..e087d4534 100644 --- a/node/block_processor/processor.go +++ b/node/block_processor/processor.go @@ -268,7 +268,7 @@ func (bp *BlockProcessor) CheckTx(ctx context.Context, tx *ktypes.Transaction, h Authenticator: tx.Signature.Type, }, readTx, tx) if err != nil { - bp.log.Info("Transaction rejected", "tx", txHash, "err", err) + bp.log.Info("Transaction rejected", "tx", txHash, "err", err, "recheck", recheck) return err } diff --git a/node/consensus/block.go b/node/consensus/block.go index 4f550974b..0bbe41c39 100644 --- a/node/consensus/block.go +++ b/node/consensus/block.go @@ -85,11 +85,7 @@ func (ce *ConsensusEngine) recheckTx(ctx context.Context, tx *ktypes.Transaction } ce.stateInfo.mtx.RUnlock() - err := ce.blockProcessor.CheckTx(ctx, tx, height, timestamp, true) - if err != nil { - ce.log.Infof("recheckTx failed for tx %s, err: %s", tx, err) - } - return err + return ce.blockProcessor.CheckTx(ctx, tx, height, timestamp, true) } // BroadcastTx checks the Tx with the mempool and if the verification is successful, broadcasts the Tx to the network. diff --git a/node/mempool/mempool.go b/node/mempool/mempool.go index bb1156d80..d2588d5d3 100644 --- a/node/mempool/mempool.go +++ b/node/mempool/mempool.go @@ -194,8 +194,8 @@ type CheckFn func(ctx context.Context, tx *ktypes.Transaction) error // RecheckTxs validates all transactions in the mempool using the provided check function, // removing any that fail validation. func (mp *Mempool) RecheckTxs(ctx context.Context, fn CheckFn) { - mp.mtx.RLock() - defer mp.mtx.RUnlock() + mp.mtx.Lock() + defer mp.mtx.Unlock() for hash, tx := range mp.txns { if err := fn(ctx, tx.Transaction); err != nil {