Skip to content

Spend reinstated utxos when disconnecting a failed withdrawal bundle#84

Open
1440000bytes wants to merge 2 commits into
LayerTwo-Labs:masterfrom
1440000bytes:fix-disconnect-failed-bundle-utxo-delete
Open

Spend reinstated utxos when disconnecting a failed withdrawal bundle#84
1440000bytes wants to merge 2 commits into
LayerTwo-Labs:masterfrom
1440000bytes:fix-disconnect-failed-bundle-utxo-delete

Conversation

@1440000bytes

Copy link
Copy Markdown

disconnect_withdrawal_bundle_failed has an inverted check on the utxo delete:

if state.utxos.delete(rwtxn, &OutPointKey::from(outpoint))? {
    return Err(error::NoUtxo { outpoint: *outpoint }.into());
};

delete returns true when it actually removes an entry. When a known withdrawal bundle fails, connect_withdrawal_bundle_failed reinstates its utxos as spendable. So on disconnect the utxo is present, delete returns true and the function errors with NoUtxo in the normal case.

The result is that a reorg disconnecting a block that carries a Failed event for a known bundle always fails, leaving the node unable to follow the better mainchain branch. Every other delete check in the file is correct.

Fix

Negate the condition so it errors only when the utxo is unexpectedly absent and spends it back into stxos otherwise.

Test

Added a unit test that reproduces the post-failure state (known bundle with its utxo reinstated), disconnects the failure and asserts the utxo is re-spent. It fails on the old code with the NoUtxo error 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