@@ -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 > ,
@@ -1116,15 +1115,16 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
1116
1115
1117
1116
self . channel_keys_id . write ( writer) ?;
1118
1117
self . holder_revocation_basepoint . write ( writer) ?;
1119
- writer. write_all ( & self . funding . outpoint . txid [ ..] ) ?;
1120
- writer. write_all ( & self . funding . outpoint . index . to_be_bytes ( ) ) ?;
1118
+ let funding_outpoint = self . get_funding_txo ( ) ;
1119
+ writer. write_all ( & funding_outpoint. txid [ ..] ) ?;
1120
+ writer. write_all ( & funding_outpoint. index . to_be_bytes ( ) ) ?;
1121
1121
self . funding . script_pubkey . write ( writer) ?;
1122
1122
self . funding . current_counterparty_commitment_txid . write ( writer) ?;
1123
1123
self . funding . prev_counterparty_commitment_txid . write ( writer) ?;
1124
1124
1125
1125
self . counterparty_commitment_params . write ( writer) ?;
1126
1126
self . funding . redeem_script . write ( writer) ?;
1127
- self . funding . channel_value_satoshis . write ( writer) ?;
1127
+ self . funding . channel_parameters . channel_value_satoshis . write ( writer) ?;
1128
1128
1129
1129
match self . their_cur_per_commitment_points {
1130
1130
Some ( ( idx, pubkey, second_option) ) => {
@@ -1381,10 +1381,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1381
1381
1382
1382
pub ( crate ) fn new (
1383
1383
secp_ctx : Secp256k1 < secp256k1:: All > , keys : Signer , shutdown_script : Option < ScriptBuf > ,
1384
- on_counterparty_tx_csv : u16 , destination_script : & Script , funding_outpoint : OutPoint ,
1385
- funding_script : ScriptBuf , channel_parameters : & ChannelTransactionParameters ,
1386
- holder_pays_commitment_tx_fee : bool , funding_redeemscript : ScriptBuf ,
1387
- channel_value_satoshis : u64 , commitment_transaction_number_obscure_factor : u64 ,
1384
+ on_counterparty_tx_csv : u16 , destination_script : & Script ,
1385
+ channel_parameters : & ChannelTransactionParameters , holder_pays_commitment_tx_fee : bool ,
1386
+ commitment_transaction_number_obscure_factor : u64 ,
1388
1387
initial_holder_commitment_tx : HolderCommitmentTransaction , best_block : BestBlock ,
1389
1388
counterparty_node_id : PublicKey , channel_id : ChannelId ,
1390
1389
) -> ChannelMonitor < Signer > {
@@ -1424,21 +1423,24 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1424
1423
} ;
1425
1424
1426
1425
let onchain_tx_handler = OnchainTxHandler :: new (
1427
- channel_value_satoshis, channel_keys_id, destination_script. into ( ) , keys ,
1428
- channel_parameters. clone ( ) , initial_holder_commitment_tx, secp_ctx
1426
+ channel_parameters . channel_value_satoshis , channel_keys_id, destination_script. into ( ) ,
1427
+ keys , channel_parameters. clone ( ) , initial_holder_commitment_tx, secp_ctx
1429
1428
) ;
1430
1429
1430
+ let funding_outpoint = channel_parameters. funding_outpoint
1431
+ . expect ( "Funding outpoint must be known during initialization" ) ;
1432
+ let funding_redeem_script = channel_parameters. make_funding_redeemscript ( ) ;
1433
+ let funding_script = funding_redeem_script. to_p2wsh ( ) ;
1431
1434
let mut outputs_to_watch = new_hash_map ( ) ;
1432
1435
outputs_to_watch. insert (
1433
1436
funding_outpoint. txid , vec ! [ ( funding_outpoint. index as u32 , funding_script. clone( ) ) ] ,
1434
1437
) ;
1435
1438
1436
1439
Self :: from_impl ( ChannelMonitorImpl {
1437
1440
funding : FundingScope {
1438
- outpoint : funding_outpoint,
1439
1441
script_pubkey : funding_script,
1440
- redeem_script : funding_redeemscript ,
1441
- channel_value_satoshis ,
1442
+ redeem_script : funding_redeem_script ,
1443
+ channel_parameters : channel_parameters . clone ( ) ,
1442
1444
1443
1445
current_counterparty_commitment_txid : None ,
1444
1446
prev_counterparty_commitment_txid : None ,
@@ -1669,7 +1671,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1669
1671
let lock = self . inner . lock ( ) . unwrap ( ) ;
1670
1672
let logger = WithChannelMonitor :: from_impl ( logger, & * lock, None ) ;
1671
1673
log_trace ! ( & logger, "Registering funding outpoint {}" , & lock. get_funding_txo( ) ) ;
1672
- filter. register_tx ( & lock. funding . outpoint . txid , & lock. funding . script_pubkey ) ;
1674
+ let funding_outpoint = lock. get_funding_txo ( ) ;
1675
+ filter. register_tx ( & funding_outpoint. txid , & lock. funding . script_pubkey ) ;
1673
1676
for ( txid, outputs) in lock. get_outputs_to_watch ( ) . iter ( ) {
1674
1677
for ( index, script_pubkey) in outputs. iter ( ) {
1675
1678
assert ! ( * index <= u16 :: MAX as u32 ) ;
@@ -3152,18 +3155,19 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3152
3155
fn generate_claimable_outpoints_and_watch_outputs ( & mut self , reason : ClosureReason ) -> ( Vec < PackageTemplate > , Vec < TransactionOutputs > ) {
3153
3156
let funding_outp = HolderFundingOutput :: build (
3154
3157
self . funding . redeem_script . clone ( ) ,
3155
- self . funding . channel_value_satoshis ,
3158
+ self . funding . channel_parameters . channel_value_satoshis ,
3156
3159
self . onchain_tx_handler . channel_type_features ( ) . clone ( )
3157
3160
) ;
3161
+ let funding_outpoint = self . get_funding_txo ( ) ;
3158
3162
let commitment_package = PackageTemplate :: build_package (
3159
- self . funding . outpoint . txid . clone ( ) , self . funding . outpoint . index as u32 ,
3163
+ funding_outpoint . txid . clone ( ) , funding_outpoint . index as u32 ,
3160
3164
PackageSolvingData :: HolderFundingOutput ( funding_outp) ,
3161
3165
self . best_block . height ,
3162
3166
) ;
3163
3167
let mut claimable_outpoints = vec ! [ commitment_package] ;
3164
3168
let event = MonitorEvent :: HolderForceClosedWithInfo {
3165
3169
reason,
3166
- outpoint : self . funding . outpoint ,
3170
+ outpoint : funding_outpoint ,
3167
3171
channel_id : self . channel_id ,
3168
3172
} ;
3169
3173
self . pending_monitor_events . push ( event) ;
@@ -3366,7 +3370,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3366
3370
}
3367
3371
3368
3372
fn get_funding_txo ( & self ) -> OutPoint {
3369
- self . funding . outpoint
3373
+ self . funding . channel_parameters . funding_outpoint
3374
+ . expect ( "Funding outpoint must be set for active monitor" )
3370
3375
}
3371
3376
3372
3377
fn get_funding_script ( & self ) -> ScriptBuf {
@@ -3409,7 +3414,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3409
3414
let commitment_txid = commitment_tx. compute_txid ( ) ;
3410
3415
debug_assert_eq ! ( self . funding. current_holder_commitment_tx. txid, commitment_txid) ;
3411
3416
let pending_htlcs = self . funding . current_holder_commitment_tx . non_dust_htlcs ( ) ;
3412
- let commitment_tx_fee_satoshis = self . funding . channel_value_satoshis -
3417
+ let channel_value_satoshis = self . funding . channel_parameters . channel_value_satoshis ;
3418
+ let commitment_tx_fee_satoshis = channel_value_satoshis -
3413
3419
commitment_tx. output . iter ( ) . fold ( 0u64 , |sum, output| sum + output. value . to_sat ( ) ) ;
3414
3420
ret. push ( Event :: BumpTransaction ( BumpTransactionEvent :: ChannelClose {
3415
3421
channel_id,
@@ -3421,7 +3427,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3421
3427
anchor_descriptor : AnchorDescriptor {
3422
3428
channel_derivation_parameters : ChannelDerivationParameters {
3423
3429
keys_id : self . channel_keys_id ,
3424
- value_satoshis : self . funding . channel_value_satoshis ,
3430
+ value_satoshis : channel_value_satoshis,
3425
3431
transaction_parameters : self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ,
3426
3432
} ,
3427
3433
outpoint : BitcoinOutPoint {
@@ -3442,7 +3448,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3442
3448
htlc_descriptors. push ( HTLCDescriptor {
3443
3449
channel_derivation_parameters : ChannelDerivationParameters {
3444
3450
keys_id : self . channel_keys_id ,
3445
- value_satoshis : self . funding . channel_value_satoshis ,
3451
+ value_satoshis : self . funding . channel_parameters . channel_value_satoshis ,
3446
3452
transaction_parameters : self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ,
3447
3453
} ,
3448
3454
commitment_txid : htlc. commitment_txid ,
@@ -4145,7 +4151,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4145
4151
// (except for HTLC transactions for channels with anchor outputs), which is an easy
4146
4152
// way to filter out any potential non-matching txn for lazy filters.
4147
4153
let prevout = & tx. input [ 0 ] . previous_output ;
4148
- if prevout. txid == self . funding . outpoint . txid && prevout. vout == self . funding . outpoint . index as u32 {
4154
+ let funding_outpoint = self . get_funding_txo ( ) ;
4155
+ if prevout. txid == funding_outpoint. txid && prevout. vout == funding_outpoint. index as u32 {
4149
4156
let mut balance_spendable_csv = None ;
4150
4157
log_info ! ( logger, "Channel {} closed by funding output spend in txid {}." ,
4151
4158
& self . channel_id( ) , txid) ;
@@ -4815,7 +4822,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4815
4822
output : outp. clone ( ) ,
4816
4823
revocation_pubkey : broadcasted_holder_revokable_script. 2 ,
4817
4824
channel_keys_id : self . channel_keys_id ,
4818
- channel_value_satoshis : self . funding . channel_value_satoshis ,
4825
+ channel_value_satoshis : self . funding . channel_parameters . channel_value_satoshis ,
4819
4826
channel_transaction_parameters : Some ( self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ) ,
4820
4827
} ) ) ;
4821
4828
}
@@ -4825,7 +4832,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
4825
4832
outpoint : OutPoint { txid : tx. compute_txid ( ) , index : i as u16 } ,
4826
4833
output : outp. clone ( ) ,
4827
4834
channel_keys_id : self . channel_keys_id ,
4828
- channel_value_satoshis : self . funding . channel_value_satoshis ,
4835
+ channel_value_satoshis : self . funding . channel_parameters . channel_value_satoshis ,
4829
4836
channel_transaction_parameters : Some ( self . onchain_tx_handler . channel_transaction_parameters . clone ( ) ) ,
4830
4837
} ) ) ;
4831
4838
}
@@ -5189,12 +5196,13 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5189
5196
To continue, run a v0.1 release, send/route a payment over the channel or close it.", channel_id) ;
5190
5197
}
5191
5198
5199
+ let channel_parameters = onchain_tx_handler. channel_transaction_parameters . clone ( ) ;
5200
+
5192
5201
Ok ( ( best_block. block_hash , ChannelMonitor :: from_impl ( ChannelMonitorImpl {
5193
5202
funding : FundingScope {
5194
- outpoint,
5195
5203
script_pubkey : funding_script,
5196
5204
redeem_script : funding_redeemscript,
5197
- channel_value_satoshis ,
5205
+ channel_parameters ,
5198
5206
5199
5207
current_counterparty_commitment_txid,
5200
5208
prev_counterparty_commitment_txid,
@@ -5487,12 +5495,11 @@ mod tests {
5487
5495
// old state.
5488
5496
let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
5489
5497
let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
5490
- let funding_txo = OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } ;
5491
5498
let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
5492
5499
let monitor = ChannelMonitor :: new (
5493
5500
Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5494
- funding_txo , ScriptBuf :: new ( ) , & channel_parameters , true , ScriptBuf :: new ( ) , 46 , 0 ,
5495
- HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) , best_block, dummy_key, channel_id,
5501
+ & channel_parameters , true , 0 , HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) ,
5502
+ best_block, dummy_key, channel_id,
5496
5503
) ;
5497
5504
5498
5505
let mut htlcs = preimages_slice_to_htlcs ! ( preimages[ 0 ..10 ] ) ;
@@ -5740,12 +5747,11 @@ mod tests {
5740
5747
} ;
5741
5748
let shutdown_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
5742
5749
let shutdown_script = ShutdownScript :: new_p2wpkh_from_pubkey ( shutdown_pubkey) ;
5743
- let funding_txo = OutPoint { txid : Txid :: from_slice ( & [ 43 ; 32 ] ) . unwrap ( ) , index : 0 } ;
5744
5750
let best_block = BestBlock :: from_network ( Network :: Testnet ) ;
5745
5751
let monitor = ChannelMonitor :: new (
5746
5752
Secp256k1 :: new ( ) , keys, Some ( shutdown_script. into_inner ( ) ) , 0 , & ScriptBuf :: new ( ) ,
5747
- funding_txo , ScriptBuf :: new ( ) , & channel_parameters , true , ScriptBuf :: new ( ) , 46 , 0 ,
5748
- HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) , best_block, dummy_key, channel_id,
5753
+ & channel_parameters , true , 0 , HolderCommitmentTransaction :: dummy ( 0 , & mut Vec :: new ( ) ) ,
5754
+ best_block, dummy_key, channel_id,
5749
5755
) ;
5750
5756
5751
5757
let chan_id = monitor. inner . lock ( ) . unwrap ( ) . channel_id ( ) ;
0 commit comments