feat(miner): improve pruneTransactions (#411)

This commit is contained in:
David 2025-04-01 15:19:52 +08:00 committed by GitHub
parent 682235849b
commit 7a019ea44b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -391,9 +391,14 @@ func pruneTransactions(
var (
prunedTxs []*types.Transaction
prunedReceipts []*types.Receipt
step = TxListCompressionPruneStep
)
for len(txs) > 0 {
if len(txs) <= step {
step = 1
}
b, err := encodeAndCompressTxList(txs)
if err != nil {
return nil, err
@ -406,17 +411,11 @@ func pruneTransactions(
Size: len(b),
}, nil
}
if len(txs) < TxListCompressionPruneStep {
prunedTxs = append(txs, prunedTxs...)
prunedReceipts = append(receipts, prunedReceipts...)
txs = []*types.Transaction{}
receipts = []*types.Receipt{}
break
}
prunedTxs = append(txs[len(txs)-TxListCompressionPruneStep:], prunedTxs...)
prunedReceipts = append(receipts[len(receipts)-TxListCompressionPruneStep:], prunedReceipts...)
txs = txs[:len(txs)-TxListCompressionPruneStep]
receipts = receipts[:len(receipts)-TxListCompressionPruneStep]
prunedTxs = append(txs[len(txs)-step:], prunedTxs...)
prunedReceipts = append(receipts[len(receipts)-step:], prunedReceipts...)
txs = txs[:len(txs)-step]
receipts = receipts[:len(receipts)-step]
}
// All transactions are pruned.