-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: block include nonce mismatch tx issue #16
Conversation
mempool/v0/reactor.go
Outdated
@@ -122,12 +124,14 @@ func (memR *Reactor) OnStart() error { | |||
memR.Logger.Info("Tx broadcasting is disabled") | |||
} | |||
go memR.receiveRoutine() | |||
go memR.checkTxRoutine() | |||
return nil | |||
} | |||
|
|||
// OnStop implements p2p.BaseReactor. | |||
func (memR *Reactor) OnStop() { | |||
close(memR.recvCh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we dont have to close these two channel.
Because the CI check is failed now: https://github.com/bnb-chain/greenfield-cometbft/actions/runs/5574353577/jobs/10189203589?pr=16
.
It is ok leaving there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
mempool/v0/reactor.go
Outdated
if errors.Is(err, mempool.ErrTxInCache) { | ||
memR.Logger.Debug("Tx already exists in cache", "tx", ntx.String()) | ||
} else if err != nil { | ||
memR.Logger.Info("Could not check tx", "tx", ntx.String(), "err", err) | ||
} | ||
} | ||
close(errChan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errChan
can be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
9866402
to
c844fee
Compare
c844fee
to
e926db4
Compare
Description
fix block include nonce mismatch tx issue
Rationale
Currently, there are two possible concurrent invocations of the CheckTx method. The first one is an RPC invocation, and the second one is the simultaneous invocation through different P2P connections.
However, in reality, CheckTx first calls ABCI for basic validation within Cosmos, and upon receiving the cometbft response, it writes to the mempool. The process is illustrated as follows:
mem.proxyAppConn.CheckTxAsync
call ABCIreqRes.SetCallback(mem.reqResCb(tx, txInfo.SenderID, txInfo.SenderP2PID, cb))
writeTx
into mempoolHowever, this creates a problem. When the CPU is particularly busy, if concurrent operations occur here, the temporary scheduling of Goroutines may cause the order of writing to the mempool after ABCI check to be incorrect. Ultimately, this results in incorrect transaction order when packaging blocks.
Therefore, we must ensure that all transaction "checking" and "writing" are executed sequentially. In this PR modification, a channel is introduced to execute transaction requests received from both P2P and RPC in a sequential manner, guaranteeing the correct order of writing to the mempool.
Example
add an example CLI or API response...
Changes
Notable changes: