Skip to content

Commit fdc8731

Browse files
authored
Merge pull request #4173 from tankyleo/25-10-broadcaster-docs
Assure BroadcasterInterface packages of len > 1 are child-with-parents
2 parents e457a48 + 7c9b21f commit fdc8731

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

lightning/src/chain/chaininterface.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ pub trait BroadcasterInterface {
3636
/// In some cases LDK may attempt to broadcast a transaction which double-spends another
3737
/// and this isn't a bug and can be safely ignored.
3838
///
39-
/// If more than one transaction is given, these transactions should be considered to be a
40-
/// package and broadcast together. Some of the transactions may or may not depend on each other,
41-
/// be sure to manage both cases correctly.
39+
/// If more than one transaction is given, these transactions MUST be a
40+
/// single child and its parents and be broadcast together as a package
41+
/// (see the [`submitpackage`](https://bitcoincore.org/en/doc/30.0.0/rpc/rawtransactions/submitpackage)
42+
/// Bitcoin Core RPC).
43+
///
44+
/// Implementations MUST NOT assume any topological order on the transactions.
4245
///
4346
/// Bitcoin transaction packages are defined in BIP 331 and here:
4447
/// <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md>

lightning/src/events/bump_transaction/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ mod tests {
11351135
let commitment_tx_bytes = Vec::<u8>::from_hex("02000000000101cc6b0a9dd84b52c07340fff6fab002fc37b4bdccfdce9f39c5ec8391a56b652907000000009b948b80044a01000000000000220020b4182433fdfdfbf894897c98f84d92cec815cee222755ffd000ae091c9dadc2d4a01000000000000220020f83f7dbf90e2de325b5bb6bab0ae370151278c6964739242b2e7ce0cb68a5d81cb4a02000000000022002024add256b3dccee772610caef82a601045ab6f98fd6d5df608cc756b891ccfe63ffa490000000000220020894bf32b37906a643625e87131897c3714c71b3ac9b161862c9aa6c8d468b4c70400473044022060abd347bff2cca0212b660e6addff792b3356bd4a1b5b26672dc2e694c3c5f002202b40b7e346b494a7b1d048b4ec33ba99c90a09ab48eb1df64ccdc768066c865c014730440220554d8361e04dc0ee178dcb23d2d23f53ec7a1ae4312a5be76bd9e83ab8981f3d0220501f23ffb18cb81ccea72d30252f88d5e69fd28ba4992803d03c00d06fa8899e0147522102817f6ce189ab7114f89e8d5df58cdbbaf272dc8e71b92982d47456a0b6a0ceee2102c9b4d2f24aca54f65e13f4c83e2a8d8e877e12d3c71a76e81f28a5cabc652aa352ae626c7620").unwrap();
11361136
let commitment_tx: Transaction =
11371137
Readable::read(&mut Cursor::new(&commitment_tx_bytes)).unwrap();
1138+
let commitment_txid = commitment_tx.compute_txid();
11381139
let total_commitment_weight =
11391140
commitment_tx.weight().to_wu() + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT;
11401141
let commitment_and_anchor_fee = 930 + 330;
@@ -1191,7 +1192,7 @@ mod tests {
11911192
keys_id: [42; 32],
11921193
transaction_parameters,
11931194
},
1194-
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
1195+
outpoint: OutPoint { txid: commitment_txid, vout: 0 },
11951196
value: Amount::from_sat(ANCHOR_OUTPUT_VALUE_SATOSHI),
11961197
},
11971198
pending_htlcs: Vec::new(),

lightning/src/util/test_utils.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,30 @@ impl TestBroadcaster {
11231123

11241124
impl chaininterface::BroadcasterInterface for TestBroadcaster {
11251125
fn broadcast_transactions(&self, txs: &[&Transaction]) {
1126+
// Assert that any batch of transactions of length greater than 1 is sorted
1127+
// topologically, and is a `child-with-parents` package as defined in
1128+
// <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md>.
1129+
//
1130+
// Implementations MUST NOT rely on this, and must re-sort the transactions
1131+
// themselves.
1132+
//
1133+
// Right now LDK only ever broadcasts packages of length 2.
1134+
assert!(txs.len() <= 2);
1135+
if txs.len() == 2 {
1136+
let parent_txid = txs[0].compute_txid();
1137+
assert!(txs[1]
1138+
.input
1139+
.iter()
1140+
.map(|input| input.previous_output.txid)
1141+
.any(|txid| txid == parent_txid));
1142+
let child_txid = txs[1].compute_txid();
1143+
assert!(txs[0]
1144+
.input
1145+
.iter()
1146+
.map(|input| input.previous_output.txid)
1147+
.all(|txid| txid != child_txid));
1148+
}
1149+
11261150
for tx in txs {
11271151
let lock_time = tx.lock_time.to_consensus_u32();
11281152
assert!(lock_time < 1_500_000_000);

0 commit comments

Comments
 (0)