@@ -37,8 +37,9 @@ use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
37
37
use crate :: ln:: types:: { PaymentHash , PaymentPreimage , ChannelId } ;
38
38
use crate :: ln:: msgs:: DecodeError ;
39
39
use crate :: ln:: channel_keys:: { DelayedPaymentKey , DelayedPaymentBasepoint , HtlcBasepoint , HtlcKey , RevocationKey , RevocationBasepoint } ;
40
- use crate :: ln:: chan_utils:: { self , CommitmentTransaction , CounterpartyCommitmentSecrets , HTLCOutputInCommitment , HTLCClaim , ChannelTransactionParameters , HolderCommitmentTransaction , TxCreationKeys } ;
41
- use crate :: ln:: channelmanager:: { HTLCSource , SentHTLCId } ;
40
+ use crate :: ln:: chan_utils:: { self , CommitmentTransaction , CounterpartyCommitmentSecrets , HTLCOutputInCommitment , HTLCClaim , ChannelTransactionParameters , HolderCommitmentTransaction , TxCreationKeys , CounterpartyChannelTransactionParameters } ;
41
+ use crate :: ln:: channelmanager:: { HTLCSource , SentHTLCId , StubChannel } ;
42
+ use crate :: ln:: features:: ChannelTypeFeatures ;
42
43
use crate :: chain;
43
44
use crate :: chain:: { BestBlock , WatchedOutput } ;
44
45
use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator , LowerBoundedFeeEstimator } ;
@@ -1346,6 +1347,103 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1346
1347
} )
1347
1348
}
1348
1349
1350
+ pub ( crate ) fn new_stub ( secp_ctx : Secp256k1 < secp256k1:: All > , stub_channel : & StubChannel , best_block : BestBlock , keys : Signer , funding_info_scriptbuf : ScriptBuf ) -> ChannelMonitor < Signer > {
1351
+ let mut outputs_to_watch = new_hash_map ( ) ;
1352
+ outputs_to_watch. insert ( stub_channel. funding_outpoint . get_txid ( ) , vec ! [ ( stub_channel. funding_outpoint. index as u32 , funding_info_scriptbuf. clone( ) ) ] ) ;
1353
+ let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
1354
+ let dummy_sig = crate :: crypto:: utils:: sign ( & secp_ctx, & secp256k1:: Message :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) , & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
1355
+
1356
+ let holder_commitment_tx = HolderSignedTx {
1357
+ txid : stub_channel. funding_outpoint . get_txid ( ) ,
1358
+ revocation_key : RevocationKey ( dummy_key) ,
1359
+ a_htlc_key : HtlcKey ( dummy_key) ,
1360
+ b_htlc_key : HtlcKey ( dummy_key) ,
1361
+ delayed_payment_key : DelayedPaymentKey ( dummy_key) ,
1362
+ per_commitment_point : dummy_key,
1363
+ htlc_outputs : Vec :: new ( ) , // There are never any HTLCs in the initial commitment transactions
1364
+ to_self_value_sat : 0 ,
1365
+ feerate_per_kw : 1 ,
1366
+ } ;
1367
+
1368
+ let channel_parameters = ChannelTransactionParameters {
1369
+ holder_pubkeys : keys. pubkeys ( ) . clone ( ) ,
1370
+ is_outbound_from_holder : true ,
1371
+ holder_selected_contest_delay : 66 ,
1372
+ counterparty_parameters : Some ( CounterpartyChannelTransactionParameters { pubkeys : keys. pubkeys ( ) . clone ( ) , selected_contest_delay : 0 } ) ,
1373
+ funding_outpoint : Some ( stub_channel. funding_outpoint ) ,
1374
+ channel_type_features : ChannelTypeFeatures :: only_static_remote_key ( ) ,
1375
+ } ;
1376
+
1377
+ let dummy_tx_creation_keys = TxCreationKeys {
1378
+ per_commitment_point : dummy_key. clone ( ) ,
1379
+ revocation_key : RevocationKey :: from_basepoint ( & secp_ctx, & RevocationBasepoint :: from ( dummy_key) , & dummy_key) ,
1380
+ broadcaster_htlc_key : HtlcKey :: from_basepoint ( & secp_ctx, & HtlcBasepoint :: from ( dummy_key) , & dummy_key) ,
1381
+ countersignatory_htlc_key : HtlcKey :: from_basepoint ( & secp_ctx, & HtlcBasepoint :: from ( dummy_key) , & dummy_key) ,
1382
+ broadcaster_delayed_payment_key : DelayedPaymentKey :: from_basepoint ( & secp_ctx, & DelayedPaymentBasepoint :: from ( dummy_key) , & dummy_key) ,
1383
+ } ;
1384
+ let counterparty_htlc_sigs = Vec :: new ( ) ;
1385
+ let mut nondust_htlcs: Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > = Vec :: new ( ) ;
1386
+ let inner = CommitmentTransaction :: new_with_auxiliary_htlc_data ( 0 , 0 , 0 , dummy_key. clone ( ) , dummy_key. clone ( ) , dummy_tx_creation_keys, 0 , & mut nondust_htlcs, & channel_parameters. as_counterparty_broadcastable ( ) ) ;
1387
+ let holder_commitment = HolderCommitmentTransaction :: new ( inner, dummy_sig, counterparty_htlc_sigs, & dummy_key, & PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ) ;
1388
+
1389
+ let onchain_tx_handler = OnchainTxHandler :: new (
1390
+ 1000 , stub_channel. channel_keys_id , ScriptBuf :: new ( ) , keys,
1391
+ channel_parameters, holder_commitment, secp_ctx
1392
+ ) ;
1393
+
1394
+ Self :: from_impl ( ChannelMonitorImpl {
1395
+ latest_update_id : CLOSED_CHANNEL_UPDATE_ID ,
1396
+ commitment_transaction_number_obscure_factor : 0 ,
1397
+ destination_script : ScriptBuf :: new ( ) ,
1398
+ broadcasted_holder_revokable_script : None ,
1399
+ counterparty_payment_script : ScriptBuf :: new ( ) ,
1400
+ shutdown_script : None ,
1401
+ channel_keys_id : stub_channel. channel_keys_id ,
1402
+ holder_revocation_basepoint : RevocationBasepoint ( PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ) ,
1403
+ channel_id : stub_channel. channel_id ,
1404
+ funding_info : ( stub_channel. funding_outpoint , ScriptBuf :: new ( ) ) ,
1405
+ current_counterparty_commitment_txid : None ,
1406
+ prev_counterparty_commitment_txid : None ,
1407
+ counterparty_commitment_params : CounterpartyCommitmentParameters {
1408
+ counterparty_delayed_payment_base_key : DelayedPaymentBasepoint ( PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ) ,
1409
+ counterparty_htlc_base_key : HtlcBasepoint ( PublicKey :: from_slice ( & [ 2 ; 33 ] ) . unwrap ( ) ) ,
1410
+ on_counterparty_tx_csv : 0 ,
1411
+ } ,
1412
+ funding_redeemscript : ScriptBuf :: new ( ) ,
1413
+ channel_value_satoshis : 0 ,
1414
+ their_cur_per_commitment_points : None ,
1415
+ on_holder_tx_csv : 1 ,
1416
+ commitment_secrets : stub_channel. commitment_secrets . clone ( ) ,
1417
+ counterparty_claimable_outpoints : new_hash_map ( ) ,
1418
+ counterparty_hash_commitment_number : new_hash_map ( ) ,
1419
+ counterparty_commitment_txn_on_chain : new_hash_map ( ) ,
1420
+ counterparty_fulfilled_htlcs : new_hash_map ( ) ,
1421
+ prev_holder_signed_commitment_tx : None ,
1422
+ current_holder_commitment_tx : holder_commitment_tx,
1423
+ current_counterparty_commitment_number : 1 << 48 ,
1424
+ current_holder_commitment_number : 1 ,
1425
+ payment_preimages : new_hash_map ( ) ,
1426
+ peer_storage : Vec :: new ( ) ,
1427
+ pending_monitor_events : Vec :: new ( ) ,
1428
+ pending_events : Vec :: new ( ) ,
1429
+ is_processing_pending_events : false ,
1430
+ onchain_events_awaiting_threshold_conf : Vec :: new ( ) ,
1431
+ outputs_to_watch,
1432
+ onchain_tx_handler,
1433
+ lockdown_from_offchain : true ,
1434
+ holder_tx_signed : true ,
1435
+ funding_spend_seen : false ,
1436
+ funding_spend_confirmed : None ,
1437
+ confirmed_commitment_tx_counterparty_output : None ,
1438
+ htlcs_resolved_on_chain : Vec :: new ( ) ,
1439
+ spendable_txids_confirmed : Vec :: new ( ) ,
1440
+ best_block,
1441
+ counterparty_node_id : Some ( stub_channel. counterparty_node_id ) ,
1442
+ initial_counterparty_commitment_info : None ,
1443
+ balances_empty_height : None
1444
+ } )
1445
+ }
1446
+
1349
1447
#[ cfg( test) ]
1350
1448
fn provide_secret ( & self , idx : u64 , secret : [ u8 ; 32 ] ) -> Result < ( ) , & ' static str > {
1351
1449
self . inner . lock ( ) . unwrap ( ) . provide_secret ( idx, secret)
@@ -2833,6 +2931,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2833
2931
2834
2932
fn update_peer_storage ( & mut self , new_data : Vec < u8 > ) {
2835
2933
self . peer_storage = new_data;
2934
+ return ;
2836
2935
}
2837
2936
2838
2937
fn generate_claimable_outpoints_and_watch_outputs ( & mut self , reason : ClosureReason ) -> ( Vec < PackageTemplate > , Vec < TransactionOutputs > ) {
@@ -3012,7 +3111,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3012
3111
} ,
3013
3112
ChannelMonitorUpdateStep :: LatestPeerStorage { data } => {
3014
3113
log_trace ! ( logger, "Updating ChannelMonitor with latest recieved PeerStorage" ) ;
3015
- self . update_peer_storage ( data. clone ( ) ) ;
3114
+ self . update_peer_storage ( data. clone ( ) )
3016
3115
}
3017
3116
}
3018
3117
}
0 commit comments