@@ -34,11 +34,12 @@ use bitcoin::secp256k1;
34
34
use bitcoin:: sighash:: EcdsaSighashType ;
35
35
36
36
use crate :: ln:: channel:: INITIAL_COMMITMENT_NUMBER ;
37
+ use crate :: ln:: features:: Features ;
37
38
use crate :: ln:: { PaymentHash , PaymentPreimage , ChannelId } ;
38
39
use crate :: ln:: msgs:: DecodeError ;
39
40
use crate :: ln:: channel_keys:: { DelayedPaymentKey , DelayedPaymentBasepoint , HtlcBasepoint , HtlcKey , RevocationKey , RevocationBasepoint } ;
40
41
use crate :: ln:: chan_utils:: { self , CommitmentTransaction , CounterpartyCommitmentSecrets , HTLCOutputInCommitment , HTLCClaim , ChannelTransactionParameters , HolderCommitmentTransaction , TxCreationKeys } ;
41
- use crate :: ln:: channelmanager:: { HTLCSource , SentHTLCId } ;
42
+ use crate :: ln:: channelmanager:: { HTLCSource , SentHTLCId , StubChannel } ;
42
43
use crate :: chain;
43
44
use crate :: chain:: { BestBlock , WatchedOutput } ;
44
45
use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator , LowerBoundedFeeEstimator } ;
@@ -1340,6 +1341,102 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1340
1341
} )
1341
1342
}
1342
1343
1344
+ pub ( crate ) fn new_stub ( secp_ctx : Secp256k1 < secp256k1:: All > , stub_channel : & StubChannel , best_block : BestBlock , keys : Signer ) -> ChannelMonitor < Signer > {
1345
+ let mut outputs_to_watch = new_hash_map ( ) ;
1346
+ outputs_to_watch. insert ( stub_channel. funding_outpoint . get_txid ( ) , vec ! [ ( stub_channel. funding_outpoint. index as u32 , ScriptBuf :: new( ) ) ] ) ;
1347
+ let dummy_key = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
1348
+ let dummy_sig = crate :: crypto:: utils:: sign ( & secp_ctx, & secp256k1:: Message :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) , & SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ) ;
1349
+
1350
+ let holder_commitment_tx = HolderSignedTx {
1351
+ txid : stub_channel. funding_outpoint . get_txid ( ) ,
1352
+ revocation_key : RevocationKey ( PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ,
1353
+ a_htlc_key : HtlcKey ( PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ,
1354
+ b_htlc_key : HtlcKey ( PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ,
1355
+ delayed_payment_key : DelayedPaymentKey ( PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ,
1356
+ per_commitment_point : PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ,
1357
+ htlc_outputs : Vec :: new ( ) , // There are never any HTLCs in the initial commitment transactions
1358
+ to_self_value_sat : 0 ,
1359
+ feerate_per_kw : 1 ,
1360
+ } ;
1361
+
1362
+ let channel_parameters = ChannelTransactionParameters {
1363
+ holder_pubkeys : keys. pubkeys ( ) . clone ( ) ,
1364
+ is_outbound_from_holder : true ,
1365
+ holder_selected_contest_delay : 66 ,
1366
+ counterparty_parameters : None ,
1367
+ funding_outpoint : Some ( stub_channel. funding_outpoint ) ,
1368
+ channel_type_features : Features :: only_static_remote_key ( ) ,
1369
+ } ;
1370
+
1371
+ let dummy_tx_creation_keys = TxCreationKeys {
1372
+ per_commitment_point : dummy_key. clone ( ) ,
1373
+ revocation_key : RevocationKey :: from_basepoint ( & secp_ctx, & RevocationBasepoint :: from ( dummy_key) , & dummy_key) ,
1374
+ broadcaster_htlc_key : HtlcKey :: from_basepoint ( & secp_ctx, & HtlcBasepoint :: from ( dummy_key) , & dummy_key) ,
1375
+ countersignatory_htlc_key : HtlcKey :: from_basepoint ( & secp_ctx, & HtlcBasepoint :: from ( dummy_key) , & dummy_key) ,
1376
+ broadcaster_delayed_payment_key : DelayedPaymentKey :: from_basepoint ( & secp_ctx, & DelayedPaymentBasepoint :: from ( dummy_key) , & dummy_key) ,
1377
+ } ;
1378
+ let mut counterparty_htlc_sigs = Vec :: new ( ) ;
1379
+ let mut nondust_htlcs: Vec < ( HTLCOutputInCommitment , Option < Box < HTLCSource > > ) > = Vec :: new ( ) ;
1380
+ 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 ( ) ) ;
1381
+ let holder_commitment = HolderCommitmentTransaction :: new ( inner, dummy_sig, counterparty_htlc_sigs, & dummy_key, & PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ;
1382
+
1383
+ let onchain_tx_handler = OnchainTxHandler :: new (
1384
+ 1000 , stub_channel. channel_keys_id , ScriptBuf :: new ( ) , keys,
1385
+ channel_parameters, holder_commitment, secp_ctx
1386
+ ) ;
1387
+
1388
+ Self :: from_impl ( ChannelMonitorImpl {
1389
+ latest_update_id : 0 ,
1390
+ commitment_transaction_number_obscure_factor : core:: u64:: MAX ,
1391
+ destination_script : ScriptBuf :: new ( ) ,
1392
+ broadcasted_holder_revokable_script : None ,
1393
+ counterparty_payment_script : ScriptBuf :: new ( ) ,
1394
+ shutdown_script : None ,
1395
+ channel_keys_id : stub_channel. channel_keys_id ,
1396
+ holder_revocation_basepoint : RevocationBasepoint ( PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ,
1397
+ channel_id : stub_channel. channel_id ,
1398
+ funding_info : ( stub_channel. funding_outpoint , ScriptBuf :: new ( ) ) ,
1399
+ current_counterparty_commitment_txid : None ,
1400
+ prev_counterparty_commitment_txid : None ,
1401
+ counterparty_commitment_params : CounterpartyCommitmentParameters {
1402
+ counterparty_delayed_payment_base_key : DelayedPaymentBasepoint ( PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ,
1403
+ counterparty_htlc_base_key : HtlcBasepoint ( PublicKey :: from_slice ( & [ 0 ; 32 ] ) . unwrap ( ) ) ,
1404
+ on_counterparty_tx_csv : 0 ,
1405
+ } ,
1406
+ funding_redeemscript : ScriptBuf :: new ( ) ,
1407
+ channel_value_satoshis : 0 ,
1408
+ their_cur_per_commitment_points : None ,
1409
+ on_holder_tx_csv : 1 ,
1410
+ commitment_secrets : stub_channel. commitment_secrets . clone ( ) ,
1411
+ counterparty_claimable_outpoints : new_hash_map ( ) ,
1412
+ counterparty_hash_commitment_number : new_hash_map ( ) ,
1413
+ counterparty_commitment_txn_on_chain : new_hash_map ( ) ,
1414
+ counterparty_fulfilled_htlcs : new_hash_map ( ) ,
1415
+ prev_holder_signed_commitment_tx : None ,
1416
+ current_holder_commitment_tx : holder_commitment_tx,
1417
+ current_counterparty_commitment_number : 1 << 48 ,
1418
+ current_holder_commitment_number : 1 ,
1419
+ payment_preimages : new_hash_map ( ) ,
1420
+ peer_storage : Vec :: new ( ) ,
1421
+ pending_monitor_events : Vec :: new ( ) ,
1422
+ pending_events : Vec :: new ( ) ,
1423
+ is_processing_pending_events : false ,
1424
+ onchain_events_awaiting_threshold_conf : Vec :: new ( ) ,
1425
+ outputs_to_watch,
1426
+ onchain_tx_handler,
1427
+ lockdown_from_offchain : false ,
1428
+ holder_tx_signed : false ,
1429
+ funding_spend_seen : false ,
1430
+ funding_spend_confirmed : None ,
1431
+ confirmed_commitment_tx_counterparty_output : None ,
1432
+ htlcs_resolved_on_chain : Vec :: new ( ) ,
1433
+ spendable_txids_confirmed : Vec :: new ( ) ,
1434
+ best_block,
1435
+ counterparty_node_id : Some ( stub_channel. counterparty_node_id ) ,
1436
+ initial_counterparty_commitment_info : None ,
1437
+ } )
1438
+ }
1439
+
1343
1440
#[ cfg( test) ]
1344
1441
fn provide_secret ( & self , idx : u64 , secret : [ u8 ; 32 ] ) -> Result < ( ) , & ' static str > {
1345
1442
self . inner . lock ( ) . unwrap ( ) . provide_secret ( idx, secret)
0 commit comments