@@ -393,11 +393,6 @@ pub(crate) const ANTI_REORG_DELAY: u32 = 6;
393
393
394
394
struct OnchainDetection < ChanSigner : ChannelKeys > {
395
395
keys : ChanSigner ,
396
- funding_key : SecretKey ,
397
- revocation_base_key : SecretKey ,
398
- htlc_base_key : SecretKey ,
399
- delayed_payment_base_key : SecretKey ,
400
- payment_base_key : SecretKey ,
401
396
funding_info : Option < ( OutPoint , Script ) > ,
402
397
current_remote_commitment_txid : Option < Sha256dHash > ,
403
398
prev_remote_commitment_txid : Option < Sha256dHash > ,
@@ -875,11 +870,6 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
875
870
self . shutdown_script . write ( writer) ?;
876
871
877
872
self . onchain_detection . keys . write ( writer) ?;
878
- writer. write_all ( & self . onchain_detection . funding_key [ ..] ) ?;
879
- writer. write_all ( & self . onchain_detection . revocation_base_key [ ..] ) ?;
880
- writer. write_all ( & self . onchain_detection . htlc_base_key [ ..] ) ?;
881
- writer. write_all ( & self . onchain_detection . delayed_payment_base_key [ ..] ) ?;
882
- writer. write_all ( & self . onchain_detection . payment_base_key [ ..] ) ?;
883
873
match self . onchain_detection . funding_info {
884
874
Some ( ( ref outpoint, ref script) ) => {
885
875
writer. write_all ( & outpoint. txid [ ..] ) ?;
@@ -1086,21 +1076,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1086
1076
logger : Arc < Logger > ) -> ChannelMonitor < ChanSigner > {
1087
1077
1088
1078
assert ! ( commitment_transaction_number_obscure_factor <= ( 1 << 48 ) ) ;
1089
- let funding_key = keys. funding_key ( ) . clone ( ) ;
1090
- let revocation_base_key = keys. revocation_base_key ( ) . clone ( ) ;
1091
- let htlc_base_key = keys. htlc_base_key ( ) . clone ( ) ;
1092
- let delayed_payment_base_key = keys. delayed_payment_base_key ( ) . clone ( ) ;
1093
- let payment_base_key = keys. payment_base_key ( ) . clone ( ) ;
1094
1079
let our_channel_close_key_hash = Hash160 :: hash ( & shutdown_pubkey. serialize ( ) ) ;
1095
1080
let shutdown_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & our_channel_close_key_hash[ ..] ) . into_script ( ) ;
1096
1081
1097
1082
let onchain_detection = OnchainDetection {
1098
1083
keys : keys. clone ( ) ,
1099
- funding_key,
1100
- revocation_base_key,
1101
- htlc_base_key,
1102
- delayed_payment_base_key,
1103
- payment_base_key,
1104
1084
funding_info : Some ( funding_info. clone ( ) ) ,
1105
1085
current_remote_commitment_txid : None ,
1106
1086
prev_remote_commitment_txid : None ,
@@ -1246,7 +1226,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1246
1226
let to_remote_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 )
1247
1227
. push_slice ( & Hash160 :: hash ( & payment_key. serialize ( ) ) [ ..] )
1248
1228
. into_script ( ) ;
1249
- if let Ok ( to_remote_key) = chan_utils:: derive_private_key ( & self . secp_ctx , & their_revocation_point, & self . onchain_detection . payment_base_key ) {
1229
+ if let Ok ( to_remote_key) = chan_utils:: derive_private_key ( & self . secp_ctx , & their_revocation_point, & self . onchain_detection . keys . payment_base_key ( ) ) {
1250
1230
self . broadcasted_remote_payment_script = Some ( ( to_remote_script, to_remote_key) ) ;
1251
1231
}
1252
1232
}
@@ -1449,9 +1429,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1449
1429
let per_commitment_key = ignore_error ! ( SecretKey :: from_slice( & secret) ) ;
1450
1430
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1451
1431
let revocation_pubkey = ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, & per_commitment_point, & self . onchain_detection. keys. pubkeys( ) . revocation_basepoint) ) ;
1452
- let revocation_key = ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & self . onchain_detection. revocation_base_key) ) ;
1432
+ let revocation_key = ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & self . onchain_detection. keys . revocation_base_key( ) ) ) ;
1453
1433
let b_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & self . onchain_detection. keys. pubkeys( ) . htlc_basepoint) ) ;
1454
- let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, & per_commitment_point, & self . onchain_detection. payment_base_key) ) ;
1434
+ let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, & per_commitment_point, & self . onchain_detection. keys . payment_base_key( ) ) ) ;
1455
1435
let delayed_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & self . their_delayed_payment_base_key. unwrap( ) ) ) ;
1456
1436
let a_htlc_key = match self . their_htlc_base_key {
1457
1437
None => return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ,
@@ -1606,12 +1586,12 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1606
1586
if let Some ( revocation_point) = revocation_point_option {
1607
1587
let revocation_pubkey = ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, revocation_point, & self . onchain_detection. keys. pubkeys( ) . revocation_basepoint) ) ;
1608
1588
let b_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & self . onchain_detection. keys. pubkeys( ) . htlc_basepoint) ) ;
1609
- let htlc_privkey = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . onchain_detection. htlc_base_key) ) ;
1589
+ let htlc_privkey = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . onchain_detection. keys . htlc_base_key( ) ) ) ;
1610
1590
let a_htlc_key = match self . their_htlc_base_key {
1611
1591
None => return ( claimable_outpoints, ( commitment_txid, watch_outputs) ) ,
1612
1592
Some ( their_htlc_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & their_htlc_base_key) ) ,
1613
1593
} ;
1614
- let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . onchain_detection. payment_base_key) ) ;
1594
+ let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . onchain_detection. keys . payment_base_key( ) ) ) ;
1615
1595
1616
1596
self . broadcasted_remote_payment_script = {
1617
1597
// Note that the Network here is ignored as we immediately drop the address for the
@@ -1663,7 +1643,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1663
1643
let per_commitment_key = ignore_error ! ( SecretKey :: from_slice( & secret) ) ;
1664
1644
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1665
1645
let revocation_pubkey = ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, & per_commitment_point, & self . onchain_detection. keys. pubkeys( ) . revocation_basepoint) ) ;
1666
- let revocation_key = ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & self . onchain_detection. revocation_base_key) ) ;
1646
+ let revocation_key = ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & self . onchain_detection. keys . revocation_base_key( ) ) ) ;
1667
1647
let delayed_key = match self . their_delayed_payment_base_key {
1668
1648
None => return ( Vec :: new ( ) , None ) ,
1669
1649
Some ( their_delayed_payment_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & their_delayed_payment_base_key) ) ,
@@ -1676,12 +1656,12 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1676
1656
( claimable_outpoints, Some ( ( htlc_txid, tx. output . clone ( ) ) ) )
1677
1657
}
1678
1658
1679
- fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx , delayed_payment_base_key : & SecretKey ) -> ( Vec < Transaction > , Vec < TxOut > , Option < ( Script , SecretKey , Script ) > ) {
1659
+ fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx ) -> ( Vec < Transaction > , Vec < TxOut > , Option < ( Script , SecretKey , Script ) > ) {
1680
1660
let mut res = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1681
1661
let mut watch_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1682
1662
1683
1663
let redeemscript = chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . their_to_self_delay . unwrap ( ) , & local_tx. delayed_payment_key ) ;
1684
- let broadcasted_local_revokable_script = if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , & local_tx. per_commitment_point , delayed_payment_base_key) {
1664
+ let broadcasted_local_revokable_script = if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , & local_tx. per_commitment_point , self . onchain_detection . keys . delayed_payment_base_key ( ) ) {
1685
1665
Some ( ( redeemscript. to_v0_p2wsh ( ) , local_delayedkey, redeemscript) )
1686
1666
} else { None } ;
1687
1667
@@ -1692,7 +1672,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1692
1672
log_trace ! ( self , "Broadcasting HTLC-Timeout transaction against local commitment transactions" ) ;
1693
1673
let mut htlc_timeout_tx = chan_utils:: build_htlc_transaction ( & local_tx. txid , local_tx. feerate_per_kw , self . their_to_self_delay . unwrap ( ) , htlc, & local_tx. delayed_payment_key , & local_tx. revocation_key ) ;
1694
1674
let ( our_sig, htlc_script) = match
1695
- chan_utils:: sign_htlc_transaction ( & mut htlc_timeout_tx, their_sig, & None , htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key , & local_tx. per_commitment_point , & self . onchain_detection . htlc_base_key , & self . secp_ctx ) {
1675
+ chan_utils:: sign_htlc_transaction ( & mut htlc_timeout_tx, their_sig, & None , htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key , & local_tx. per_commitment_point , & self . onchain_detection . keys . htlc_base_key ( ) , & self . secp_ctx ) {
1696
1676
Ok ( res) => res,
1697
1677
Err ( _) => continue ,
1698
1678
} ;
@@ -1707,7 +1687,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1707
1687
log_trace ! ( self , "Broadcasting HTLC-Success transaction against local commitment transactions" ) ;
1708
1688
let mut htlc_success_tx = chan_utils:: build_htlc_transaction ( & local_tx. txid , local_tx. feerate_per_kw , self . their_to_self_delay . unwrap ( ) , htlc, & local_tx. delayed_payment_key , & local_tx. revocation_key ) ;
1709
1689
let ( our_sig, htlc_script) = match
1710
- chan_utils:: sign_htlc_transaction ( & mut htlc_success_tx, their_sig, & Some ( * payment_preimage) , htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key , & local_tx. per_commitment_point , & self . onchain_detection . htlc_base_key , & self . secp_ctx ) {
1690
+ chan_utils:: sign_htlc_transaction ( & mut htlc_success_tx, their_sig, & Some ( * payment_preimage) , htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key , & local_tx. per_commitment_point , & self . onchain_detection . keys . htlc_base_key ( ) , & self . secp_ctx ) {
1711
1691
Ok ( res) => res,
1712
1692
Err ( _) => continue ,
1713
1693
} ;
@@ -1771,29 +1751,29 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1771
1751
1772
1752
if let & mut Some ( ref mut local_tx) = & mut self . current_local_signed_commitment_tx {
1773
1753
if local_tx. txid == commitment_txid {
1774
- local_tx. tx . add_local_sig ( & self . onchain_detection . funding_key , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1754
+ local_tx. tx . add_local_sig ( & self . onchain_detection . keys . funding_key ( ) , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1775
1755
}
1776
1756
}
1777
1757
if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1778
1758
if local_tx. txid == commitment_txid {
1779
1759
is_local_tx = true ;
1780
1760
log_trace ! ( self , "Got latest local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1781
1761
assert ! ( local_tx. tx. has_local_sig( ) ) ;
1782
- let mut res = self . broadcast_by_local_state ( local_tx, & self . onchain_detection . delayed_payment_base_key ) ;
1762
+ let mut res = self . broadcast_by_local_state ( local_tx) ;
1783
1763
append_onchain_update ! ( res) ;
1784
1764
}
1785
1765
}
1786
1766
if let & mut Some ( ref mut local_tx) = & mut self . prev_local_signed_commitment_tx {
1787
1767
if local_tx. txid == commitment_txid {
1788
- local_tx. tx . add_local_sig ( & self . onchain_detection . funding_key , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1768
+ local_tx. tx . add_local_sig ( & self . onchain_detection . keys . funding_key ( ) , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1789
1769
}
1790
1770
}
1791
1771
if let & Some ( ref local_tx) = & self . prev_local_signed_commitment_tx {
1792
1772
if local_tx. txid == commitment_txid {
1793
1773
is_local_tx = true ;
1794
1774
log_trace ! ( self , "Got previous local commitment tx broadcast, searching for available HTLCs to claim" ) ;
1795
1775
assert ! ( local_tx. tx. has_local_sig( ) ) ;
1796
- let mut res = self . broadcast_by_local_state ( local_tx, & self . onchain_detection . delayed_payment_base_key ) ;
1776
+ let mut res = self . broadcast_by_local_state ( local_tx) ;
1797
1777
append_onchain_update ! ( res) ;
1798
1778
}
1799
1779
}
@@ -1837,11 +1817,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1837
1817
// tracking state and panic!()ing if we get an update after force-closure/local-tx signing.
1838
1818
log_trace ! ( self , "Getting signed latest local commitment transaction!" ) ;
1839
1819
if let & mut Some ( ref mut local_tx) = & mut self . current_local_signed_commitment_tx {
1840
- local_tx. tx . add_local_sig ( & self . onchain_detection . funding_key , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1820
+ local_tx. tx . add_local_sig ( & self . onchain_detection . keys . funding_key ( ) , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1841
1821
}
1842
1822
if let & Some ( ref local_tx) = & self . current_local_signed_commitment_tx {
1843
1823
let mut res = vec ! [ local_tx. tx. with_valid_witness( ) . clone( ) ] ;
1844
- res. append ( & mut self . broadcast_by_local_state ( local_tx, & self . onchain_detection . delayed_payment_base_key ) . 0 ) ;
1824
+ res. append ( & mut self . broadcast_by_local_state ( local_tx) . 0 ) ;
1845
1825
// We throw away the generated waiting_first_conf data as we aren't (yet) confirmed and we don't actually know what the caller wants to do.
1846
1826
// The data will be re-generated and tracked in check_spend_local_transaction if we get a confirmation.
1847
1827
res
@@ -1919,14 +1899,14 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1919
1899
} else { false } ;
1920
1900
if let Some ( ref mut cur_local_tx) = self . current_local_signed_commitment_tx {
1921
1901
if should_broadcast {
1922
- cur_local_tx. tx . add_local_sig ( & self . onchain_detection . funding_key , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1902
+ cur_local_tx. tx . add_local_sig ( & self . onchain_detection . keys . funding_key ( ) , self . funding_redeemscript . as_ref ( ) . unwrap ( ) , self . channel_value_satoshis . unwrap ( ) , & self . secp_ctx ) ;
1923
1903
}
1924
1904
}
1925
1905
if let Some ( ref cur_local_tx) = self . current_local_signed_commitment_tx {
1926
1906
if should_broadcast {
1927
1907
log_trace ! ( self , "Broadcast onchain {}" , log_tx!( cur_local_tx. tx. with_valid_witness( ) ) ) ;
1928
1908
broadcaster. broadcast_transaction ( & cur_local_tx. tx . with_valid_witness ( ) ) ;
1929
- let ( txs, new_outputs, _) = self . broadcast_by_local_state ( & cur_local_tx, & self . onchain_detection . delayed_payment_base_key ) ;
1909
+ let ( txs, new_outputs, _) = self . broadcast_by_local_state ( & cur_local_tx) ;
1930
1910
if !new_outputs. is_empty ( ) {
1931
1911
watch_outputs. push ( ( cur_local_tx. txid . clone ( ) , new_outputs) ) ;
1932
1912
}
@@ -2283,11 +2263,6 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2283
2263
2284
2264
let onchain_detection = {
2285
2265
let keys = Readable :: read ( reader) ?;
2286
- let funding_key = Readable :: read ( reader) ?;
2287
- let revocation_base_key = Readable :: read ( reader) ?;
2288
- let htlc_base_key = Readable :: read ( reader) ?;
2289
- let delayed_payment_base_key = Readable :: read ( reader) ?;
2290
- let payment_base_key = Readable :: read ( reader) ?;
2291
2266
// Technically this can fail and serialize fail a round-trip, but only for serialization of
2292
2267
// barely-init'd ChannelMonitors that we can't do anything with.
2293
2268
let outpoint = OutPoint {
@@ -2299,11 +2274,6 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2299
2274
let prev_remote_commitment_txid = Readable :: read ( reader) ?;
2300
2275
OnchainDetection {
2301
2276
keys,
2302
- funding_key,
2303
- revocation_base_key,
2304
- htlc_base_key,
2305
- delayed_payment_base_key,
2306
- payment_base_key,
2307
2277
funding_info,
2308
2278
current_remote_commitment_txid,
2309
2279
prev_remote_commitment_txid,
0 commit comments