fix: distinguish dropped txs from mempool txs in esplora confirmations#169
Open
matthewjablack wants to merge 1 commit into
Open
fix: distinguish dropped txs from mempool txs in esplora confirmations#169matthewjablack wants to merge 1 commit into
matthewjablack wants to merge 1 commit into
Conversation
8bac293 to
9560027
Compare
dc8a172 to
acf1469
Compare
acf1469 to
820fa8f
Compare
Root cause: get_transaction_confirmations returned Ok(0) for both mempool txs and dropped/never-broadcast txs. With NB_CONFIRMATIONS=0, the manager's `0 >= 0` check always passed, promoting contracts through states even when their funding tx was never mined. esplora.rs: when the tx is unconfirmed, call get_tx to check if it's actually in the mempool. If the tx is gone, return a TransactionNotFound error instead of Ok(0). This lets consumers distinguish mempool (Ok(0)) from dropped (Err). manager.rs: - close_contract / check_and_broadcast_refund / check_refund: use unwrap_or(0) since the tx may not exist yet (pre-broadcast) - check_confirmed_contract pending_close_txs: skip dropped txs - check_for_spliced_contract: only skip pre-close when the splice fund tx is dropped (Err), not when it is in mempool (Ok(0)) - check_preclosed_contract: on confirmation error for splice closes (no attestations), revert to Confirmed instead of propagating - recover_incorrectly_closed_contracts: new periodic check that finds splice-closed contracts whose closing tx is gone and reverts them
820fa8f to
def648e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause:
get_transaction_confirmationsinesplora.rsreturnedOk(0)for both mempool txs and dropped/never-broadcast txs. WithNB_CONFIRMATIONS=0, the manager's0 >= 0check always passed, promoting contracts through states even when their funding tx was never mined.Changes
ddk/src/chain/esplora.rs— the core fix:confirmed: false), callget_txto check if it's actually in the mempoolOk(0)(existing behavior)Err(TransactionNotFound)instead ofOk(0)get_height()call inside theconfirmedbranch (avoids wasted call when unconfirmed)ddk-manager/src/manager.rs— defense-in-depth + recovery:close_contract/check_and_broadcast_refund/check_refund: useunwrap_or(0)since the tx may not exist yet (pre-broadcast)check_confirmed_contractpending_close_txs: skip dropped txs viaErr(_) => continuecheck_for_spliced_contract: skip pre-close only when the splice fund tx is dropped (Err), not when it's in the mempool (Ok(0))check_preclosed_contract: on confirmation error for splice closes (no attestations), revert to Confirmed instead of propagatingrecover_incorrectly_closed_contracts: new periodic check that finds splice-closed contracts whose closing tx is gone and reverts them to ConfirmedContext
On testnet4 with
NB_CONFIRMATIONS=0, a splice fund tx entered the mempool and ddk walked the parent contract Confirmed → PreClosed → Closed in a singleperiodic_checkcycle. The splice tx was later dropped from mempool, but the contract was already Closed. Subsequent splice attempts failed atget_signature_for_dlc_inputbecause it only accepts Confirmed contracts.