@@ -17,7 +17,7 @@ use crate::chain::channelmonitor::{ANTI_REORG_DELAY, Balance};
17
17
use crate :: chain:: transaction:: OutPoint ;
18
18
use crate :: chain:: chaininterface:: LowerBoundedFeeEstimator ;
19
19
#[ cfg( anchors) ]
20
- use crate :: events:: bump_transaction:: BumpTransactionEvent ;
20
+ use crate :: events:: bump_transaction:: { BumpTransactionEvent , BumpTransactionEventHandler , Wallet , WalletSource } ;
21
21
use crate :: events:: { Event , MessageSendEvent , MessageSendEventsProvider , ClosureReason , HTLCDestination } ;
22
22
use crate :: ln:: channel;
23
23
#[ cfg( anchors) ]
@@ -1938,7 +1938,6 @@ fn test_yield_anchors_events() {
1938
1938
// allowing the consumer to provide additional fees to the commitment transaction to be
1939
1939
// broadcast. Once the commitment transaction confirms, events for the HTLC resolution should be
1940
1940
// emitted by LDK, such that the consumer can attach fees to the zero fee HTLC transactions.
1941
- let secp = Secp256k1 :: new ( ) ;
1942
1941
let mut chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1943
1942
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1944
1943
let mut anchors_config = UserConfig :: default ( ) ;
@@ -1955,6 +1954,8 @@ fn test_yield_anchors_events() {
1955
1954
1956
1955
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
1957
1956
1957
+ * nodes[ 0 ] . fee_estimator . sat_per_kw . lock ( ) . unwrap ( ) *= 2 ;
1958
+
1958
1959
connect_blocks ( & nodes[ 0 ] , TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1 ) ;
1959
1960
check_closed_broadcast ! ( & nodes[ 0 ] , true ) ;
1960
1961
assert ! ( nodes[ 0 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . is_empty( ) ) ;
@@ -1964,34 +1965,38 @@ fn test_yield_anchors_events() {
1964
1965
& LowerBoundedFeeEstimator :: new ( node_cfgs[ 0 ] . fee_estimator ) , & nodes[ 0 ] . logger
1965
1966
) ;
1966
1967
1968
+ let coinbase_tx = Transaction {
1969
+ version : 2 ,
1970
+ lock_time : PackedLockTime :: ZERO ,
1971
+ input : vec ! [ TxIn { ..Default :: default ( ) } ] ,
1972
+ output : vec ! [ TxOut { // UTXO to attach fees to `anchor_tx` and `htlc_txs`
1973
+ value: Amount :: ONE_BTC . to_sat( ) ,
1974
+ script_pubkey: nodes[ 0 ] . wallet_utxo_source. change_script( ) . unwrap( ) ,
1975
+ } ] ,
1976
+ } ;
1977
+ nodes[ 0 ] . wallet_utxo_source . add_utxo (
1978
+ bitcoin:: OutPoint { txid : coinbase_tx. txid ( ) , vout : 0 } , coinbase_tx. output [ 0 ] . value ,
1979
+ ) ;
1980
+ nodes[ 0 ] . wallet_utxo_source . add_utxo (
1981
+ bitcoin:: OutPoint { txid : coinbase_tx. txid ( ) , vout : 1 } , coinbase_tx. output [ 0 ] . value * 2 ,
1982
+ ) ;
1983
+ let wallet = Wallet :: new ( & nodes[ 0 ] . wallet_utxo_source ) ;
1984
+ let bump_event_handler = BumpTransactionEventHandler :: new (
1985
+ nodes[ 0 ] . tx_broadcaster , & wallet, nodes[ 0 ] . keys_manager , nodes[ 0 ] . logger ,
1986
+ ) ;
1987
+
1967
1988
let mut holder_events = nodes[ 0 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
1968
1989
assert_eq ! ( holder_events. len( ) , 1 ) ;
1969
- let ( commitment_tx, anchor_tx) = match holder_events. pop ( ) . unwrap ( ) {
1970
- Event :: BumpTransaction ( BumpTransactionEvent :: ChannelClose { commitment_tx, anchor_descriptor, .. } ) => {
1971
- assert_eq ! ( commitment_tx. input. len( ) , 1 ) ;
1972
- assert_eq ! ( commitment_tx. output. len( ) , 6 ) ;
1973
- let mut anchor_tx = Transaction {
1974
- version : 2 ,
1975
- lock_time : PackedLockTime :: ZERO ,
1976
- input : vec ! [
1977
- TxIn { previous_output: anchor_descriptor. outpoint, ..Default :: default ( ) } ,
1978
- TxIn { ..Default :: default ( ) } ,
1979
- ] ,
1980
- output : vec ! [ TxOut {
1981
- value: Amount :: ONE_BTC . to_sat( ) ,
1982
- script_pubkey: Script :: new_op_return( & [ ] ) ,
1983
- } ] ,
1984
- } ;
1985
- let signer = nodes[ 0 ] . keys_manager . derive_channel_keys (
1986
- anchor_descriptor. channel_value_satoshis , & anchor_descriptor. channel_keys_id ,
1987
- ) ;
1988
- let funding_sig = signer. sign_holder_anchor_input ( & mut anchor_tx, 0 , & secp) . unwrap ( ) ;
1989
- anchor_tx. input [ 0 ] . witness = chan_utils:: build_anchor_input_witness (
1990
- & signer. pubkeys ( ) . funding_pubkey , & funding_sig
1991
- ) ;
1992
- ( commitment_tx, anchor_tx)
1993
- } ,
1994
- _ => panic ! ( "Unexpected event" ) ,
1990
+ let ( commitment_tx, anchor_tx) = {
1991
+ bump_event_handler. handle_event ( holder_events. pop ( ) . unwrap ( ) ) ;
1992
+ let mut txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
1993
+ assert_eq ! ( txn. len( ) , 2 ) ;
1994
+ let anchor_tx = txn. pop ( ) . unwrap ( ) ;
1995
+ let commitment_tx = txn. pop ( ) . unwrap ( ) ;
1996
+ assert_eq ! ( commitment_tx. input. len( ) , 1 ) ;
1997
+ assert_eq ! ( commitment_tx. output. len( ) , 6 ) ;
1998
+ check_spends ! ( anchor_tx, commitment_tx, coinbase_tx) ;
1999
+ ( commitment_tx, anchor_tx)
1995
2000
} ;
1996
2001
1997
2002
mine_transactions ( & nodes[ 0 ] , & [ & commitment_tx, & anchor_tx] ) ;
@@ -2011,36 +2016,12 @@ fn test_yield_anchors_events() {
2011
2016
} ;
2012
2017
let mut htlc_txs = Vec :: with_capacity ( 2 ) ;
2013
2018
for event in holder_events {
2014
- match event {
2015
- Event :: BumpTransaction ( BumpTransactionEvent :: HTLCResolution { htlc_descriptors, tx_lock_time, .. } ) => {
2016
- assert_eq ! ( htlc_descriptors. len( ) , 1 ) ;
2017
- let htlc_descriptor = & htlc_descriptors[ 0 ] ;
2018
- let signer = nodes[ 0 ] . keys_manager . derive_channel_keys (
2019
- htlc_descriptor. channel_value_satoshis , & htlc_descriptor. channel_keys_id
2020
- ) ;
2021
- let per_commitment_point = signer. get_per_commitment_point ( htlc_descriptor. per_commitment_number , & secp) ;
2022
- let mut htlc_tx = Transaction {
2023
- version : 2 ,
2024
- lock_time : tx_lock_time,
2025
- input : vec ! [
2026
- htlc_descriptor. unsigned_tx_input( ) , // HTLC input
2027
- TxIn { ..Default :: default ( ) } // Fee input
2028
- ] ,
2029
- output : vec ! [
2030
- htlc_descriptor. tx_output( & per_commitment_point, & secp) , // HTLC output
2031
- TxOut { // Fee input change
2032
- value: Amount :: ONE_BTC . to_sat( ) ,
2033
- script_pubkey: Script :: new_op_return( & [ ] ) ,
2034
- }
2035
- ]
2036
- } ;
2037
- let our_sig = signer. sign_holder_htlc_transaction ( & mut htlc_tx, 0 , htlc_descriptor, & secp) . unwrap ( ) ;
2038
- let witness_script = htlc_descriptor. witness_script ( & per_commitment_point, & secp) ;
2039
- htlc_tx. input [ 0 ] . witness = htlc_descriptor. tx_input_witness ( & our_sig, & witness_script) ;
2040
- htlc_txs. push ( htlc_tx) ;
2041
- } ,
2042
- _ => panic ! ( "Unexpected event" ) ,
2043
- }
2019
+ // Ideally we'd use the change UTXO from `anchor_tx` here to not reuse the same UTXO but it
2020
+ // doesn't really matter since we're not validating against an actual chain backend anyway.
2021
+ bump_event_handler. handle_event ( event) ;
2022
+ let mut txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
2023
+ assert_eq ! ( txn. len( ) , 1 ) ;
2024
+ htlc_txs. push ( txn. pop ( ) . unwrap ( ) ) ;
2044
2025
}
2045
2026
2046
2027
mine_transactions ( & nodes[ 0 ] , & [ & htlc_txs[ 0 ] , & htlc_txs[ 1 ] ] ) ;
0 commit comments