-
Notifications
You must be signed in to change notification settings - Fork 20
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: mempool lane size check on CheckTx
#561
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #561 +/- ##
==========================================
+ Coverage 43.59% 45.06% +1.46%
==========================================
Files 63 63
Lines 2812 2920 +108
==========================================
+ Hits 1226 1316 +90
- Misses 1459 1469 +10
- Partials 127 135 +8 ☔ View full report in Codecov by Sentry. |
// GetContextForTx is returns the latest committed state and sets the context given | ||
// the checkTx request. | ||
func (m MempoolParityCheckTx) GetContextForTx(req *cmtabci.RequestCheckTx) sdk.Context { | ||
// Retrieve the commit multi-store which is used to retrieve the latest committed state. | ||
ms := m.baseApp.CommitMultiStore().CacheMultiStore() | ||
|
||
// Create a new context based off of the latest committed state. | ||
header := cmtproto.Header{ | ||
Height: m.baseApp.LastBlockHeight(), | ||
ChainID: m.baseApp.ChainID(), | ||
} | ||
ctx, _ := sdk.NewContext(ms, header, true, m.baseApp.Logger()).CacheContext() | ||
|
||
// Set the context to the correct checking mode. | ||
switch req.Type { | ||
case cmtabci.CheckTxType_New: | ||
ctx = ctx.WithIsCheckTx(true) | ||
case cmtabci.CheckTxType_Recheck: | ||
ctx = ctx.WithIsReCheckTx(true) | ||
default: | ||
panic("unknown check tx type") | ||
} | ||
|
||
// Set the remaining important context values. | ||
ctx = ctx. | ||
WithTxBytes(req.Tx). | ||
WithEventManager(sdk.NewEventManager()). | ||
WithConsensusParams(m.baseApp.GetConsensusParams(ctx)) | ||
|
||
return ctx | ||
} |
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.
can you benchmarket how long this takes just so we have a reference on the slowdown we expected? I imagine some of this is not necessary.
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.
How would you imagine benchmarking this?
Start a small in mem test app and call this on it?
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.
benchmarking with a real simapp would be better, but probably not important to get this shipped. fine as is
sdkCtx := m.GetContextForTx(req) | ||
lane, err := m.matchLane(sdkCtx, tx) | ||
if err != nil { | ||
m.logger.Debug("failed to match lane", "lane", lane, "err", err) | ||
return sdkerrors.ResponseCheckTxWithEvents( | ||
err, | ||
0, | ||
0, | ||
nil, | ||
false, | ||
), nil | ||
} | ||
|
||
consensusParams := sdkCtx.ConsensusParams() | ||
laneSize := lane.GetMaxBlockSpace().MulInt64(consensusParams.GetBlock().GetMaxBytes()).TruncateInt64() | ||
|
||
txSize := int64(len(req.Tx)) | ||
if txSize > laneSize { | ||
m.logger.Debug( | ||
"tx size exceeds max block bytes", | ||
"tx", tx, | ||
"tx size", txSize, | ||
"max bytes", laneSize, | ||
) | ||
|
||
return sdkerrors.ResponseCheckTxWithEvents( | ||
fmt.Errorf("tx size exceeds max block bytes"), | ||
0, | ||
0, | ||
nil, | ||
false, | ||
), nil | ||
} |
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.
Does it make sense to do this check before the entire ante-handler sequence is run?
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'm not sure - I think the case with a huge Tx is much less likely than the case where youre Tx just fails the antehandler. So i would rather run that and have the matching logic done later only when we need to
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.
lgtm
* push * init * fix setup * format * fix test * use lane * ok * finalize * fix everything * lint fix: * Update abci/checktx/mempool_parity_check_tx.go Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> * lint fix * tidy * remove * cleanup --------- Co-authored-by: David Terpay <david.terpay@gmail.com> Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> (cherry picked from commit f1cde2a) # Conflicts: # README.md # abci/abci.go # abci/checktx/check_tx_test.go # abci/checktx/mempool_parity_check_tx.go # block/mocks/lane.go # block/mocks/lane_mempool.go # go.mod # go.sum # tests/app/app.go # tests/app/testappd/cmd/testnet.go # x/auction/types/mocks/bank_keeper.go # x/auction/types/mocks/staking_keeper.go
* push * init * fix setup * format * fix test * use lane * ok * finalize * fix everything * lint fix: * Update abci/checktx/mempool_parity_check_tx.go Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> * lint fix * tidy * remove * cleanup --------- Co-authored-by: David Terpay <david.terpay@gmail.com> Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> (cherry picked from commit f1cde2a) # Conflicts: # README.md # go.mod # go.sum # x/auction/types/mocks/account_keeper.go # x/auction/types/mocks/bank_keeper.go # x/auction/types/mocks/distribution_keeper.go # x/auction/types/mocks/rewards_address_provider.go # x/auction/types/mocks/staking_keeper.go
* fix: mempool lane size check on `CheckTx` (#561) * push * init * fix setup * format * fix test * use lane * ok * finalize * fix everything * lint fix: * Update abci/checktx/mempool_parity_check_tx.go Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> * lint fix * tidy * remove * cleanup --------- Co-authored-by: David Terpay <david.terpay@gmail.com> Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> (cherry picked from commit f1cde2a) # Conflicts: # README.md # go.mod # go.sum # x/auction/types/mocks/account_keeper.go # x/auction/types/mocks/bank_keeper.go # x/auction/types/mocks/distribution_keeper.go # x/auction/types/mocks/rewards_address_provider.go # x/auction/types/mocks/staking_keeper.go * fix * tidy --------- Co-authored-by: Alex Johnson <alex@skip.money>
* fix: mempool lane size check on `CheckTx` (#561) * push * init * fix setup * format * fix test * use lane * ok * finalize * fix everything * lint fix: * Update abci/checktx/mempool_parity_check_tx.go Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> * lint fix * tidy * remove * cleanup --------- Co-authored-by: David Terpay <david.terpay@gmail.com> Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> (cherry picked from commit f1cde2a) # Conflicts: # README.md # abci/abci.go # abci/checktx/check_tx_test.go # abci/checktx/mempool_parity_check_tx.go # block/mocks/lane.go # block/mocks/lane_mempool.go # go.mod # go.sum # tests/app/app.go # tests/app/testappd/cmd/testnet.go # x/auction/types/mocks/bank_keeper.go # x/auction/types/mocks/staking_keeper.go * bettington --------- Co-authored-by: Alex Johnson <alex@skip.money>
Closes BLO-1473