Skip to content

Commit 6ba7461

Browse files
committed
Refactor TransactionType with channel context
We add the `ChannelId` as context to the just-added `TransactionType` enum. Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent 851f00d commit 6ba7461

File tree

10 files changed

+33
-30
lines changed

10 files changed

+33
-30
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, Messa
3737
use lightning::blinded_path::payment::{BlindedPaymentPath, ReceiveTlvs};
3838
use lightning::chain;
3939
use lightning::chain::chaininterface::{
40-
BroadcastType, BroadcasterInterface, ConfirmationTarget, FeeEstimator,
40+
TransactionType, BroadcasterInterface, ConfirmationTarget, FeeEstimator,
4141
};
4242
use lightning::chain::channelmonitor::{ChannelMonitor, MonitorEvent};
4343
use lightning::chain::transaction::OutPoint;
@@ -161,7 +161,7 @@ pub struct TestBroadcaster {
161161
txn_broadcasted: RefCell<Vec<Transaction>>,
162162
}
163163
impl BroadcasterInterface for TestBroadcaster {
164-
fn broadcast_transactions(&self, txs: &[(&Transaction, BroadcastType)]) {
164+
fn broadcast_transactions(&self, txs: &[(&Transaction, TransactionType)]) {
165165
for (tx, _broadcast_type) in txs {
166166
self.txn_broadcasted.borrow_mut().push((*tx).clone());
167167
}

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, Messa
3434
use lightning::blinded_path::payment::{BlindedPaymentPath, ReceiveTlvs};
3535
use lightning::chain;
3636
use lightning::chain::chaininterface::{
37-
BroadcastType, BroadcasterInterface, ConfirmationTarget, FeeEstimator,
37+
TransactionType, BroadcasterInterface, ConfirmationTarget, FeeEstimator,
3838
};
3939
use lightning::chain::chainmonitor;
4040
use lightning::chain::transaction::OutPoint;
@@ -186,7 +186,7 @@ struct TestBroadcaster {
186186
txn_broadcasted: Mutex<Vec<Transaction>>,
187187
}
188188
impl BroadcasterInterface for TestBroadcaster {
189-
fn broadcast_transactions(&self, txs: &[(&Transaction, BroadcastType)]) {
189+
fn broadcast_transactions(&self, txs: &[(&Transaction, TransactionType)]) {
190190
let owned_txs: Vec<Transaction> = txs.iter().map(|(tx, _)| (*tx).clone()).collect();
191191
self.txn_broadcasted.lock().unwrap().extend(owned_txs);
192192
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["--cfg=lsps1_service"]

lightning-liquidity/src/lsps2/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::prelude::{new_hash_map, HashMap};
4040
use crate::sync::{Arc, Mutex, MutexGuard, RwLock};
4141
use crate::utils::async_poll::dummy_waker;
4242

43-
use lightning::chain::chaininterface::{BroadcastType, BroadcasterInterface};
43+
use lightning::chain::chaininterface::{BroadcasterInterface, TransactionType};
4444
use lightning::events::HTLCHandlingFailureType;
4545
use lightning::ln::channelmanager::{AChannelManager, FailureCode, InterceptId};
4646
use lightning::ln::msgs::{ErrorAction, LightningError};
@@ -2038,7 +2038,7 @@ where
20382038
if let Some(funding_tx) = jit_channel.get_funding_tx() {
20392039
self.tx_broadcaster.broadcast_transactions(&[(
20402040
funding_tx,
2041-
BroadcastType::Funding { channel_ids: vec![ch_id] },
2041+
TransactionType::Funding { channel_ids: vec![ch_id] },
20422042
)]);
20432043
}
20442044
}

lightning/src/chain/chaininterface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bitcoin::transaction::Transaction;
2525
/// This is used to provide context about the type of transaction being broadcast, which may be
2626
/// useful for logging, filtering, or prioritization purposes.
2727
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
28-
pub enum BroadcastType {
28+
pub enum TransactionType {
2929
/// A funding transaction establishing a new channel.
3030
Funding {
3131
/// The IDs of the channels being funded.
@@ -94,9 +94,9 @@ pub trait BroadcasterInterface {
9494
/// Bitcoin transaction packages are defined in BIP 331 and here:
9595
/// <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md>
9696
///
97-
/// Each transaction is paired with a [`BroadcastType`] indicating the class of transaction
97+
/// Each transaction is paired with a [`TransactionType`] indicating the class of transaction
9898
/// being broadcast, which may be useful for logging, filtering, or prioritization.
99-
fn broadcast_transactions(&self, txs: &[(&Transaction, BroadcastType)]);
99+
fn broadcast_transactions(&self, txs: &[(&Transaction, TransactionType)]);
100100
}
101101

102102
/// An enum that represents the priority at which we want a transaction to confirm used for feerate

lightning/src/chain/onchaintx.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use bitcoin::transaction::Transaction;
2424

2525
use crate::chain::chaininterface::ConfirmationTarget;
2626
use crate::chain::chaininterface::{
27-
BroadcastType, BroadcasterInterface, FeeEstimator, LowerBoundedFeeEstimator,
27+
BroadcasterInterface, FeeEstimator, LowerBoundedFeeEstimator, TransactionType,
2828
};
2929
use crate::chain::channelmonitor::ANTI_REORG_DELAY;
3030
use crate::chain::package::{PackageSolvingData, PackageTemplate};
@@ -537,7 +537,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
537537
if tx.is_fully_signed() {
538538
let log_start = if feerate_was_bumped { "Broadcasting RBF-bumped" } else { "Rebroadcasting" };
539539
log_info!(logger, "{} onchain {}", log_start, log_tx!(tx.0));
540-
broadcaster.broadcast_transactions(&[(&tx.0, BroadcastType::Claim { channel_id: self.channel_id })]);
540+
broadcaster.broadcast_transactions(&[(&tx.0, TransactionType::Claim { channel_id: self.channel_id })]);
541541
} else {
542542
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.compute_txid());
543543
}
@@ -884,7 +884,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
884884
OnchainClaim::Tx(tx) => {
885885
if tx.is_fully_signed() {
886886
log_info!(logger, "Broadcasting onchain {}", log_tx!(tx.0));
887-
broadcaster.broadcast_transactions(&[(&tx.0, BroadcastType::Claim { channel_id: self.channel_id })]);
887+
broadcaster.broadcast_transactions(&[(&tx.0, TransactionType::Claim { channel_id: self.channel_id })]);
888888
} else {
889889
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", tx.0.compute_txid());
890890
}
@@ -1105,7 +1105,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
11051105
OnchainClaim::Tx(bump_tx) => {
11061106
if bump_tx.is_fully_signed() {
11071107
log_info!(logger, "Broadcasting RBF-bumped onchain {}", log_tx!(bump_tx.0));
1108-
broadcaster.broadcast_transactions(&[(&bump_tx.0, BroadcastType::Claim { channel_id: self.channel_id })]);
1108+
broadcaster.broadcast_transactions(&[(&bump_tx.0, TransactionType::Claim { channel_id: self.channel_id })]);
11091109
} else {
11101110
log_info!(logger, "Waiting for signature of RBF-bumped unsigned onchain transaction {}",
11111111
bump_tx.0.compute_txid());
@@ -1208,7 +1208,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
12081208
OnchainClaim::Tx(bump_tx) => {
12091209
if bump_tx.is_fully_signed() {
12101210
log_info!(logger, "Broadcasting onchain {}", log_tx!(bump_tx.0));
1211-
broadcaster.broadcast_transactions(&[(&bump_tx.0, BroadcastType::Claim { channel_id: self.channel_id })]);
1211+
broadcaster.broadcast_transactions(&[(&bump_tx.0, TransactionType::Claim { channel_id: self.channel_id })]);
12121212
} else {
12131213
log_info!(logger, "Waiting for signature of unsigned onchain transaction {}", bump_tx.0.compute_txid());
12141214
}

lightning/src/events/bump_transaction/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use core::future::Future;
1818
use core::ops::Deref;
1919

2020
use crate::chain::chaininterface::{
21-
compute_feerate_sat_per_1000_weight, fee_for_weight, BroadcastType, BroadcasterInterface,
21+
compute_feerate_sat_per_1000_weight, fee_for_weight, BroadcasterInterface, TransactionType,
2222
};
2323
use crate::chain::ClaimId;
2424
use crate::io_extras::sink;
@@ -790,7 +790,7 @@ where
790790
package_target_feerate_sat_per_1000_weight);
791791
self.broadcaster.broadcast_transactions(&[(
792792
&commitment_tx,
793-
BroadcastType::Commitment { channel_id },
793+
TransactionType::Commitment { channel_id },
794794
)]);
795795
return Ok(());
796796
}
@@ -959,8 +959,8 @@ where
959959
commitment_tx.compute_txid()
960960
);
961961
self.broadcaster.broadcast_transactions(&[
962-
(&commitment_tx, BroadcastType::Commitment { channel_id }),
963-
(&anchor_tx, BroadcastType::Anchor { channel_id }),
962+
(&commitment_tx, TransactionType::Commitment { channel_id }),
963+
(&anchor_tx, TransactionType::Anchor { channel_id }),
964964
]);
965965
return Ok(());
966966
}
@@ -1196,7 +1196,7 @@ where
11961196
log_info!(self.logger, "Broadcasting {}", log_tx!(htlc_tx));
11971197
self.broadcaster.broadcast_transactions(&[(
11981198
&htlc_tx,
1199-
BroadcastType::HtlcResolution { channel_id },
1199+
TransactionType::HtlcResolution { channel_id },
12001200
)]);
12011201
}
12021202

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ use crate::blinded_path::payment::{AsyncBolt12OfferContext, Bolt12OfferContext,
3939
use crate::blinded_path::NodeIdLookUp;
4040
use crate::chain;
4141
use crate::chain::chaininterface::{
42-
BroadcastType, BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
42+
BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
43+
TransactionType,
4344
};
4445
use crate::chain::channelmonitor::{
4546
Balance, ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, MonitorEvent,
@@ -6550,7 +6551,7 @@ where
65506551
);
65516552
self.tx_broadcaster.broadcast_transactions(&[(
65526553
funding_tx,
6553-
BroadcastType::Funding { channel_ids: vec![channel.context().channel_id()] },
6554+
TransactionType::Funding { channel_ids: vec![channel.context().channel_id()] },
65546555
)]);
65556556
{
65566557
let mut pending_events = self.pending_events.lock().unwrap();
@@ -9488,7 +9489,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
94889489
log_info!(self.logger, "Broadcasting batch funding tx {}", tx.compute_txid());
94899490
self.tx_broadcaster.broadcast_transactions(&[(
94909491
&tx,
9491-
BroadcastType::Funding { channel_ids: batch_channel_ids },
9492+
TransactionType::Funding { channel_ids: batch_channel_ids },
94929493
)]);
94939494
}
94949495
}
@@ -10157,7 +10158,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1015710158
log_info!(logger, "Broadcasting funding transaction with txid {}", tx.compute_txid());
1015810159
self.tx_broadcaster.broadcast_transactions(&[(
1015910160
&tx,
10160-
BroadcastType::Funding { channel_ids: vec![channel.context.channel_id()] },
10161+
TransactionType::Funding { channel_ids: vec![channel.context.channel_id()] },
1016110162
)]);
1016210163
}
1016310164
}
@@ -11621,7 +11622,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1162111622
log_info!(logger, "Broadcasting {}", log_tx!(broadcast_tx));
1162211623
self.tx_broadcaster.broadcast_transactions(&[(
1162311624
&broadcast_tx,
11624-
BroadcastType::CooperativeClose { channel_id: msg.channel_id },
11625+
TransactionType::CooperativeClose { channel_id: msg.channel_id },
1162511626
)]);
1162611627
let _ = self.handle_error(err, *counterparty_node_id);
1162711628
}
@@ -12951,7 +12952,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1295112952
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
1295212953
self.tx_broadcaster.broadcast_transactions(&[(
1295312954
&broadcast_tx,
12954-
BroadcastType::CooperativeClose { channel_id },
12955+
TransactionType::CooperativeClose { channel_id },
1295512956
)]);
1295612957
}
1295712958
} else {
@@ -13082,7 +13083,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1308213083
log_info!(logger, "Broadcasting {}", log_tx!(tx));
1308313084
self.tx_broadcaster.broadcast_transactions(&[(
1308413085
&tx,
13085-
BroadcastType::CooperativeClose { channel_id },
13086+
TransactionType::CooperativeClose { channel_id },
1308613087
)]);
1308713088
false
1308813089
} else {

lightning/src/util/sweep.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! sweeping them.
1010
1111
use crate::chain::chaininterface::{
12-
BroadcastType, BroadcasterInterface, ConfirmationTarget, FeeEstimator,
12+
BroadcasterInterface, ConfirmationTarget, FeeEstimator, TransactionType,
1313
};
1414
use crate::chain::channelmonitor::{ANTI_REORG_DELAY, ARCHIVAL_DELAY_BLOCKS};
1515
use crate::chain::{self, BestBlock, Confirm, Filter, Listen, WatchedOutput};
@@ -597,7 +597,7 @@ where
597597
// Persistence completely successfully. If we have a spending transaction, we broadcast it.
598598
if let Some((spending_tx, channel_ids)) = spending_tx_and_chan_id {
599599
self.broadcaster
600-
.broadcast_transactions(&[(&spending_tx, BroadcastType::Sweep { channel_ids })]);
600+
.broadcast_transactions(&[(&spending_tx, TransactionType::Sweep { channel_ids })]);
601601
}
602602

603603
Ok(())

lightning/src/util/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::chain;
1414
use crate::chain::chaininterface;
1515
#[cfg(any(test, feature = "_externalize_tests"))]
1616
use crate::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;
17-
use crate::chain::chaininterface::{BroadcastType, ConfirmationTarget};
17+
use crate::chain::chaininterface::{ConfirmationTarget, TransactionType};
1818
use crate::chain::chainmonitor::{ChainMonitor, Persist};
1919
use crate::chain::channelmonitor::{
2020
ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, MonitorEvent,
@@ -1154,7 +1154,7 @@ impl TestBroadcaster {
11541154
}
11551155

11561156
impl chaininterface::BroadcasterInterface for TestBroadcaster {
1157-
fn broadcast_transactions(&self, txs: &[(&Transaction, BroadcastType)]) {
1157+
fn broadcast_transactions(&self, txs: &[(&Transaction, TransactionType)]) {
11581158
// Assert that any batch of transactions of length greater than 1 is sorted
11591159
// topologically, and is a `child-with-parents` package as defined in
11601160
// <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md>.

0 commit comments

Comments
 (0)