mempool: migrate rechecktx to be a consensus parameter (#8514)

This commit is contained in:
Callum Waters
2022-05-25 23:57:23 +02:00
committed by GitHub
parent 4c857a7ed2
commit b0ec8a0ea7
46 changed files with 882 additions and 304 deletions
+1
View File
@@ -126,6 +126,7 @@ func makeReactor(
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
eventbus := eventbus.NewDefault(logger)
+1
View File
@@ -35,6 +35,7 @@ func (emptyMempool) Update(
_ []*abci.ExecTxResult,
_ mempool.PreCheckFunc,
_ mempool.PostCheckFunc,
_ bool,
) error {
return nil
}
+2 -1
View File
@@ -420,6 +420,7 @@ func (txmp *TxMempool) Update(
execTxResult []*abci.ExecTxResult,
newPreFn PreCheckFunc,
newPostFn PostCheckFunc,
recheck bool,
) error {
txmp.height = blockHeight
txmp.notifiedTxsAvailable = false
@@ -452,7 +453,7 @@ func (txmp *TxMempool) Update(
// initiate re-CheckTx per remaining transaction or notify that remaining
// transactions are left.
if txmp.Size() > 0 {
if txmp.config.Recheck {
if recheck {
txmp.logger.Debug(
"executing re-CheckTx for all remaining transactions",
"num_txs", txmp.Size(),
+6 -6
View File
@@ -173,7 +173,7 @@ func TestTxMempool_TxsAvailable(t *testing.T) {
// commit half the transactions and ensure we fire an event
txmp.Lock()
require.NoError(t, txmp.Update(ctx, 1, rawTxs[:50], responses, nil, nil))
require.NoError(t, txmp.Update(ctx, 1, rawTxs[:50], responses, nil, nil, true))
txmp.Unlock()
ensureTxFire()
ensureNoTxFire()
@@ -210,7 +210,7 @@ func TestTxMempool_Size(t *testing.T) {
}
txmp.Lock()
require.NoError(t, txmp.Update(ctx, 1, rawTxs[:50], responses, nil, nil))
require.NoError(t, txmp.Update(ctx, 1, rawTxs[:50], responses, nil, nil, true))
txmp.Unlock()
require.Equal(t, len(rawTxs)/2, txmp.Size())
@@ -243,7 +243,7 @@ func TestTxMempool_Flush(t *testing.T) {
}
txmp.Lock()
require.NoError(t, txmp.Update(ctx, 1, rawTxs[:50], responses, nil, nil))
require.NoError(t, txmp.Update(ctx, 1, rawTxs[:50], responses, nil, nil, true))
txmp.Unlock()
txmp.Flush()
@@ -501,7 +501,7 @@ func TestTxMempool_ConcurrentTxs(t *testing.T) {
}
txmp.Lock()
require.NoError(t, txmp.Update(ctx, height, reapedTxs, responses, nil, nil))
require.NoError(t, txmp.Update(ctx, height, reapedTxs, responses, nil, nil, true))
txmp.Unlock()
height++
@@ -547,7 +547,7 @@ func TestTxMempool_ExpiredTxs_NumBlocks(t *testing.T) {
}
txmp.Lock()
require.NoError(t, txmp.Update(ctx, txmp.height+1, reapedTxs, responses, nil, nil))
require.NoError(t, txmp.Update(ctx, txmp.height+1, reapedTxs, responses, nil, nil, true))
txmp.Unlock()
require.Equal(t, 95, txmp.Size())
@@ -573,7 +573,7 @@ func TestTxMempool_ExpiredTxs_NumBlocks(t *testing.T) {
}
txmp.Lock()
require.NoError(t, txmp.Update(ctx, txmp.height+10, reapedTxs, responses, nil, nil))
require.NoError(t, txmp.Update(ctx, txmp.height+10, reapedTxs, responses, nil, nil, true))
txmp.Unlock()
require.GreaterOrEqual(t, txmp.Size(), 45)
+5 -5
View File
@@ -157,13 +157,13 @@ func (_m *Mempool) Unlock() {
_m.Called()
}
// Update provides a mock function with given fields: ctx, blockHeight, blockTxs, txResults, newPreFn, newPostFn
func (_m *Mempool) Update(ctx context.Context, blockHeight int64, blockTxs types.Txs, txResults []*abcitypes.ExecTxResult, newPreFn mempool.PreCheckFunc, newPostFn mempool.PostCheckFunc) error {
ret := _m.Called(ctx, blockHeight, blockTxs, txResults, newPreFn, newPostFn)
// Update provides a mock function with given fields: ctx, blockHeight, blockTxs, txResults, newPreFn, newPostFn, recheck
func (_m *Mempool) Update(ctx context.Context, blockHeight int64, blockTxs types.Txs, txResults []*abcitypes.ExecTxResult, newPreFn mempool.PreCheckFunc, newPostFn mempool.PostCheckFunc, recheck bool) error {
ret := _m.Called(ctx, blockHeight, blockTxs, txResults, newPreFn, newPostFn, recheck)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, int64, types.Txs, []*abcitypes.ExecTxResult, mempool.PreCheckFunc, mempool.PostCheckFunc) error); ok {
r0 = rf(ctx, blockHeight, blockTxs, txResults, newPreFn, newPostFn)
if rf, ok := ret.Get(0).(func(context.Context, int64, types.Txs, []*abcitypes.ExecTxResult, mempool.PreCheckFunc, mempool.PostCheckFunc, bool) error); ok {
r0 = rf(ctx, blockHeight, blockTxs, txResults, newPreFn, newPostFn, recheck)
} else {
r0 = ret.Error(0)
}
+2 -2
View File
@@ -253,7 +253,7 @@ func TestReactorConcurrency(t *testing.T) {
deliverTxResponses[i] = &abci.ExecTxResult{Code: 0}
}
require.NoError(t, mempool.Update(ctx, 1, convertTex(txs), deliverTxResponses, nil, nil))
require.NoError(t, mempool.Update(ctx, 1, convertTex(txs), deliverTxResponses, nil, nil, true))
}()
// 1. submit a bunch of txs
@@ -267,7 +267,7 @@ func TestReactorConcurrency(t *testing.T) {
mempool.Lock()
defer mempool.Unlock()
err := mempool.Update(ctx, 1, []types.Tx{}, make([]*abci.ExecTxResult, 0), nil, nil)
err := mempool.Update(ctx, 1, []types.Tx{}, make([]*abci.ExecTxResult, 0), nil, nil, true)
require.NoError(t, err)
}()
}
+1
View File
@@ -71,6 +71,7 @@ type Mempool interface {
txResults []*abci.ExecTxResult,
newPreFn PreCheckFunc,
newPostFn PostCheckFunc,
recheck bool,
) error
// FlushAppConn flushes the mempool connection to ensure async callback calls
+1
View File
@@ -373,6 +373,7 @@ func (blockExec *BlockExecutor) Commit(
txResults,
TxPreCheckForState(state),
TxPostCheckForState(state),
state.ConsensusParams.ABCI.RecheckTx,
)
return res.Data, res.RetainHeight, err
+5
View File
@@ -64,6 +64,7 @@ func TestApplyBlock(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
blockExec := sm.NewBlockExecutor(stateStore, logger, proxyApp, mp, sm.EmptyEvidencePool{}, blockStore, eventBus, sm.NopMetrics())
@@ -125,6 +126,7 @@ func TestFinalizeBlockDecidedLastCommit(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
eventBus := eventbus.NewDefault(logger)
@@ -250,6 +252,7 @@ func TestFinalizeBlockByzantineValidators(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
eventBus := eventbus.NewDefault(logger)
@@ -511,6 +514,7 @@ func TestFinalizeBlockValidatorUpdates(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
mp.On("ReapMaxBytesMaxGas", mock.Anything, mock.Anything).Return(types.Txs{})
@@ -645,6 +649,7 @@ func TestEmptyPrepareProposal(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
mp.On("ReapMaxBytesMaxGas", mock.Anything, mock.Anything).Return(types.Txs{})
+3
View File
@@ -52,6 +52,7 @@ func TestValidateBlockHeader(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
blockStore := store.NewBlockStore(dbm.NewMemDB())
@@ -158,6 +159,7 @@ func TestValidateBlockCommit(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
blockStore := store.NewBlockStore(dbm.NewMemDB())
@@ -314,6 +316,7 @@ func TestValidateBlockEvidence(t *testing.T) {
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything,
mock.Anything).Return(nil)
state.ConsensusParams.Evidence.MaxBytes = 1000