-
Notifications
You must be signed in to change notification settings - Fork 412
Inline ignore_error macro #3093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
G8XSU
wants to merge
2
commits into
lightningdevkit:main
Choose a base branch
from
G8XSU:2024-05-08-claimable-persist-3049-outputs-macro
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3233,34 +3233,26 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> { | |
/// height > height + CLTV_SHARED_CLAIM_BUFFER. In any case, will install monitoring for | ||
/// HTLC-Success/HTLC-Timeout transactions. | ||
/// | ||
/// Returns packages to claim the revoked output(s), as well as additional outputs to watch and | ||
/// general information about the output that is to the counterparty in the commitment | ||
/// transaction. | ||
/// Returns packages to claim the revoked output(s) and general information about the output that | ||
/// is to the counterparty in the commitment transaction. | ||
fn check_spend_counterparty_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, block_hash: &BlockHash, logger: &L) | ||
-> (Vec<PackageTemplate>, TransactionOutputs, CommitmentTxCounterpartyOutputInfo) | ||
-> (Vec<PackageTemplate>, CommitmentTxCounterpartyOutputInfo) | ||
where L::Target: Logger { | ||
// Most secp and related errors trying to create keys means we have no hope of constructing | ||
// a spend transaction...so we return no transactions to broadcast | ||
let mut claimable_outpoints = Vec::new(); | ||
let mut watch_outputs = Vec::new(); | ||
let mut to_counterparty_output_info = None; | ||
|
||
let commitment_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers! | ||
let per_commitment_option = self.counterparty_claimable_outpoints.get(&commitment_txid); | ||
|
||
macro_rules! ignore_error { | ||
( $thing : expr ) => { | ||
match $thing { | ||
Ok(a) => a, | ||
Err(_) => return (claimable_outpoints, (commitment_txid, watch_outputs), to_counterparty_output_info) | ||
} | ||
}; | ||
} | ||
|
||
let commitment_number = 0xffffffffffff - ((((tx.input[0].sequence.0 as u64 & 0xffffff) << 3*8) | (tx.lock_time.to_consensus_u32() as u64 & 0xffffff)) ^ self.commitment_transaction_number_obscure_factor); | ||
if commitment_number >= self.get_min_seen_secret() { | ||
let secret = self.get_secret(commitment_number).unwrap(); | ||
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret)); | ||
let per_commitment_key = match SecretKey::from_slice(&secret) { | ||
Ok(per_commitment_key) => per_commitment_key, | ||
Err(_) => return (claimable_outpoints, to_counterparty_output_info) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, blindly ignoring this is a bit of a holdover from when we thought we could use the same |
||
}; | ||
let per_commitment_point = PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key); | ||
let revocation_pubkey = RevocationKey::from_basepoint(&self.onchain_tx_handler.secp_ctx, &self.holder_revocation_basepoint, &per_commitment_point,); | ||
let delayed_key = DelayedPaymentKey::from_basepoint(&self.onchain_tx_handler.secp_ctx, &self.counterparty_commitment_params.counterparty_delayed_payment_base_key, &PublicKey::from_secret_key(&self.onchain_tx_handler.secp_ctx, &per_commitment_key)); | ||
|
@@ -3286,8 +3278,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> { | |
if transaction_output_index as usize >= tx.output.len() || | ||
tx.output[transaction_output_index as usize].value != htlc.to_bitcoin_amount() { | ||
// per_commitment_data is corrupt or our commitment signing key leaked! | ||
return (claimable_outpoints, (commitment_txid, watch_outputs), | ||
to_counterparty_output_info); | ||
return (claimable_outpoints, to_counterparty_output_info); | ||
} | ||
let revk_htlc_outp = RevokedHTLCOutput::build(per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key, htlc.amount_msat / 1000, htlc.clone(), &self.onchain_tx_handler.channel_transaction_parameters.channel_type_features); | ||
let justice_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::RevokedHTLCOutput(revk_htlc_outp), htlc.cltv_expiry, height); | ||
|
@@ -3300,9 +3291,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> { | |
if !claimable_outpoints.is_empty() || per_commitment_option.is_some() { // ie we're confident this is actually ours | ||
// We're definitely a counterparty commitment transaction! | ||
log_error!(logger, "Got broadcast of revoked counterparty commitment transaction, going to generate general spend tx with {} inputs", claimable_outpoints.len()); | ||
for (idx, outp) in tx.output.iter().enumerate() { | ||
watch_outputs.push((idx as u32, outp.clone())); | ||
} | ||
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number); | ||
|
||
if let Some(per_commitment_claimable_data) = per_commitment_option { | ||
|
@@ -3328,9 +3316,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> { | |
// already processed the block, resulting in the counterparty_commitment_txn_on_chain entry | ||
// not being generated by the above conditional. Thus, to be safe, we go ahead and | ||
// insert it here. | ||
for (idx, outp) in tx.output.iter().enumerate() { | ||
watch_outputs.push((idx as u32, outp.clone())); | ||
} | ||
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number); | ||
|
||
log_info!(logger, "Got broadcast of non-revoked counterparty commitment transaction {}", commitment_txid); | ||
|
@@ -3346,7 +3331,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> { | |
} | ||
|
||
} | ||
(claimable_outpoints, (commitment_txid, watch_outputs), to_counterparty_output_info) | ||
(claimable_outpoints, to_counterparty_output_info) | ||
} | ||
|
||
/// Returns the HTLC claim package templates and the counterparty output info | ||
|
@@ -3778,24 +3763,25 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> { | |
self.funding_spend_seen = true; | ||
let mut commitment_tx_to_counterparty_output = None; | ||
if (tx.input[0].sequence.0 >> 8*3) as u8 == 0x80 && (tx.lock_time.to_consensus_u32() >> 8*3) as u8 == 0x20 { | ||
let (mut new_outpoints, new_outputs, counterparty_output_idx_sats) = | ||
self.check_spend_counterparty_transaction(&tx, height, &block_hash, &logger); | ||
commitment_tx_to_counterparty_output = counterparty_output_idx_sats; | ||
if !new_outputs.1.is_empty() { | ||
watch_outputs.push(new_outputs); | ||
} | ||
claimable_outpoints.append(&mut new_outpoints); | ||
if new_outpoints.is_empty() { | ||
if let Some((mut new_outpoints, new_outputs)) = self.check_spend_holder_transaction(&tx, height, &block_hash, &logger) { | ||
#[cfg(not(fuzzing))] | ||
debug_assert!(commitment_tx_to_counterparty_output.is_none(), | ||
"A commitment transaction matched as both a counterparty and local commitment tx?"); | ||
if !new_outputs.1.is_empty() { | ||
watch_outputs.push(new_outputs); | ||
} | ||
claimable_outpoints.append(&mut new_outpoints); | ||
balance_spendable_csv = Some(self.on_holder_tx_csv); | ||
if let Some((mut new_outpoints, new_outputs)) = self.check_spend_holder_transaction(&tx, height, &block_hash, &logger) { | ||
if !new_outputs.1.is_empty() { | ||
watch_outputs.push(new_outputs); | ||
} | ||
|
||
claimable_outpoints.append(&mut new_outpoints); | ||
balance_spendable_csv = Some(self.on_holder_tx_csv); | ||
} else { | ||
let mut new_watch_outputs = Vec::new(); | ||
for (idx, outp) in tx.output.iter().enumerate() { | ||
new_watch_outputs.push((idx as u32, outp.clone())); | ||
} | ||
watch_outputs.push((txid, new_watch_outputs)); | ||
|
||
let (mut new_outpoints, counterparty_output_idx_sats) = | ||
self.check_spend_counterparty_transaction(&tx, height, &block_hash, &logger); | ||
commitment_tx_to_counterparty_output = counterparty_output_idx_sats; | ||
|
||
claimable_outpoints.append(&mut new_outpoints); | ||
} | ||
} | ||
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry { | ||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.