@@ -1867,23 +1867,35 @@ fn test_yield_anchors_events() {
1867
1867
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( anchors_config) , Some ( anchors_config) ] ) ;
1868
1868
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1869
1869
1870
- let chan_id = create_announced_chan_between_nodes_with_value (
1870
+ let ( _ , _ , chan_id, funding_tx ) = create_announced_chan_between_nodes_with_value (
1871
1871
& nodes, 0 , 1 , 1_000_000 , 500_000_000
1872
- ) . 2 ;
1873
- route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
1874
- let ( payment_preimage , payment_hash , ..) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 1_000_000 ) ;
1872
+ ) ;
1873
+ let ( payment_preimage_1 , payment_hash_1 , .. ) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) ;
1874
+ let ( payment_preimage_2 , payment_hash_2 , ..) = route_payment ( & nodes[ 1 ] , & [ & nodes[ 0 ] ] , 2_000_000 ) ;
1875
1875
1876
1876
assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
1877
+ assert ! ( nodes[ 1 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
1877
1878
1878
1879
* nodes[ 0 ] . fee_estimator . sat_per_kw . lock ( ) . unwrap ( ) *= 2 ;
1880
+
1879
1881
connect_blocks ( & nodes[ 0 ] , TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1 ) ;
1880
- check_closed_broadcast ! ( & nodes[ 0 ] , true ) ;
1881
- assert ! ( nodes[ 0 ] . tx_broadcaster. txn_broadcasted. lock( ) . unwrap( ) . is_empty( ) ) ;
1882
+ assert ! ( nodes[ 0 ] . tx_broadcaster. txn_broadcast( ) . is_empty( ) ) ;
1883
+
1884
+ connect_blocks ( & nodes[ 1 ] , TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1 ) ;
1885
+ {
1886
+ let txn = nodes[ 1 ] . tx_broadcaster . txn_broadcast ( ) ;
1887
+ assert_eq ! ( txn. len( ) , 1 ) ;
1888
+ check_spends ! ( txn[ 0 ] , funding_tx) ;
1889
+ }
1882
1890
1883
1891
get_monitor ! ( nodes[ 0 ] , chan_id) . provide_payment_preimage (
1884
- & payment_hash , & payment_preimage , & node_cfgs[ 0 ] . tx_broadcaster ,
1892
+ & payment_hash_2 , & payment_preimage_2 , & node_cfgs[ 0 ] . tx_broadcaster ,
1885
1893
& LowerBoundedFeeEstimator :: new ( node_cfgs[ 0 ] . fee_estimator ) , & nodes[ 0 ] . logger
1886
1894
) ;
1895
+ get_monitor ! ( nodes[ 1 ] , chan_id) . provide_payment_preimage (
1896
+ & payment_hash_1, & payment_preimage_1, & node_cfgs[ 0 ] . tx_broadcaster ,
1897
+ & LowerBoundedFeeEstimator :: new ( node_cfgs[ 1 ] . fee_estimator ) , & nodes[ 1 ] . logger
1898
+ ) ;
1887
1899
1888
1900
let mut holder_events = nodes[ 0 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
1889
1901
assert_eq ! ( holder_events. len( ) , 1 ) ;
@@ -1904,27 +1916,50 @@ fn test_yield_anchors_events() {
1904
1916
assert_eq ! ( txn. len( ) , 2 ) ;
1905
1917
let anchor_tx = txn. pop ( ) . unwrap ( ) ;
1906
1918
let commitment_tx = txn. pop ( ) . unwrap ( ) ;
1919
+ check_spends ! ( commitment_tx, funding_tx) ;
1907
1920
check_spends ! ( anchor_tx, coinbase_tx, commitment_tx) ;
1908
1921
( commitment_tx, anchor_tx)
1909
1922
} ,
1910
1923
_ => panic ! ( "Unexpected event" ) ,
1911
1924
} ;
1912
1925
1926
+ assert_eq ! ( commitment_tx. output[ 2 ] . value, 1_000 ) ; // HTLC A -> B
1927
+ assert_eq ! ( commitment_tx. output[ 3 ] . value, 2_000 ) ; // HTLC B -> A
1928
+
1913
1929
mine_transactions ( & nodes[ 0 ] , & [ & commitment_tx, & anchor_tx] ) ;
1914
1930
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1931
+ mine_transactions ( & nodes[ 1 ] , & [ & commitment_tx, & anchor_tx] ) ;
1932
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
1933
+
1934
+ {
1935
+ let mut txn = nodes[ 1 ] . tx_broadcaster . unique_txn_broadcast ( ) ;
1936
+ assert_eq ! ( txn. len( ) , if nodes[ 1 ] . connect_style. borrow( ) . updates_best_block_first( ) { 3 } else { 2 } ) ;
1937
+
1938
+ let htlc_preimage_tx = txn. pop ( ) . unwrap ( ) ;
1939
+ assert_eq ! ( htlc_preimage_tx. input. len( ) , 1 ) ;
1940
+ assert_eq ! ( htlc_preimage_tx. input[ 0 ] . previous_output. vout, 3 ) ;
1941
+ check_spends ! ( htlc_preimage_tx, commitment_tx) ;
1942
+
1943
+ let htlc_timeout_tx = txn. pop ( ) . unwrap ( ) ;
1944
+ assert_eq ! ( htlc_timeout_tx. input. len( ) , 1 ) ;
1945
+ assert_eq ! ( htlc_timeout_tx. input[ 0 ] . previous_output. vout, 2 ) ;
1946
+ check_spends ! ( htlc_timeout_tx, commitment_tx) ;
1947
+
1948
+ if let Some ( commitment_tx) = txn. pop ( ) {
1949
+ check_spends ! ( commitment_tx, funding_tx) ;
1950
+ }
1951
+ }
1915
1952
1916
1953
let mut holder_events = nodes[ 0 ] . chain_monitor . chain_monitor . get_and_clear_pending_events ( ) ;
1917
1954
// Certain block `ConnectStyle`s cause an extra `ChannelClose` event to be emitted since the
1918
1955
// best block is updated before the confirmed transactions are notified.
1919
- match * nodes[ 0 ] . connect_style . borrow ( ) {
1920
- ConnectStyle :: BestBlockFirst |ConnectStyle :: BestBlockFirstReorgsOnlyTip |ConnectStyle :: BestBlockFirstSkippingBlocks => {
1921
- assert_eq ! ( holder_events. len( ) , 3 ) ;
1922
- if let Event :: BumpTransaction ( BumpTransactionEvent :: ChannelClose { .. } ) = holder_events. remove ( 0 ) { }
1923
- else { panic ! ( "unexpected event" ) ; }
1924
-
1925
- } ,
1926
- _ => assert_eq ! ( holder_events. len( ) , 2 ) ,
1927
- } ;
1956
+ if nodes[ 0 ] . connect_style . borrow ( ) . updates_best_block_first ( ) {
1957
+ assert_eq ! ( holder_events. len( ) , 3 ) ;
1958
+ if let Event :: BumpTransaction ( BumpTransactionEvent :: ChannelClose { .. } ) = holder_events. remove ( 0 ) { }
1959
+ else { panic ! ( "unexpected event" ) ; }
1960
+ } else {
1961
+ assert_eq ! ( holder_events. len( ) , 2 ) ;
1962
+ }
1928
1963
let mut htlc_txs = Vec :: with_capacity ( 2 ) ;
1929
1964
for event in holder_events {
1930
1965
match event {
@@ -1958,6 +1993,9 @@ fn test_yield_anchors_events() {
1958
1993
1959
1994
// Clear the remaining events as they're not relevant to what we're testing.
1960
1995
nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
1996
+ nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
1997
+ nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1998
+ nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
1961
1999
}
1962
2000
1963
2001
#[ test]
0 commit comments