Skip to content

Commit c5214c2

Browse files
authored
Merge pull request #2089 from wpaulino/bump-transaction-event-handler
Add BumpTransaction event handler
2 parents c3c1050 + bc39da6 commit c5214c2

File tree

8 files changed

+654
-72
lines changed

8 files changed

+654
-72
lines changed

lightning/src/chain/channelmonitor.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
25392539
let mut ret = Vec::new();
25402540
mem::swap(&mut ret, &mut self.pending_events);
25412541
#[cfg(anchors)]
2542-
for claim_event in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) {
2542+
for (claim_id, claim_event) in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) {
25432543
match claim_event {
25442544
ClaimEvent::BumpCommitment {
25452545
package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx,
@@ -2550,6 +2550,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
25502550
let commitment_tx_fee_satoshis = self.channel_value_satoshis -
25512551
commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value);
25522552
ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose {
2553+
claim_id,
25532554
package_target_feerate_sat_per_1000_weight,
25542555
commitment_tx,
25552556
commitment_tx_fee_satoshis,
@@ -2581,6 +2582,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
25812582
});
25822583
}
25832584
ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
2585+
claim_id,
25842586
target_feerate_sat_per_1000_weight,
25852587
htlc_descriptors,
25862588
tx_lock_time,

lightning/src/chain/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,7 @@ where
389389
self.1.block_disconnected(header, height);
390390
}
391391
}
392+
393+
/// A unique identifier to track each pending output claim within a [`ChannelMonitor`].
394+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
395+
pub struct ClaimId(pub [u8; 32]);

lightning/src/chain/onchaintx.rs

+72-66
Large diffs are not rendered by default.

lightning/src/events/bump_transaction.rs

+552-2
Large diffs are not rendered by default.

lightning/src/events/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ use crate::util::string::UntrustedString;
3333
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
3434

3535
use bitcoin::{PackedLockTime, Transaction, OutPoint};
36-
#[cfg(anchors)]
37-
use bitcoin::{Txid, TxIn, TxOut, Witness};
3836
use bitcoin::blockdata::script::Script;
3937
use bitcoin::hashes::Hash;
4038
use bitcoin::hashes::sha256::Hash as Sha256;

lightning/src/ln/chan_utils.rs

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ pub(crate) const MIN_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 136;
5757
/// This is the maximum post-anchor value.
5858
pub const MAX_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 143;
5959

60+
/// The upper bound weight of an anchor input.
61+
pub const ANCHOR_INPUT_WITNESS_WEIGHT: u64 = 116;
62+
/// The upper bound weight of an HTLC timeout input from a commitment transaction with anchor
63+
/// outputs.
64+
pub const HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 288;
65+
/// The upper bound weight of an HTLC success input from a commitment transaction with anchor
66+
/// outputs.
67+
pub const HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT: u64 = 327;
68+
6069
/// Gets the weight for an HTLC-Success transaction.
6170
#[inline]
6271
pub fn htlc_success_tx_weight(opt_anchors: bool) -> u64 {

lightning/src/ln/monitor_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
17851785
let mut feerate = 0;
17861786
#[cfg(anchors)] {
17871787
feerate = if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
1788-
target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time,
1788+
target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time, ..
17891789
}) = events.pop().unwrap() {
17901790
let secp = Secp256k1::new();
17911791
assert_eq!(htlc_descriptors.len(), 1);

lightning/src/util/ser.rs

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
3737
use bitcoin::hash_types::{Txid, BlockHash};
3838
use core::marker::Sized;
3939
use core::time::Duration;
40+
use crate::chain::ClaimId;
4041
use crate::ln::msgs::DecodeError;
4142
#[cfg(taproot)]
4243
use crate::ln::msgs::PartialSignatureWithNonce;
@@ -1409,6 +1410,18 @@ impl Readable for TransactionU16LenLimited {
14091410
}
14101411
}
14111412

1413+
impl Writeable for ClaimId {
1414+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
1415+
self.0.write(writer)
1416+
}
1417+
}
1418+
1419+
impl Readable for ClaimId {
1420+
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
1421+
Ok(Self(Readable::read(reader)?))
1422+
}
1423+
}
1424+
14121425
#[cfg(test)]
14131426
mod tests {
14141427
use core::convert::TryFrom;

0 commit comments

Comments
 (0)