Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: check tx don't need to hold mempool lock #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/7-release-mempool-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[mempool]` relase lock earlier in CheckTx
([#7](https://github.com/crypto-org-chain/cometbft/pull/7))
22 changes: 16 additions & 6 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ func (mem *CListMempool) CheckTx(
tx types.Tx,
cb func(*abci.ResponseCheckTx),
txInfo TxInfo,
) error {
if err := mem.addTxToCache(tx, txInfo); err != nil {
return err
}

reqRes, err := mem.proxyAppConn.CheckTxAsync(context.TODO(), &abci.RequestCheckTx{Tx: tx})
if err != nil {
panic(fmt.Errorf("CheckTx request for tx %s failed: %w", log.NewLazySprintf("%v", tx.Hash()), err))
}
reqRes.SetCallback(mem.reqResCb(tx, txInfo, cb))
return nil
}

func (mem *CListMempool) addTxToCache(
tx types.Tx,
txInfo TxInfo,
) error {
mem.updateMtx.RLock()
// use defer to unlock mutex because application (*local client*) might panic
Expand Down Expand Up @@ -268,12 +284,6 @@ func (mem *CListMempool) CheckTx(
return ErrTxInCache
}

reqRes, err := mem.proxyAppConn.CheckTxAsync(context.TODO(), &abci.RequestCheckTx{Tx: tx})
if err != nil {
panic(fmt.Errorf("CheckTx request for tx %s failed: %w", log.NewLazySprintf("%v", tx.Hash()), err))
}
reqRes.SetCallback(mem.reqResCb(tx, txInfo, cb))

return nil
}

Expand Down
Loading