@@ -872,10 +872,9 @@ impl<Signer: EcdsaChannelSigner> Clone for ChannelMonitor<Signer> where Signer:
872
872
873
873
#[ derive( Clone , PartialEq ) ]
874
874
struct FundingScope {
875
- outpoint : OutPoint ,
876
875
script_pubkey : ScriptBuf ,
877
876
redeem_script : ScriptBuf ,
878
- channel_value_satoshis : u64 ,
877
+ channel_parameters : ChannelTransactionParameters ,
879
878
880
879
current_counterparty_commitment_txid : Option < Txid > ,
881
880
prev_counterparty_commitment_txid : Option < Txid > ,
@@ -1110,15 +1109,16 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
1110
1109
1111
1110
self . channel_keys_id . write ( writer) ?;
1112
1111
self . holder_revocation_basepoint . write ( writer) ?;
1113
- writer. write_all ( & self . funding . outpoint . txid [ ..] ) ?;
1114
- writer. write_all ( & self . funding . outpoint . index . to_be_bytes ( ) ) ?;
1112
+ let funding_outpoint = self . get_funding_txo ( ) ;
1113
+ writer. write_all ( & funding_outpoint. txid [ ..] ) ?;
1114
+ writer. write_all ( & funding_outpoint. index . to_be_bytes ( ) ) ?;
1115
1115
self . funding . script_pubkey . write ( writer) ?;
1116
1116
self . funding . current_counterparty_commitment_txid . write ( writer) ?;
1117
1117
self . funding . prev_counterparty_commitment_txid . write ( writer) ?;
1118
1118
1119
1119
self . counterparty_commitment_params . write ( writer) ?;
1120
1120
self . funding . redeem_script . write ( writer) ?;
1121
- self . funding . channel_value_satoshis . write ( writer) ?;
1121
+ self . funding . channel_parameters . channel_value_satoshis . write ( writer) ?;
1122
1122
1123
1123
match self . their_cur_per_commitment_points {
1124
1124
Some ( ( idx, pubkey, second_option) ) => {
@@ -1375,10 +1375,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1375
1375
1376
1376
pub ( crate ) fn new (
1377
1377
secp_ctx : Secp256k1 < secp256k1:: All > , keys : Signer , shutdown_script : Option < ScriptBuf > ,
1378
- on_counterparty_tx_csv : u16 , destination_script : & Script , funding_outpoint : OutPoint ,
1379
- funding_script : ScriptBuf , channel_parameters : & ChannelTransactionParameters ,
1380
- holder_pays_commitment_tx_fee : bool , funding_redeemscript : ScriptBuf ,
1381
- channel_value_satoshis : u64 , commitment_transaction_number_obscure_factor : u64 ,
1378
+ on_counterparty_tx_csv : u16 , destination_script : & Script ,
1379
+ channel_parameters : & ChannelTransactionParameters , holder_pays_commitment_tx_fee : bool ,
1380
+ commitment_transaction_number_obscure_factor : u64 ,
1382
1381
initial_holder_commitment_tx : HolderCommitmentTransaction , best_block : BestBlock ,
1383
1382
counterparty_node_id : PublicKey , channel_id : ChannelId ,
1384
1383
) -> ChannelMonitor < Signer > {
@@ -1418,21 +1417,24 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1418
1417
} ;
1419
1418
1420
1419
let onchain_tx_handler = OnchainTxHandler :: new (
1421
- channel_value_satoshis, channel_keys_id, destination_script. into ( ) , keys ,
1422
- channel_parameters. clone ( ) , initial_holder_commitment_tx, secp_ctx
1420
+ channel_parameters . channel_value_satoshis , channel_keys_id, destination_script. into ( ) ,
1421
+ keys , channel_parameters. clone ( ) , initial_holder_commitment_tx, secp_ctx
1423
1422
) ;
1424
1423
1424
+ let funding_outpoint = channel_parameters. funding_outpoint
1425
+ . expect ( "Funding outpoint must be known during initialization" ) ;
1426
+ let funding_redeem_script = channel_parameters. make_funding_redeemscript ( ) ;
1427
+ let funding_script = funding_redeem_script. to_p2wsh ( ) ;
1425
1428
let mut outputs_to_watch = new_hash_map ( ) ;
1426
1429
outputs_to_watch. insert (
1427
1430
funding_outpoint. txid , vec ! [ ( funding_outpoint. index as u32 , funding_script. clone( ) ) ] ,
1428
1431
) ;
1429
1432
1430
1433
Self :: from_impl ( ChannelMonitorImpl {
1431
1434
funding : FundingScope {
1432
- outpoint : funding_outpoint,
1433
1435
script_pubkey : funding_script,
1434
- redeem_script : funding_redeemscript ,
1435
- channel_value_satoshis ,
1436
+ redeem_script : funding_redeem_script ,
1437
+ channel_parameters : channel_parameters . clone ( ) ,
1436
1438
1437
1439
current_counterparty_commitment_txid : None ,
1438
1440
prev_counterparty_commitment_txid : None ,
@@ -1663,7 +1665,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1663
1665
let lock = self . inner . lock ( ) . unwrap ( ) ;
1664
1666
let logger = WithChannelMonitor :: from_impl ( logger, & * lock, None ) ;
1665
1667
log_trace ! ( & logger, "Registering funding outpoint {}" , & lock. get_funding_txo( ) ) ;
1666
- filter. register_tx ( & lock. funding . outpoint . txid , & lock. funding . script_pubkey ) ;
1668
+ let funding_outpoint = lock. get_funding_txo ( ) ;
1669
+ filter. register_tx ( & funding_outpoint. txid , & lock. funding . script_pubkey ) ;
1667
1670
for ( txid, outputs) in lock. get_outputs_to_watch ( ) . iter ( ) {
1668
1671
for ( index, script_pubkey) in outputs. iter ( ) {
1669
1672
assert ! ( * index <= u16 :: MAX as u32 ) ;
@@ -3146,18 +3149,19 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3146
3149
fn generate_claimable_outpoints_and_watch_outputs ( & mut self , reason : ClosureReason ) -> ( Vec < PackageTemplate > , Vec < TransactionOutputs > ) {
3147
3150
let funding_outp = HolderFundingOutput :: build (
3148
3151
self . funding . redeem_script . clone ( ) ,
3149
- self . funding . channel_value_satoshis ,
3152
+ self . funding . channel_parameters . channel_value_satoshis ,
3150
3153
self . onchain_tx_handler . channel_type_features ( ) . clone ( )
3151
3154
) ;
3155
+ let funding_outpoint = self . get_funding_txo ( ) ;
3152
3156
let commitment_package = PackageTemplate :: build_package (
3153
- self . funding . outpoint . txid . clone ( ) , self . funding . outpoint . index as u32 ,
3157
+ funding_outpoint . txid . clone ( ) , funding_outpoint . index as u32 ,
3154
3158
PackageSolvingData :: HolderFundingOutput ( funding_outp) ,
3155
3159
self . best_block . height ,
3156
3160
) ;
3157
3161
let mut claimable_outpoints = vec ! [ commitment_package] ;
3158
3162
let event = MonitorEvent :: HolderForceClosedWithInfo {
3159
3163
reason,
3160
- outpoint : self . funding . outpoint ,
3164
+ outpoint : funding_outpoint ,
3161
3165
channel_id : self . channel_id ,
3162
3166
} ;
3163
3167
self . pending_monitor_events . push ( event) ;
@@ -3360,7 +3364,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3360
3364
}
3361
3365
3362
3366
fn get_funding_txo ( & self ) -> OutPoint {
3363
- self . funding . outpoint
3367
+ self . funding . channel_parameters . funding_outpoint
3368
+ . expect ( "Funding outpoint must be set for active monitor" )
3364
3369
}
3365
3370
3366
3371
fn get_funding_script ( & self ) -> ScriptBuf {
@@ -3403,7 +3408,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3403
3408
let commitment_txid = commitment_tx. compute_txid ( ) ;
3404
3409
debug_assert_eq ! ( self . funding. current_holder_commitment_tx. txid, commitment_txid) ;
3405
3410
let pending_htlcs = self . funding . current_holder_commitment_tx . non_dust_htlcs ( ) ;
3406
- let commitment_tx_fee_satoshis = self . funding . channel_value_satoshis -
3411
+ let channel_value_satoshis = self . funding . channel_parameters . channel_value_satoshis ;
3412
+ let commitment_tx_fee_satoshis = channel_value_satoshis -
3407
3413
commitment_tx. output . iter ( ) . fold ( 0u64 , |sum, output| sum + output. value . to_sat ( ) ) ;
3408
3414
ret. push ( Event :: BumpTransaction ( BumpTransactionEvent :: ChannelClose {
3409
3415
channel_id,
@@ -3415,7 +3421,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3415
3421
anchor_descriptor : AnchorDescriptor {
3416
3422
channel_derivation_parameters : ChannelDerivationParameters {
3417
3423
keys_id : self . channel_keys_id ,
3418
- value_satoshis : self . funding . channel_value_satoshis ,
3424
+ value_satoshis : channel_value_satoshis,
3419
3425
transaction_parameters : self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ,
3420
3426
} ,
3421
3427
outpoint : BitcoinOutPoint {
@@ -3436,7 +3442,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3436
3442
htlc_descriptors. push ( HTLCDescriptor {
3437
3443
channel_derivation_parameters : ChannelDerivationParameters {
3438
3444
keys_id : self . channel_keys_id ,
3439
- value_satoshis : self . funding . channel_value_satoshis ,
3445
+ value_satoshis : self . funding . channel_parameters . channel_value_satoshis ,
3440
3446
transaction_parameters : self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ,
3441
3447
} ,
3442
3448
commitment_txid : htlc. commitment_txid ,
@@ -4139,7 +4145,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4139
4145
// (except for HTLC transactions for channels with anchor outputs), which is an easy
4140
4146
// way to filter out any potential non-matching txn for lazy filters.
4141
4147
let prevout = & tx. input [ 0 ] . previous_output ;
4142
- if prevout. txid == self . funding . outpoint . txid && prevout. vout == self . funding . outpoint . index as u32 {
4148
+ let funding_outpoint = self . get_funding_txo ( ) ;
4149
+ if prevout. txid == funding_outpoint. txid && prevout. vout == funding_outpoint. index as u32 {
4143
4150
let mut balance_spendable_csv = None ;
4144
4151
log_info ! ( logger, "Channel {} closed by funding output spend in txid {}." ,
4145
4152
& self . channel_id( ) , txid) ;
@@ -4809,7 +4816,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4809
4816
output : outp. clone ( ) ,
4810
4817
revocation_pubkey : broadcasted_holder_revokable_script. 2 ,
4811
4818
channel_keys_id : self . channel_keys_id ,
4812
- channel_value_satoshis : self . funding . channel_value_satoshis ,
4819
+ channel_value_satoshis : self . funding . channel_parameters . channel_value_satoshis ,
4813
4820
channel_transaction_parameters : Some ( self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ) ,
4814
4821
} ) ) ;
4815
4822
}
@@ -4819,7 +4826,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4819
4826
outpoint : OutPoint { txid : tx. compute_txid ( ) , index : i as u16 } ,
4820
4827
output : outp. clone ( ) ,
4821
4828
channel_keys_id : self . channel_keys_id ,
4822
- channel_value_satoshis : self . funding . channel_value_satoshis ,
4829
+ channel_value_satoshis : self . funding . channel_parameters . channel_value_satoshis ,
4823
4830
channel_transaction_parameters : Some ( self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ) ,
4824
4831
} ) ) ;
4825
4832
}
@@ -5183,12 +5190,13 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5183
5190
To continue, run a v0.1 release, send/route a payment over the channel or close it.", channel_id) ;
5184
5191
}
5185
5192
5193
+ let channel_parameters = onchain_tx_handler. channel_transaction_parameters . clone ( ) ;
5194
+
5186
5195
Ok ( ( best_block. block_hash , ChannelMonitor :: from_impl ( ChannelMonitorImpl {
5187
5196
funding : FundingScope {
5188
- outpoint,
5189
5197
script_pubkey : funding_script,
5190
5198
redeem_script : funding_redeemscript,
5191
- channel_value_satoshis ,
5199
+ channel_parameters ,
5192
5200
5193
5201
current_counterparty_commitment_txid,
5194
5202
prev_counterparty_commitment_txid,
@@ -5481,12 +5489,11 @@ mod tests {
5481
5489
// old state.
5482
5490
let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
5483
5491
let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
5484
- let funding_txo = OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } ;
5485
5492
let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
5486
5493
let monitor = ChannelMonitor :: new (
5487
5494
Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5488
- funding_txo , ScriptBuf :: new ( ) , & channel_parameters , true , ScriptBuf :: new ( ) , 46 , 0 ,
5489
- HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) , best_block, dummy_key, channel_id,
5495
+ & channel_parameters , true , 0 , HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) ,
5496
+ best_block, dummy_key, channel_id,
5490
5497
) ;
5491
5498
5492
5499
let mut htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
@@ -5734,12 +5741,11 @@ mod tests {
5734
5741
} ;
5735
5742
let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
5736
5743
let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
5737
- let funding_txo = OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } ;
5738
5744
let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
5739
5745
let monitor = ChannelMonitor :: new (
5740
5746
Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5741
- funding_txo , ScriptBuf :: new ( ) , & channel_parameters , true , ScriptBuf :: new ( ) , 46 , 0 ,
5742
- HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) , best_block, dummy_key, channel_id,
5747
+ & channel_parameters , true , 0 , HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) ,
5748
+ best_block, dummy_key, channel_id,
5743
5749
) ;
5744
5750
5745
5751
let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
0 commit comments