Skip to content
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

Add BumpTransaction event handler #2089

Merged
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
4 changes: 3 additions & 1 deletion lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let mut ret = Vec::new();
mem::swap(&mut ret, &mut self.pending_events);
#[cfg(anchors)]
for claim_event in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) {
for (claim_id, claim_event) in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) {
match claim_event {
ClaimEvent::BumpCommitment {
package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx,
Expand All @@ -2516,6 +2516,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
let commitment_tx_fee_satoshis = self.channel_value_satoshis -
commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value);
ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose {
claim_id,
package_target_feerate_sat_per_1000_weight,
commitment_tx,
commitment_tx_fee_satoshis,
Expand Down Expand Up @@ -2547,6 +2548,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
});
}
ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
claim_id,
target_feerate_sat_per_1000_weight,
htlc_descriptors,
tx_lock_time,
Expand Down
4 changes: 4 additions & 0 deletions lightning/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ where
self.1.block_disconnected(header, height);
}
}

/// A unique identifier to track each pending output claim within a [`ChannelMonitor`].
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct ClaimId(pub [u8; 32]);
138 changes: 72 additions & 66 deletions lightning/src/chain/onchaintx.rs

Large diffs are not rendered by default.

554 changes: 552 additions & 2 deletions lightning/src/events/bump_transaction.rs

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ use crate::util::string::UntrustedString;
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};

use bitcoin::{PackedLockTime, Transaction, OutPoint};
#[cfg(anchors)]
use bitcoin::{Txid, TxIn, TxOut, Witness};
use bitcoin::blockdata::script::Script;
use bitcoin::hashes::Hash;
use bitcoin::hashes::sha256::Hash as Sha256;
Expand Down
9 changes: 9 additions & 0 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ pub(crate) const MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 136;
/// This is the maximum post-anchor value.
pub const MAX_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 143;

/// The upper bound weight of an anchor input.
pub const ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 116;
/// The upper bound weight of an HTLC timeout input from a commitment transaction with anchor
/// outputs.
pub const HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 288;
/// The upper bound weight of an HTLC success input from a commitment transaction with anchor
/// outputs.
pub const HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 327;

/// Gets the weight for an HTLC-Success transaction.
#[inline]
pub fn htlc_success_tx_weight(opt_anchors: bool) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/monitor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
let mut feerate = 0;
#[cfg(anchors)] {
feerate = if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time,
target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time, ..
}) = events.pop().unwrap() {
let secp = Secp256k1::new();
assert_eq!(htlc_descriptors.len(), 1);
Expand Down
13 changes: 13 additions & 0 deletions lightning/src/util/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin::hash_types::{Txid, BlockHash};
use core::marker::Sized;
use core::time::Duration;
use crate::chain::ClaimId;
use crate::ln::msgs::DecodeError;
#[cfg(taproot)]
use crate::ln::msgs::PartialSignatureWithNonce;
Expand Down Expand Up @@ -1393,6 +1394,18 @@ impl Readable for TransactionU16LenLimited {
}
}

impl Writeable for ClaimId {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
self.0.write(writer)
}
}

impl Readable for ClaimId {
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
Ok(Self(Readable::read(reader)?))
}
}

#[cfg(test)]
mod tests {
use core::convert::TryFrom;
Expand Down