|
9 | 9 |
|
10 | 10 | #![cfg_attr(not(test), allow(unused_imports))] |
11 | 11 |
|
12 | | -use crate::chain::chaininterface::{TransactionType, FEERATE_FLOOR_SATS_PER_KW}; |
| 12 | +use crate::chain::chaininterface::{FundingPurpose, TransactionType, FEERATE_FLOOR_SATS_PER_KW}; |
13 | 13 | use crate::chain::channelmonitor::{ANTI_REORG_DELAY, LATENCY_GRACE_PERIOD_BLOCKS}; |
14 | 14 | use crate::chain::transaction::OutPoint; |
15 | 15 | use crate::chain::ChannelMonitorUpdateStatus; |
@@ -503,9 +503,9 @@ pub fn sign_interactive_funding_tx<'a, 'b, 'c, 'd>( |
503 | 503 | ) |
504 | 504 | } |
505 | 505 |
|
506 | | -/// `expected_replaced_txid` is the expected value of `TransactionType::Splice.replaced_txid` on |
507 | | -/// the resulting broadcast: `None` for a first splice attempt; `Some(txid)` for an RBF replacing |
508 | | -/// that prior negotiated candidate. |
| 506 | +/// `expected_replaced_txid` is the expected txid of the prior negotiated candidate in the |
| 507 | +/// `TransactionType::InteractiveFunding` broadcast: `None` for a first splice attempt; `Some(txid)` |
| 508 | +/// for an RBF replacing that prior negotiated candidate. |
509 | 509 | pub fn sign_interactive_funding_tx_with_acceptor_contribution<'a, 'b, 'c, 'd>( |
510 | 510 | initiator: &'a Node<'b, 'c, 'd>, acceptor: &'a Node<'b, 'c, 'd>, is_0conf: bool, |
511 | 511 | acceptor_has_contribution: bool, expected_replaced_txid: Option<Txid>, |
@@ -608,28 +608,29 @@ pub fn sign_interactive_funding_tx_with_acceptor_contribution<'a, 'b, 'c, 'd>( |
608 | 608 | assert_eq!(initiator_txn[0].0, acceptor_txn[0].0); |
609 | 609 | let (tx, initiator_tx_type) = initiator_txn.remove(0); |
610 | 610 | let (_, acceptor_tx_type) = acceptor_txn.remove(0); |
611 | | - // Verify transaction types are Splice for both nodes. The initiator always contributes; |
612 | | - // the acceptor contributes iff the flag says so. Both parties must observe the same |
613 | | - // `replaced_txid` as the caller declares. |
614 | | - if let TransactionType::Splice { contribution, replaced_txid, .. } = &initiator_tx_type { |
615 | | - assert!( |
616 | | - contribution.is_some(), |
617 | | - "Initiator always contributes; expected Some, got None" |
618 | | - ); |
619 | | - assert_eq!(*replaced_txid, expected_replaced_txid, "initiator replaced_txid mismatch"); |
620 | | - } else { |
621 | | - panic!("Expected TransactionType::Splice, got {:?}", initiator_tx_type); |
622 | | - } |
623 | | - if let TransactionType::Splice { contribution, replaced_txid, .. } = &acceptor_tx_type { |
624 | | - assert_eq!( |
625 | | - contribution.is_some(), |
626 | | - acceptor_has_contribution, |
627 | | - "Acceptor contribution presence must match `acceptor_has_contribution`", |
628 | | - ); |
629 | | - assert_eq!(*replaced_txid, expected_replaced_txid, "acceptor replaced_txid mismatch"); |
630 | | - } else { |
631 | | - panic!("Expected TransactionType::Splice, got {:?}", acceptor_tx_type); |
632 | | - } |
| 611 | + // Verify transaction types are InteractiveFunding for both nodes. The initiator always |
| 612 | + // contributes; the acceptor contributes iff the flag says so. Both parties must observe |
| 613 | + // the same prior candidate txid as the caller declares. |
| 614 | + let assert_broadcast = |
| 615 | + |label: &str, tx_type: &TransactionType, contribution_expected: bool| { |
| 616 | + let candidates = match tx_type { |
| 617 | + TransactionType::InteractiveFunding(candidates) => candidates, |
| 618 | + other => panic!("Expected TransactionType::InteractiveFunding, got {other:?}"), |
| 619 | + }; |
| 620 | + let last = candidates.last().expect("at least one candidate"); |
| 621 | + assert_eq!(last.txid, tx.compute_txid(), "{label} last candidate txid mismatch"); |
| 622 | + let last_channel = last.channels.first().expect("at least one channel"); |
| 623 | + assert!(matches!(last_channel.purpose, FundingPurpose::Splice)); |
| 624 | + assert_eq!( |
| 625 | + last_channel.contribution.is_some(), |
| 626 | + contribution_expected, |
| 627 | + "{label} contribution presence mismatch", |
| 628 | + ); |
| 629 | + let prior_txid = candidates.len().checked_sub(2).map(|i| candidates[i].txid); |
| 630 | + assert_eq!(prior_txid, expected_replaced_txid, "{label} replaced_txid mismatch"); |
| 631 | + }; |
| 632 | + assert_broadcast("initiator", &initiator_tx_type, true); |
| 633 | + assert_broadcast("acceptor", &acceptor_tx_type, acceptor_has_contribution); |
633 | 634 | tx |
634 | 635 | }; |
635 | 636 | (tx, splice_locked) |
@@ -4370,8 +4371,8 @@ fn test_splice_rbf_acceptor_basic() { |
4370 | 4371 | new_funding_script.clone(), |
4371 | 4372 | ); |
4372 | 4373 |
|
4373 | | - // Step 10: Sign and broadcast. The broadcast's `TransactionType::Splice.replaced_txid` must |
4374 | | - // point at the first splice tx it is replacing. |
| 4374 | + // Step 10: Sign and broadcast. The prior candidate in the broadcast's |
| 4375 | + // `TransactionType::InteractiveFunding` must point at the first splice tx it is replacing. |
4375 | 4376 | let (rbf_tx, splice_locked) = sign_interactive_funding_tx( |
4376 | 4377 | &nodes[0], |
4377 | 4378 | &nodes[1], |
|
0 commit comments