@@ -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,6 +605,7 @@ 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 ) > ,
@@ -756,6 +757,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
756
757
757
758
// Set in initial Channel-object creation, so should always be set by now:
758
759
U48 ( self . commitment_transaction_number_obscure_factor ) . write ( writer) ?;
760
+ self . is_outbound . write ( writer) ?;
759
761
760
762
self . destination_script . write ( writer) ?;
761
763
if let Some ( ref broadcasted_holder_revokable_script) = self . broadcasted_holder_revokable_script {
@@ -934,9 +936,10 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
934
936
impl < ChanSigner : ChannelKeys > ChannelMonitor < ChanSigner > {
935
937
pub ( crate ) fn new ( keys : ChanSigner , shutdown_pubkey : & PublicKey ,
936
938
on_counterparty_tx_csv : u16 , destination_script : & Script , funding_info : ( OutPoint , Script ) ,
937
- counterparty_htlc_base_key : & PublicKey , counterparty_delayed_payment_base_key : & PublicKey ,
939
+ counterparty_pubkeys : & ChannelPublicKeys ,
938
940
on_holder_tx_csv : u16 , funding_redeemscript : Script , channel_value_satoshis : u64 ,
939
941
commitment_transaction_number_obscure_factor : u64 ,
942
+ is_outbound : bool ,
940
943
initial_holder_commitment_tx : HolderCommitmentTransaction ) -> ChannelMonitor < ChanSigner > {
941
944
942
945
assert ! ( commitment_transaction_number_obscure_factor <= ( 1 << 48 ) ) ;
@@ -945,7 +948,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
945
948
let payment_key_hash = WPubkeyHash :: hash ( & keys. pubkeys ( ) . payment_point . serialize ( ) ) ;
946
949
let counterparty_payment_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & payment_key_hash[ ..] ) . into_script ( ) ;
947
950
948
- 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 ( ) } ;
951
+ let counterparty_delayed_payment_base_key = counterparty_pubkeys. delayed_payment_basepoint ;
952
+ let counterparty_htlc_base_key = counterparty_pubkeys. htlc_basepoint ;
953
+ let counterparty_tx_cache = CounterpartyCommitmentTransaction { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv, per_htlc : HashMap :: new ( ) } ;
949
954
950
955
let mut onchain_tx_handler = OnchainTxHandler :: new ( destination_script. clone ( ) , keys. clone ( ) , on_holder_tx_csv) ;
951
956
@@ -969,6 +974,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
969
974
ChannelMonitor {
970
975
latest_update_id : 0 ,
971
976
commitment_transaction_number_obscure_factor,
977
+ is_outbound,
972
978
973
979
destination_script : destination_script. clone ( ) ,
974
980
broadcasted_holder_revokable_script : None ,
@@ -2199,6 +2205,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2199
2205
2200
2206
let latest_update_id: u64 = Readable :: read ( reader) ?;
2201
2207
let commitment_transaction_number_obscure_factor = <U48 as Readable >:: read ( reader) ?. 0 ;
2208
+ let is_outbound = Readable :: read ( reader) ?;
2202
2209
2203
2210
let destination_script = Readable :: read ( reader) ?;
2204
2211
let broadcasted_holder_revokable_script = match <u8 as Readable >:: read ( reader) ? {
@@ -2422,6 +2429,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
2422
2429
Ok ( ( last_block_hash. clone ( ) , ChannelMonitor {
2423
2430
latest_update_id,
2424
2431
commitment_transaction_number_obscure_factor,
2432
+ is_outbound,
2425
2433
2426
2434
destination_script,
2427
2435
broadcasted_holder_revokable_script,
@@ -2485,7 +2493,7 @@ mod tests {
2485
2493
use ln:: channelmanager:: { PaymentPreimage , PaymentHash } ;
2486
2494
use ln:: onchaintx:: { OnchainTxHandler , InputDescriptors } ;
2487
2495
use ln:: chan_utils;
2488
- use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction } ;
2496
+ use ln:: chan_utils:: { HTLCOutputInCommitment , HolderCommitmentTransaction , ChannelPublicKeys } ;
2489
2497
use util:: test_utils:: TestLogger ;
2490
2498
use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
2491
2499
use bitcoin:: secp256k1:: Secp256k1 ;
@@ -2556,14 +2564,21 @@ mod tests {
2556
2564
( 0 , 0 )
2557
2565
) ;
2558
2566
2567
+ let counterparty_pubkeys = ChannelPublicKeys {
2568
+ funding_pubkey : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
2569
+ revocation_basepoint : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ,
2570
+ payment_point : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 46 ; 32 ] ) . unwrap ( ) ) ,
2571
+ delayed_payment_basepoint : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 47 ; 32 ] ) . unwrap ( ) ) ,
2572
+ htlc_basepoint : PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 48 ; 32 ] ) . unwrap ( ) )
2573
+ } ;
2559
2574
// Prune with one old state and a holder commitment tx holding a few overlaps with the
2560
2575
// old state.
2561
2576
let mut monitor = ChannelMonitor :: new ( keys,
2562
2577
& PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) , 0 , & Script :: new ( ) ,
2563
2578
( OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } , Script :: new ( ) ) ,
2564
- & PublicKey :: from_secret_key ( & secp_ctx , & SecretKey :: from_slice ( & [ 44 ; 32 ] ) . unwrap ( ) ) ,
2565
- & PublicKey :: from_secret_key ( & secp_ctx , & SecretKey :: from_slice ( & [ 45 ; 32 ] ) . unwrap ( ) ) ,
2566
- 10 , Script :: new ( ) , 46 , 0 , HolderCommitmentTransaction :: dummy ( ) ) ;
2579
+ & counterparty_pubkeys ,
2580
+ 10 , Script :: new ( ) , 46 , 0 ,
2581
+ true , HolderCommitmentTransaction :: dummy ( ) ) ;
2567
2582
2568
2583
monitor. provide_latest_holder_commitment_tx_info ( HolderCommitmentTransaction :: dummy ( ) , preimages_to_holder_htlcs ! ( preimages[ 0 ..10 ] ) ) . unwrap ( ) ;
2569
2584
monitor. provide_latest_counterparty_commitment_tx_info ( & dummy_tx, preimages_slice_to_htlc_outputs ! ( preimages[ 5 ..15 ] ) , 281474976710655 , dummy_key, & logger) ;
0 commit comments