Skip to content

Delete withdrawal bundle event block from the correct db on disconnect#85

Open
1440000bytes wants to merge 2 commits into
LayerTwo-Labs:masterfrom
1440000bytes:fix-disconnect-wrong-event-block-table
Open

Delete withdrawal bundle event block from the correct db on disconnect#85
1440000bytes wants to merge 2 commits into
LayerTwo-Labs:masterfrom
1440000bytes:fix-disconnect-wrong-event-block-table

Conversation

@1440000bytes

Copy link
Copy Markdown

In disconnect, the withdrawal-event branch reads the sequence index from withdrawal_bundle_event_blocks.last() but deletes that index from deposit_blocks:

let (last_withdrawal_bundle_event_block_seq_idx, ...) = state
    .withdrawal_bundle_event_blocks
    .last(rwtxn)? ... ;
...
if !state
    .deposit_blocks
    .delete(rwtxn, &last_withdrawal_bundle_event_block_seq_idx)?
{
    return Err(Error::NoWithdrawalBundleEventBlock);
};

So on a reorg disconnecting a two-way peg block that carries a withdrawal bundle event, the event-block record is never removed, and an unrelated deposit record sharing the same sequence index is deleted instead (or the disconnect errors if no such deposit record exists). Both get_last_deposit_block_hash and get_last_withdrawal_bundle_event_block_hash drive mainchain sync position, so this corrupts deposit/withdrawal tracking and can diverge state across nodes.

Fix

Delete from withdrawal_bundle_event_blocks, matching the lookup and mirroring the deposit branch just below.

Test

Added a unit test that seeds a withdrawal_bundle_event_blocks row and a deposit_blocks row at the same index, disconnects a withdrawal bundle event and asserts the event-block row is removed while the deposit row survives. It fails on the old code and passes with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant