Skip to content

Commit aa0e2a4

Browse files
authoredNov 19, 2021
Add ability to remove "Parent" transactions from the mempool (celestiaorg#582)
* add the new transaction wrapper * export and move DecodeChildTx * return a more precise type (Tx instead of []byte) for DecodeChildTx * add test and helper function * linter
·
1 parent 7828d21 commit aa0e2a4

File tree

6 files changed

+407
-113
lines changed

6 files changed

+407
-113
lines changed
 

‎buf.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: v1beta1
2+
13
build:
24
roots:
35
- proto

‎mempool/clist_mempool.go

+6
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,12 @@ func (mem *CListMempool) Update(
605605
// https://github.com/tendermint/tendermint/issues/3322.
606606
if e, ok := mem.txsMap.Load(TxKey(tx)); ok {
607607
mem.removeTx(tx, e.(*clist.CElement), false)
608+
// see if the transaction is a child transaction of a some parent
609+
// transaction that exists in the mempool
610+
} else if parentHash, _, isChild := types.DecodeChildTx(tx); isChild {
611+
var parentKey [TxKeySize]byte
612+
copy(parentKey[:], parentHash)
613+
mem.RemoveTxByKey(parentKey, false)
608614
}
609615
}
610616

‎mempool/clist_mempool_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,29 @@ func TestMempoolUpdate(t *testing.T) {
214214
err = mempool.CheckTx([]byte{0x03}, nil, TxInfo{})
215215
require.NoError(t, err)
216216
}
217+
218+
// 4. Removes a parent transaction after receiving a child transaction in the update
219+
{
220+
mempool.Flush()
221+
parentTx := []byte{1, 2, 3, 4}
222+
childTx := []byte{1, 2}
223+
parentHash := sha256.Sum256(parentTx)
224+
225+
// create the wrapped child transaction
226+
wTx, err := types.WrapChildTx(parentHash[:], childTx)
227+
require.NoError(t, err)
228+
229+
// add the parent transaction to the mempool
230+
err = mempool.CheckTx(parentTx, nil, TxInfo{})
231+
require.NoError(t, err)
232+
233+
// remove the parent from the mempool using the wrapped child tx
234+
err = mempool.Update(1, []types.Tx{wTx}, abciResponses(1, abci.CodeTypeOK), nil, nil)
235+
require.NoError(t, err)
236+
237+
assert.Zero(t, mempool.Size())
238+
239+
}
217240
}
218241

219242
func TestMempool_KeepInvalidTxsInCache(t *testing.T) {

0 commit comments

Comments
 (0)
Please sign in to comment.