@@ -39,7 +39,7 @@ use bitcoin::secp256k1;
39
39
40
40
use ln:: msgs:: DecodeError ;
41
41
use ln:: chan_utils;
42
- use ln:: chan_utils:: { CounterpartyCommitmentSecrets , HTLCOutputInCommitment , HolderCommitmentTransaction , HTLCType } ;
42
+ use ln:: chan_utils:: { CounterpartyCommitmentSecrets , HTLCOutputInCommitment , HolderCommitmentTransaction , HTLCType , ChannelPublicKeys } ;
43
43
use ln:: channelmanager:: { HTLCSource , PaymentPreimage , PaymentHash } ;
44
44
use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
45
45
use chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
@@ -605,13 +605,15 @@ impl Readable for ChannelMonitorUpdateStep {
605
605
pub struct ChannelMonitor < ChanSigner : ChannelKeys > {
606
606
latest_update_id : u64 ,
607
607
commitment_transaction_number_obscure_factor : u64 ,
608
+ is_outbound : bool ,
608
609
609
610
destination_script : Script ,
610
611
broadcasted_holder_revokable_script : Option < ( Script , PublicKey , PublicKey ) > ,
611
612
counterparty_payment_script : Script ,
612
613
shutdown_script : Script ,
613
614
614
615
keys : ChanSigner ,
616
+ counterparty_pubkeys : ChannelPublicKeys ,
615
617
funding_info : ( OutPoint , Script ) ,
616
618
current_counterparty_commitment_txid : Option < Txid > ,
617
619
prev_counterparty_commitment_txid : Option < Txid > ,
@@ -756,6 +758,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
756
758
757
759
// Set in initial Channel-object creation, so should always be set by now:
758
760
U48 ( self . commitment_transaction_number_obscure_factor ) . write ( writer) ?;
761
+ self . is_outbound . write ( writer) ?;
759
762
760
763
self . destination_script . write ( writer) ?;
761
764
if let Some ( ref broadcasted_holder_revokable_script) = self . broadcasted_holder_revokable_script {
@@ -771,6 +774,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
771
774
self . shutdown_script . write ( writer) ?;
772
775
773
776
self . keys . write ( writer) ?;
777
+ self . counterparty_pubkeys . write ( writer) ?;
774
778
writer. write_all ( & self . funding_info . 0 . txid [ ..] ) ?;
775
779
writer. write_all ( & byte_utils:: be16_to_array ( self . funding_info . 0 . index ) ) ?;
776
780
self . funding_info . 1 . write ( writer) ?;
@@ -933,9 +937,10 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
933
937
impl < ChanSigner : ChannelKeys > ChannelMonitor < ChanSigner > {
934
938
pub ( crate ) fn new ( keys : ChanSigner , shutdown_pubkey : & PublicKey ,
935
939
on_counterparty_tx_csv : u16 , destination_script : & Script , funding_info : ( OutPoint , Script ) ,
936
- counterparty_htlc_base_key : & PublicKey , counterparty_delayed_payment_base_key : & PublicKey ,
940
+ counterparty_pubkeys : & ChannelPublicKeys ,
937
941
on_holder_tx_csv : u16 , funding_redeemscript : Script , channel_value_satoshis : u64 ,
938
942
commitment_transaction_number_obscure_factor : u64 ,
943
+ is_outbound : bool ,
939
944
initial_holder_commitment_tx : HolderCommitmentTransaction ) -> ChannelMonitor < ChanSigner > {
940
945
941
946
assert ! ( commitment_transaction_number_obscure_factor <= ( 1 << 48 ) ) ;
@@ -944,7 +949,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
944
949
let payment_key_hash = WPubkeyHash :: hash ( & keys. pubkeys ( ) . payment_point . serialize ( ) ) ;
945
950
let counterparty_payment_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & payment_key_hash[ ..] ) . into_script ( ) ;
946
951
947
- let counterparty_tx_cache = CounterpartyCommitmentTransaction { counterparty_delayed_payment_base_key : * counterparty_delayed_payment_base_key, counterparty_htlc_base_key : * counterparty_htlc_base_key, on_counterparty_tx_csv, per_htlc : HashMap :: new ( ) } ;
952
+ let counterparty_delayed_payment_base_key = counterparty_pubkeys. delayed_payment_basepoint ;
953
+ let counterparty_htlc_base_key = counterparty_pubkeys. htlc_basepoint ;
954
+ let counterparty_tx_cache = CounterpartyCommitmentTransaction { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv, per_htlc : HashMap :: new ( ) } ;
948
955
949
956
let mut onchain_tx_handler = OnchainTxHandler :: new ( destination_script. clone ( ) , keys. clone ( ) , on_holder_tx_csv) ;
950
957
@@ -968,13 +975,15 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
968
975
ChannelMonitor {
969
976
latest_update_id : 0 ,
970
977
commitment_transaction_number_obscure_factor,
978
+ is_outbound,
971
979
972
980
destination_script : destination_script. clone ( ) ,
973
981
broadcasted_holder_revokable_script : None ,
974
982
counterparty_payment_script,
975
983
shutdown_script,
976
984
977
985
keys,
986
+ counterparty_pubkeys : counterparty_pubkeys. clone ( ) ,
978
987
funding_info,
979
988
current_counterparty_commitment_txid : None ,
980
989
prev_counterparty_commitment_txid : None ,
@@ -2113,6 +2122,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2113
2122
2114
2123
let latest_update_id: u64 = Readable :: read ( reader) ?;
2115
2124
let commitment_transaction_number_obscure_factor = <U48 as Readable >:: read ( reader) ?. 0 ;
2125
+ let is_outbound = Readable :: read ( reader) ?;
2116
2126
2117
2127
let destination_script = Readable :: read ( reader) ?;
2118
2128
let broadcasted_holder_revokable_script = match <u8 as Readable >:: read ( reader) ? {
@@ -2129,6 +2139,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2129
2139
let shutdown_script = Readable :: read ( reader) ?;
2130
2140
2131
2141
let keys = Readable :: read ( reader) ?;
2142
+ let counterparty_pubkeys = Readable :: read ( reader) ?;
2132
2143
// Technically this can fail and serialize fail a round-trip, but only for serialization of
2133
2144
// barely-init'd ChannelMonitors that we can't do anything with.
2134
2145
let outpoint = OutPoint {
@@ -2336,13 +2347,15 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2336
2347
Ok ( ( last_block_hash. clone ( ) , ChannelMonitor {
2337
2348
latest_update_id,
2338
2349
commitment_transaction_number_obscure_factor,
2350
+ is_outbound,
2339
2351
2340
2352
destination_script,
2341
2353
broadcasted_holder_revokable_script,
2342
2354
counterparty_payment_script,
2343
2355
shutdown_script,
2344
2356
2345
2357
keys,
2358
+ counterparty_pubkeys,
2346
2359
funding_info,
2347
2360
current_counterparty_commitment_txid,
2348
2361
prev_counterparty_commitment_txid,
@@ -2399,7 +2412,7 @@ mod tests {
2399
2412
use ln:: channelmanager:: { PaymentPreimage , PaymentHash } ;
2400
2413
use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
2401
2414
use ln:: chan_utils;
2402
- use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2415
+ use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction , ChannelPublicKeys } ;
2403
2416
use util:: test_utils:: TestLogger ;
2404
2417
use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
2405
2418
use bitcoin:: secp256k1:: Secp256k1 ;
@@ -2470,14 +2483,21 @@ mod tests {
2470
2483
( 0 , 0 )
2471
2484
) ;
2472
2485
2486
+ let counterparty_pubkeys = ChannelPublicKeys {
2487
+ funding_pubkey : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
2488
+ revocation_basepoint : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ,
2489
+ payment_point : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 46 ; 32 ] ) . unwrap ( ) ) ,
2490
+ delayed_payment_basepoint : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 47 ; 32 ] ) . unwrap ( ) ) ,
2491
+ htlc_basepoint : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 48 ; 32 ] ) . unwrap ( ) )
2492
+ } ;
2473
2493
// Prune with one old state and a holder commitment tx holding a few overlaps with the
2474
2494
// old state.
2475
2495
let mut monitor = ChannelMonitor :: new ( keys,
2476
2496
& PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) , 0 , & Script :: new ( ) ,
2477
2497
( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , Script :: new ( ) ) ,
2478
- & PublicKey :: from_secret_key ( & secp_ctx , & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
2479
- & PublicKey :: from_secret_key ( & secp_ctx , & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ,
2480
- 10 , Script :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( ) ) ;
2498
+ & counterparty_pubkeys ,
2499
+ 10 , Script :: new ( ) , 46 , 0 ,
2500
+ true , HolderCommitmentTransaction :: dummy ( ) ) ;
2481
2501
2482
2502
monitor. provide_latest_holder_commitment_tx_info ( HolderCommitmentTransaction :: dummy ( ) , preimages_to_holder_htlcs ! ( preimages[ 0 ..10 ] ) ) . unwrap ( ) ;
2483
2503
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 5 ..15 ] ) , 281474976710655 , dummy_key, & logger) ;
0 commit comments