Skip to content

Commit

Permalink
(fixup) Test the reverted CheckTxSync callback parameter from https:/…
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed Jul 13, 2023
1 parent 36637c0 commit 7d5b3f9
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion consensus/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func deliverTxsRange(cs *State, start, end int) {
for i := start; i < end; i++ {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
_, err := assertMempool(cs.txNotifier).CheckTxSync(txBytes, mempl.TxInfo{})
err := assertMempool(cs.txNotifier).CheckTxSync(txBytes, nil, mempl.TxInfo{})
if err != nil {
panic(fmt.Sprintf("Error after CheckTx: %v", err))
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses)

// send a tx
if _, err := assertMempool(css[3].txNotifier).CheckTxSync([]byte{1, 2, 3}, mempl.TxInfo{}); err != nil {
if err := assertMempool(css[3].txNotifier).CheckTxSync([]byte{1, 2, 3}, nil, mempl.TxInfo{}); err != nil {
t.Error(err)
}

Expand Down Expand Up @@ -549,7 +549,7 @@ func waitForAndValidateBlock(
err := validateBlock(newBlock, activeVals)
assert.Nil(t, err)
for _, tx := range txs {
_, err := assertMempool(css[j].txNotifier).CheckTxSync(tx, mempl.TxInfo{})
err := assertMempool(css[j].txNotifier).CheckTxSync(tx, nil, mempl.TxInfo{})
assert.Nil(t, err)
}
}, css)
Expand Down
12 changes: 6 additions & 6 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func sendTxs(ctx context.Context, cs *State) {
return
default:
tx := []byte{byte(i)}
if _, err := assertMempool(cs.txNotifier).CheckTxSync(tx, mempl.TxInfo{}); err != nil {
if err := assertMempool(cs.txNotifier).CheckTxSync(tx, nil, mempl.TxInfo{}); err != nil {
panic(err)
}
i++
Expand Down Expand Up @@ -471,7 +471,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
valPubKey1ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey1)
assert.Nil(t, err)
newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
_, err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx1, mempl.TxInfo{})
err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx1, nil, mempl.TxInfo{})
assert.Nil(t, err)
})

Expand All @@ -485,7 +485,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
updatePubKey1ABCI, err := cryptoenc.PubKeyToProto(updateValidatorPubKey1)
require.NoError(t, err)
updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
_, err = assertMempool(css[0].txNotifier).CheckTxSync(updateValidatorTx1, mempl.TxInfo{})
err = assertMempool(css[0].txNotifier).CheckTxSync(updateValidatorTx1, nil, mempl.TxInfo{})
assert.Nil(t, err)
})

Expand All @@ -502,14 +502,14 @@ func TestSimulateValidatorsChange(t *testing.T) {
newVal2ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey2)
require.NoError(t, err)
newValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, testMinPower)
_, err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx2, mempl.TxInfo{})
err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx2, nil, mempl.TxInfo{})
assert.Nil(t, err)
newValidatorPubKey3, err := css[nVals+2].privValidator.GetPubKey()
require.NoError(t, err)
newVal3ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey3)
require.NoError(t, err)
newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
_, err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx3, mempl.TxInfo{})
err = assertMempool(css[0].txNotifier).CheckTxSync(newValidatorTx3, nil, mempl.TxInfo{})
assert.Nil(t, err)
})

Expand Down Expand Up @@ -549,7 +549,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
newVal3ABCI, err := cryptoenc.PubKeyToProto(newValidatorPubKey3)
require.NoError(t, err)
removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
_, err = assertMempool(css[0].txNotifier).CheckTxSync(removeValidatorTx3, mempl.TxInfo{})
err = assertMempool(css[0].txNotifier).CheckTxSync(removeValidatorTx3, nil, mempl.TxInfo{})
assert.Nil(t, err)
})

Expand Down
4 changes: 2 additions & 2 deletions mempool/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func BenchmarkReap(b *testing.B) {
for i := 0; i < size; i++ {
tx := make([]byte, 8)
binary.BigEndian.PutUint64(tx, uint64(i))
mempool.CheckTxSync(tx, TxInfo{}) // nolint: errcheck
mempool.CheckTxSync(tx, nil, TxInfo{}) // nolint: errcheck
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -53,7 +53,7 @@ func BenchmarkCheckTxSync(b *testing.B) {
for i := 0; i < b.N; i++ {
tx := make([]byte, 8)
binary.BigEndian.PutUint64(tx, uint64(i))
mempool.CheckTxSync(tx, TxInfo{}) // nolint: errcheck
mempool.CheckTxSync(tx, nil, TxInfo{}) // nolint: errcheck
}
}

Expand Down
4 changes: 2 additions & 2 deletions mempool/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestCacheAfterUpdate(t *testing.T) {
for tcIndex, tc := range tests {
for i := 0; i < tc.numTxsToCreate; i++ {
tx := types.Tx{byte(i)}
_, err := mempool.CheckTxSync(tx, TxInfo{})
err := mempool.CheckTxSync(tx, nil, TxInfo{})
require.NoError(t, err)
}

Expand All @@ -74,7 +74,7 @@ func TestCacheAfterUpdate(t *testing.T) {

for _, v := range tc.reAddIndices {
tx := types.Tx{byte(v)}
_, _ = mempool.CheckTxSync(tx, TxInfo{})
_ = mempool.CheckTxSync(tx, nil, TxInfo{})
}

cache := mempool.cache.(*mapTxCache)
Expand Down
46 changes: 23 additions & 23 deletions mempool/clist_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func checkTxs(t *testing.T, mempool Mempool, count int, peerID uint16) types.Txs
if err != nil {
t.Error(err)
}
if _, err := mempool.CheckTxSync(txBytes, txInfo); err != nil {
if err := mempool.CheckTxSync(txBytes, nil, txInfo); err != nil {
// Skip invalid txs.
// TestMempoolFilters will fail otherwise. It asserts a number of txs
// returned.
Expand Down Expand Up @@ -196,15 +196,15 @@ func TestMempoolUpdate(t *testing.T) {
err := mempool.Update(newTestBlock(1, []types.Tx{[]byte{0x01}}),
abciResponses(1, ocabci.CodeTypeOK), nil, nil)
require.NoError(t, err)
_, err = mempool.CheckTxSync([]byte{0x01}, TxInfo{})
err = mempool.CheckTxSync([]byte{0x01}, nil, TxInfo{})
if assert.Error(t, err) {
assert.Equal(t, ErrTxInCache, err)
}
}

// 2. Removes valid txs from the mempool
{
_, err := mempool.CheckTxSync([]byte{0x02}, TxInfo{})
err := mempool.CheckTxSync([]byte{0x02}, nil, TxInfo{})
require.NoError(t, err)
err = mempool.Update(newTestBlock(1, []types.Tx{[]byte{0x02}}), abciResponses(1, ocabci.CodeTypeOK), nil, nil)
require.NoError(t, err)
Expand All @@ -213,13 +213,13 @@ func TestMempoolUpdate(t *testing.T) {

// 3. Removes invalid transactions from the cache and the mempool (if present)
{
_, err := mempool.CheckTxSync([]byte{0x03}, TxInfo{})
err := mempool.CheckTxSync([]byte{0x03}, nil, TxInfo{})
require.NoError(t, err)
err = mempool.Update(newTestBlock(1, []types.Tx{[]byte{0x03}}), abciResponses(1, 1), nil, nil)
require.NoError(t, err)
assert.Zero(t, mempool.Size())

_, err = mempool.CheckTxSync([]byte{0x03}, TxInfo{})
err = mempool.CheckTxSync([]byte{0x03}, nil, TxInfo{})
require.NoError(t, err)
}
}
Expand All @@ -240,7 +240,7 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, 1)

_, err := mempool.CheckTxSync(b, TxInfo{})
err := mempool.CheckTxSync(b, nil, TxInfo{})
require.NoError(t, err)

// simulate new block
Expand All @@ -251,13 +251,13 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) {
require.NoError(t, err)

// a must be added to the cache
_, err = mempool.CheckTxSync(a, TxInfo{})
err = mempool.CheckTxSync(a, nil, TxInfo{})
if assert.Error(t, err) {
assert.Equal(t, ErrTxInCache, err)
}

// b must remain in the cache
_, err = mempool.CheckTxSync(b, TxInfo{})
err = mempool.CheckTxSync(b, nil, TxInfo{})
if assert.Error(t, err) {
assert.Equal(t, ErrTxInCache, err)
}
Expand All @@ -271,10 +271,10 @@ func TestMempool_KeepInvalidTxsInCache(t *testing.T) {
// remove a from the cache to test (2)
mempool.cache.Remove(a)

_, err := mempool.CheckTxSync(a, TxInfo{})
err := mempool.CheckTxSync(a, nil, TxInfo{})
require.NoError(t, err)

_, err = mempool.CheckTxSync(a, TxInfo{})
err = mempool.CheckTxSync(a, nil, TxInfo{})
if assert.Error(t, err) {
assert.Equal(t, ErrTxInCache, err)
}
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestSerialReap(t *testing.T) {
// This will succeed
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
_, err := mempool.CheckTxSync(txBytes, TxInfo{})
err := mempool.CheckTxSync(txBytes, nil, TxInfo{})
_, cached := cacheMap[string(txBytes)]
if cached {
require.NotNil(t, err, "expected error for cached tx")
Expand All @@ -358,7 +358,7 @@ func TestSerialReap(t *testing.T) {
cacheMap[string(txBytes)] = struct{}{}

// Duplicates are cached and should return error
_, err = mempool.CheckTxSync(txBytes, TxInfo{})
err = mempool.CheckTxSync(txBytes, nil, TxInfo{})
require.NotNil(t, err, "Expected error after CheckTx on duplicated tx")
}
}
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestMempoolCloseWAL(t *testing.T) {
require.Equal(t, 1, len(m2), "expecting the wal match in")

// 5. Write some contents to the WAL
_, err = mempool.CheckTxSync(types.Tx([]byte("foo")), TxInfo{})
err = mempool.CheckTxSync(types.Tx([]byte("foo")), nil, TxInfo{})
require.NoError(t, err)
walFilepath := mempool.wal.Path
sum1 := checksumFile(walFilepath, t)
Expand All @@ -477,7 +477,7 @@ func TestMempoolCloseWAL(t *testing.T) {
// 7. Invoke CloseWAL() and ensure it discards the
// WAL thus any other write won't go through.
mempool.CloseWAL()
_, err = mempool.CheckTxSync(types.Tx([]byte("bar")), TxInfo{})
err = mempool.CheckTxSync(types.Tx([]byte("bar")), nil, TxInfo{})
require.NoError(t, err)
sum2 := checksumFile(walFilepath, t)
require.Equal(t, sum1, sum2, "expected no change to the WAL after invoking CloseWAL() since it was discarded")
Expand Down Expand Up @@ -516,7 +516,7 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) {

tx := tmrand.Bytes(testCase.len)

_, err := mempl.CheckTxSync(tx, TxInfo{})
err := mempl.CheckTxSync(tx, nil, TxInfo{})
bv := gogotypes.BytesValue{Value: tx}
bz, err2 := bv.Marshal()
require.NoError(t, err2)
Expand All @@ -542,7 +542,7 @@ func TestMempoolTxsBytes(t *testing.T) {
assert.EqualValues(t, 0, mempool.TxsBytes())

// 2. len(tx) after CheckTx
_, err := mempool.CheckTxSync([]byte{0x01}, TxInfo{})
err := mempool.CheckTxSync([]byte{0x01}, nil, TxInfo{})
require.NoError(t, err)
assert.EqualValues(t, 1, mempool.TxsBytes())

Expand All @@ -553,17 +553,17 @@ func TestMempoolTxsBytes(t *testing.T) {
assert.EqualValues(t, 0, mempool.TxsBytes())

// 4. zero after Flush
_, err = mempool.CheckTxSync([]byte{0x02, 0x03}, TxInfo{})
err = mempool.CheckTxSync([]byte{0x02, 0x03}, nil, TxInfo{})
require.NoError(t, err)
assert.EqualValues(t, 2, mempool.TxsBytes())

mempool.Flush()
assert.EqualValues(t, 0, mempool.TxsBytes())

// 5. ErrMempoolIsFull is returned when/if MaxTxsBytes limit is reached.
_, err = mempool.CheckTxSync([]byte{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}, TxInfo{})
err = mempool.CheckTxSync([]byte{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}, nil, TxInfo{})
require.NoError(t, err)
_, err = mempool.CheckTxSync([]byte{0x05}, TxInfo{})
err = mempool.CheckTxSync([]byte{0x05}, nil, TxInfo{})
if assert.Error(t, err) {
assert.IsType(t, ErrMempoolIsFull{}, err)
}
Expand All @@ -577,7 +577,7 @@ func TestMempoolTxsBytes(t *testing.T) {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(0))

_, err = mempool.CheckTxSync(txBytes, TxInfo{})
err = mempool.CheckTxSync(txBytes, nil, TxInfo{})
require.NoError(t, err)
assert.EqualValues(t, 8, mempool.TxsBytes())

Expand All @@ -603,7 +603,7 @@ func TestMempoolTxsBytes(t *testing.T) {
assert.EqualValues(t, 0, mempool.TxsBytes())

// 7. Test RemoveTxByKey function
_, err = mempool.CheckTxSync([]byte{0x06}, TxInfo{})
err = mempool.CheckTxSync([]byte{0x06}, nil, TxInfo{})
require.NoError(t, err)
assert.EqualValues(t, 1, mempool.TxsBytes())
mempool.RemoveTxByKey(TxKey([]byte{0x07}), true)
Expand Down Expand Up @@ -647,7 +647,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) {
tx := txs[txNum]

// this will err with ErrTxInCache many times ...
mempool.CheckTxSync(tx, TxInfo{SenderID: uint16(peerID)}) // nolint: errcheck
mempool.CheckTxSync(tx, nil, TxInfo{SenderID: uint16(peerID)}) // nolint: errcheck
}
err := mempool.FlushAppConn()
require.NoError(t, err)
Expand Down Expand Up @@ -731,7 +731,7 @@ func TestTxMempoolPostCheckError(t *testing.T) {
}

tx := types.Tx{1}
_, err := mempool.CheckTxSync(tx, TxInfo{})
err := mempool.CheckTxSync(tx, nil, TxInfo{})
require.NoError(t, err)

req := abci.RequestCheckTx{
Expand Down
4 changes: 2 additions & 2 deletions mempool/mock/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var _ mempl.Mempool = Mempool{}
func (Mempool) Lock() {}
func (Mempool) Unlock() {}
func (Mempool) Size() int { return 0 }
func (Mempool) CheckTxSync(_ types.Tx, _ mempl.TxInfo) (*ocabci.Response, error) {
return nil, nil
func (Mempool) CheckTxSync(_ types.Tx, _ func(*ocabci.Response), _ mempl.TxInfo) error {
return nil
}
func (Mempool) CheckTxAsync(_ types.Tx, _ mempl.TxInfo, _ func(error), _ func(*ocabci.Response)) {
}
Expand Down
4 changes: 2 additions & 2 deletions mempool/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestReactor_MaxTxBytes(t *testing.T) {
// Broadcast a tx, which has the max size
// => ensure it's received by the second reactor.
tx1 := tmrand.Bytes(config.Mempool.MaxTxBytes)
_, err := reactors[0].mempool.CheckTxSync(tx1, TxInfo{SenderID: UnknownPeerID})
err := reactors[0].mempool.CheckTxSync(tx1, nil, TxInfo{SenderID: UnknownPeerID})
require.NoError(t, err)
waitForTxsOnReactors(t, []types.Tx{tx1}, reactors)

Expand All @@ -187,7 +187,7 @@ func TestReactor_MaxTxBytes(t *testing.T) {
// Broadcast a tx, which is beyond the max size
// => ensure it's not sent
tx2 := tmrand.Bytes(config.Mempool.MaxTxBytes + 1)
_, err = reactors[0].mempool.CheckTxSync(tx2, TxInfo{SenderID: UnknownPeerID})
err = reactors[0].mempool.CheckTxSync(tx2, nil, TxInfo{SenderID: UnknownPeerID})
require.Error(t, err)
}

Expand Down
4 changes: 2 additions & 2 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestCreateProposalBlock(t *testing.T) {
txLength := 100
for i := 0; i <= maxBytes/txLength; i++ {
tx := tmrand.Bytes(txLength)
_, err := mempool.CheckTxSync(tx, mempl.TxInfo{})
err := mempool.CheckTxSync(tx, nil, mempl.TxInfo{})
assert.NoError(t, err)
}

Expand Down Expand Up @@ -377,7 +377,7 @@ func TestMaxProposalBlockSize(t *testing.T) {
// fill the mempool with one txs just below the maximum size
txLength := int(types.MaxDataBytesNoEvidence(maxBytes, 1))
tx := tmrand.Bytes(txLength - 4) // to account for the varint
_, err = mempool.CheckTxSync(tx, mempl.TxInfo{})
err = mempool.CheckTxSync(tx, nil, mempl.TxInfo{})
assert.NoError(t, err)

blockExec := sm.NewBlockExecutor(
Expand Down
2 changes: 1 addition & 1 deletion test/fuzz/mempool/checktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
}

func Fuzz(data []byte) int {
_, err := mempool.CheckTxSync(data, mempl.TxInfo{})
err := mempool.CheckTxSync(data, nil, mempl.TxInfo{})
if err != nil {
return 0
}
Expand Down

0 comments on commit 7d5b3f9

Please sign in to comment.