Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public async Task When_NewHeadBlock_Remove_TxIndex_OfRemovedBlock_Unless_ItsAlso
}

[Test]
public void When_NewHeadBlock_ClearOldTxIndex()
public void When_NewHeadBlock_ClearOldTxIndex_And_KeepsReceipts()
{
_receiptConfig.TxLookupLimit = 1000;
CreateStorage();
Expand All @@ -466,6 +466,7 @@ public void When_NewHeadBlock_ClearOldTxIndex()
() => _receiptsDb.GetColumnDb(ReceiptsColumns.Transactions)[receipts[0].TxHash!.Bytes],
Is.Null.After(1000, 100)
);
Assert.That(_storage.HasBlock(receipts[0].BlockNumber, receipts[0].BlockHash!));
}

private (Block block, TxReceipt[] receipts) PrepareBlock(Block? block = null, bool isFinalized = false, long? headNumber = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void BlockTreeOnBlockAddedToMain(object? sender, BlockReplacementEventAr
Block newOldTx = _blockTree.FindBlock(newMain.Number - _receiptConfig.TxLookupLimit.Value);
if (newOldTx is not null)
{
RemoveReceipts(newOldTx);
RemoveBlockTx(newOldTx);
}
}
});
Expand Down Expand Up @@ -338,6 +338,11 @@ public void RemoveReceipts(Block block)
GetBlockNumPrefixedKey(block.Number, block.Hash, blockNumPrefixed);
_receiptsDb.Remove(blockNumPrefixed);

RemoveBlockTx(block);
}

private void RemoveBlockTx(Block block)
{
using IWriteBatch writeBatch = _transactionDb.StartWriteBatch();
foreach (Transaction tx in block.Transactions)
{
Expand Down