@@ -713,6 +713,7 @@ pub struct ChannelMonitor<Signer: WriteableEcdsaChannelSigner> {
713
713
inner : Mutex < ChannelMonitorImpl < Signer > > ,
714
714
}
715
715
716
+ #[ derive( PartialEq ) ]
716
717
pub ( crate ) struct ChannelMonitorImpl < Signer : WriteableEcdsaChannelSigner > {
717
718
latest_update_id : u64 ,
718
719
commitment_transaction_number_obscure_factor : u64 ,
@@ -847,71 +848,19 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
847
848
848
849
/// The node_id of our counterparty
849
850
counterparty_node_id : Option < PublicKey > ,
850
-
851
- secp_ctx : Secp256k1 < secp256k1:: All > , //TODO: dedup this a bit...
852
851
}
853
852
854
853
/// Transaction outputs to watch for on-chain spends.
855
854
pub type TransactionOutputs = ( Txid , Vec < ( u32 , TxOut ) > ) ;
856
855
857
- #[ cfg( any( test, fuzzing, feature = "_test_utils" ) ) ]
858
- /// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
859
- /// object
860
- impl < Signer : WriteableEcdsaChannelSigner > PartialEq for ChannelMonitor < Signer > {
856
+ impl < Signer : WriteableEcdsaChannelSigner > PartialEq for ChannelMonitor < Signer > where Signer : PartialEq {
861
857
fn eq ( & self , other : & Self ) -> bool {
862
858
let inner = self . inner . lock ( ) . unwrap ( ) ;
863
859
let other = other. inner . lock ( ) . unwrap ( ) ;
864
860
inner. eq ( & other)
865
861
}
866
862
}
867
863
868
- #[ cfg( any( test, fuzzing, feature = "_test_utils" ) ) ]
869
- /// Used only in testing and fuzzing to check serialization roundtrips don't change the underlying
870
- /// object
871
- impl < Signer : WriteableEcdsaChannelSigner > PartialEq for ChannelMonitorImpl < Signer > {
872
- fn eq ( & self , other : & Self ) -> bool {
873
- if self . latest_update_id != other. latest_update_id ||
874
- self . commitment_transaction_number_obscure_factor != other. commitment_transaction_number_obscure_factor ||
875
- self . destination_script != other. destination_script ||
876
- self . broadcasted_holder_revokable_script != other. broadcasted_holder_revokable_script ||
877
- self . counterparty_payment_script != other. counterparty_payment_script ||
878
- self . channel_keys_id != other. channel_keys_id ||
879
- self . holder_revocation_basepoint != other. holder_revocation_basepoint ||
880
- self . funding_info != other. funding_info ||
881
- self . current_counterparty_commitment_txid != other. current_counterparty_commitment_txid ||
882
- self . prev_counterparty_commitment_txid != other. prev_counterparty_commitment_txid ||
883
- self . counterparty_commitment_params != other. counterparty_commitment_params ||
884
- self . funding_redeemscript != other. funding_redeemscript ||
885
- self . channel_value_satoshis != other. channel_value_satoshis ||
886
- self . their_cur_per_commitment_points != other. their_cur_per_commitment_points ||
887
- self . on_holder_tx_csv != other. on_holder_tx_csv ||
888
- self . commitment_secrets != other. commitment_secrets ||
889
- self . counterparty_claimable_outpoints != other. counterparty_claimable_outpoints ||
890
- self . counterparty_commitment_txn_on_chain != other. counterparty_commitment_txn_on_chain ||
891
- self . counterparty_hash_commitment_number != other. counterparty_hash_commitment_number ||
892
- self . prev_holder_signed_commitment_tx != other. prev_holder_signed_commitment_tx ||
893
- self . current_counterparty_commitment_number != other. current_counterparty_commitment_number ||
894
- self . current_holder_commitment_number != other. current_holder_commitment_number ||
895
- self . current_holder_commitment_tx != other. current_holder_commitment_tx ||
896
- self . payment_preimages != other. payment_preimages ||
897
- self . pending_monitor_events != other. pending_monitor_events ||
898
- self . pending_events . len ( ) != other. pending_events . len ( ) || // We trust events to round-trip properly
899
- self . onchain_events_awaiting_threshold_conf != other. onchain_events_awaiting_threshold_conf ||
900
- self . outputs_to_watch != other. outputs_to_watch ||
901
- self . lockdown_from_offchain != other. lockdown_from_offchain ||
902
- self . holder_tx_signed != other. holder_tx_signed ||
903
- self . funding_spend_seen != other. funding_spend_seen ||
904
- self . funding_spend_confirmed != other. funding_spend_confirmed ||
905
- self . confirmed_commitment_tx_counterparty_output != other. confirmed_commitment_tx_counterparty_output ||
906
- self . htlcs_resolved_on_chain != other. htlcs_resolved_on_chain
907
- {
908
- false
909
- } else {
910
- true
911
- }
912
- }
913
- }
914
-
915
864
impl < Signer : WriteableEcdsaChannelSigner > Writeable for ChannelMonitor < Signer > {
916
865
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , Error > {
917
866
self . inner . lock ( ) . unwrap ( ) . write ( writer)
@@ -1140,7 +1089,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1140
1089
1141
1090
let onchain_tx_handler =
1142
1091
OnchainTxHandler :: new ( destination_script. clone ( ) , keys,
1143
- channel_parameters. clone ( ) , initial_holder_commitment_tx, secp_ctx. clone ( ) ) ;
1092
+ channel_parameters. clone ( ) , initial_holder_commitment_tx, secp_ctx) ;
1144
1093
1145
1094
let mut outputs_to_watch = HashMap :: new ( ) ;
1146
1095
outputs_to_watch. insert ( funding_info. 0 . txid , vec ! [ ( funding_info. 0 . index as u32 , funding_info. 1 . clone( ) ) ] ) ;
@@ -1196,8 +1145,6 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1196
1145
1197
1146
best_block,
1198
1147
counterparty_node_id : Some ( counterparty_node_id) ,
1199
-
1200
- secp_ctx,
1201
1148
} )
1202
1149
}
1203
1150
@@ -2512,9 +2459,9 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2512
2459
if commitment_number >= self . get_min_seen_secret ( ) {
2513
2460
let secret = self . get_secret ( commitment_number) . unwrap ( ) ;
2514
2461
let per_commitment_key = ignore_error ! ( SecretKey :: from_slice( & secret) ) ;
2515
- let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
2516
- let revocation_pubkey = chan_utils:: derive_public_revocation_key ( & self . secp_ctx , & per_commitment_point, & self . holder_revocation_basepoint ) ;
2517
- let delayed_key = chan_utils:: derive_public_key ( & self . secp_ctx , & PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) , & self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ;
2462
+ let per_commitment_point = PublicKey :: from_secret_key ( & self . onchain_tx_handler . secp_ctx , & per_commitment_key) ;
2463
+ let revocation_pubkey = chan_utils:: derive_public_revocation_key ( & self . onchain_tx_handler . secp_ctx , & per_commitment_point, & self . holder_revocation_basepoint ) ;
2464
+ let delayed_key = chan_utils:: derive_public_key ( & self . onchain_tx_handler . secp_ctx , & PublicKey :: from_secret_key ( & self . onchain_tx_handler . secp_ctx , & per_commitment_key) , & self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ;
2518
2465
2519
2466
let revokeable_redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, self . counterparty_commitment_params . on_counterparty_tx_csv , & delayed_key) ;
2520
2467
let revokeable_p2wsh = revokeable_redeemscript. to_v0_p2wsh ( ) ;
@@ -2627,8 +2574,8 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2627
2574
2628
2575
if let Some ( transaction) = tx {
2629
2576
let revocation_pubkey = chan_utils:: derive_public_revocation_key (
2630
- & self . secp_ctx , & per_commitment_point, & self . holder_revocation_basepoint ) ;
2631
- let delayed_key = chan_utils:: derive_public_key ( & self . secp_ctx ,
2577
+ & self . onchain_tx_handler . secp_ctx , & per_commitment_point, & self . holder_revocation_basepoint ) ;
2578
+ let delayed_key = chan_utils:: derive_public_key ( & self . onchain_tx_handler . secp_ctx ,
2632
2579
& per_commitment_point,
2633
2580
& self . counterparty_commitment_params . counterparty_delayed_payment_base_key ) ;
2634
2581
let revokeable_p2wsh = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey,
@@ -2685,7 +2632,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2685
2632
Ok ( key) => key,
2686
2633
Err ( _) => return ( Vec :: new ( ) , None )
2687
2634
} ;
2688
- let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
2635
+ let per_commitment_point = PublicKey :: from_secret_key ( & self . onchain_tx_handler . secp_ctx , & per_commitment_key) ;
2689
2636
2690
2637
let htlc_txid = tx. txid ( ) ;
2691
2638
let mut claimable_outpoints = vec ! [ ] ;
@@ -3931,9 +3878,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
3931
3878
( 13 , spendable_txids_confirmed, vec_type) ,
3932
3879
} ) ;
3933
3880
3934
- let mut secp_ctx = Secp256k1 :: new ( ) ;
3935
- secp_ctx. seeded_randomize ( & entropy_source. get_secure_random_bytes ( ) ) ;
3936
-
3937
3881
Ok ( ( best_block. block_hash ( ) , ChannelMonitor :: from_impl ( ChannelMonitorImpl {
3938
3882
latest_update_id,
3939
3883
commitment_transaction_number_obscure_factor,
@@ -3985,8 +3929,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
3985
3929
3986
3930
best_block,
3987
3931
counterparty_node_id,
3988
-
3989
- secp_ctx,
3990
3932
} ) ) )
3991
3933
}
3992
3934
}
0 commit comments