@@ -522,7 +522,7 @@ impl Channel {
522
522
523
523
/// Creates a new channel from a remote sides' request for one.
524
524
/// Assumes chain_hash has already been checked and corresponds with what we expect!
525
- pub fn new_from_req ( fee_estimator : & FeeEstimator , keys_provider : & Arc < KeysInterface > , their_node_id : PublicKey , _their_local_features : LocalFeatures , msg : & msgs:: OpenChannel , user_id : u64 , logger : Arc < Logger > , config : & UserConfig ) -> Result < Channel , ChannelError > {
525
+ pub fn new_from_req ( fee_estimator : & FeeEstimator , keys_provider : & Arc < KeysInterface > , their_node_id : PublicKey , their_local_features : LocalFeatures , msg : & msgs:: OpenChannel , user_id : u64 , logger : Arc < Logger > , config : & UserConfig ) -> Result < Channel , ChannelError > {
526
526
let chan_keys = keys_provider. get_channel_keys ( true ) ;
527
527
let mut local_config = ( * config) . channel_options . clone ( ) ;
528
528
@@ -625,6 +625,27 @@ impl Channel {
625
625
channel_monitor. set_their_base_keys ( & msg. htlc_basepoint , & msg. delayed_payment_basepoint ) ;
626
626
channel_monitor. set_their_to_self_delay ( msg. to_self_delay ) ;
627
627
628
+ let their_shutdown_scriptpubkey = if their_local_features. supports_upfront_shutdown_script ( ) {
629
+ match & msg. shutdown_scriptpubkey {
630
+ & OptionalField :: Present ( ref script) => {
631
+ // Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. We enforce it while receiving shutdown msg
632
+ if script. is_p2pkh ( ) || script. is_p2sh ( ) || script. is_v0_p2wsh ( ) || script. is_v0_p2wpkh ( ) {
633
+ Some ( script. clone ( ) )
634
+ // Peer is signaling upfront_shutdown and has opt-out with a 0-length script. We don't enforce anything
635
+ } else if script. len ( ) == 0 {
636
+ None
637
+ // Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. Fail the channel
638
+ } else {
639
+ return Err ( ChannelError :: Close ( "Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format" ) ) ;
640
+ }
641
+ } ,
642
+ // Peer is signaling upfront shutdown but don't opt-out with correct mechanism (a.k.a 0-length script). Peer looks buggy, we fail the channel
643
+ & OptionalField :: Absent => {
644
+ return Err ( ChannelError :: Close ( "Peer is signaling upfront_shutdown but we don't get any script. Use 0-length script to opt-out" ) ) ;
645
+ }
646
+ }
647
+ } else { None } ;
648
+
628
649
let mut chan = Channel {
629
650
user_id : user_id,
630
651
config : local_config,
@@ -692,7 +713,7 @@ impl Channel {
692
713
their_prev_commitment_point : None ,
693
714
their_node_id : their_node_id,
694
715
695
- their_shutdown_scriptpubkey : None ,
716
+ their_shutdown_scriptpubkey,
696
717
697
718
channel_monitor : channel_monitor,
698
719
@@ -1341,7 +1362,7 @@ impl Channel {
1341
1362
1342
1363
// Message handlers:
1343
1364
1344
- pub fn accept_channel ( & mut self , msg : & msgs:: AcceptChannel , config : & UserConfig , _their_local_features : LocalFeatures ) -> Result < ( ) , ChannelError > {
1365
+ pub fn accept_channel ( & mut self , msg : & msgs:: AcceptChannel , config : & UserConfig , their_local_features : LocalFeatures ) -> Result < ( ) , ChannelError > {
1345
1366
// Check sanity of message fields:
1346
1367
if !self . channel_outbound {
1347
1368
return Err ( ChannelError :: Close ( "Got an accept_channel message from an inbound peer" ) ) ;
@@ -1400,6 +1421,27 @@ impl Channel {
1400
1421
return Err ( ChannelError :: Close ( "We consider the minimum depth to be unreasonably large" ) ) ;
1401
1422
}
1402
1423
1424
+ let their_shutdown_scriptpubkey = if their_local_features. supports_upfront_shutdown_script ( ) {
1425
+ match & msg. shutdown_scriptpubkey {
1426
+ & OptionalField :: Present ( ref script) => {
1427
+ // Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. We enforce it while receiving shutdown msg
1428
+ if script. is_p2pkh ( ) || script. is_p2sh ( ) || script. is_v0_p2wsh ( ) || script. is_v0_p2wpkh ( ) {
1429
+ Some ( script. clone ( ) )
1430
+ // Peer is signaling upfront_shutdown and has opt-out with a 0-length script. We don't enforce anything
1431
+ } else if script. len ( ) == 0 {
1432
+ None
1433
+ // Peer is signaling upfront_shutdown and has provided a non-accepted scriptpubkey format. Fail the channel
1434
+ } else {
1435
+ return Err ( ChannelError :: Close ( "Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format" ) ) ;
1436
+ }
1437
+ } ,
1438
+ // Peer is signaling upfront shutdown but don't opt-out with correct mechanism (a.k.a 0-length script). Peer looks buggy, we fail the channel
1439
+ & OptionalField :: Absent => {
1440
+ return Err ( ChannelError :: Close ( "Peer is signaling upfront_shutdown but we don't get any script. Use 0-length script to opt-out" ) ) ;
1441
+ }
1442
+ }
1443
+ } else { None } ;
1444
+
1403
1445
self . channel_monitor . set_their_base_keys ( & msg. htlc_basepoint , & msg. delayed_payment_basepoint ) ;
1404
1446
1405
1447
self . their_dust_limit_satoshis = msg. dust_limit_satoshis ;
@@ -1415,6 +1457,7 @@ impl Channel {
1415
1457
self . their_delayed_payment_basepoint = Some ( msg. delayed_payment_basepoint ) ;
1416
1458
self . their_htlc_basepoint = Some ( msg. htlc_basepoint ) ;
1417
1459
self . their_cur_commitment_point = Some ( msg. first_per_commitment_point ) ;
1460
+ self . their_shutdown_scriptpubkey = their_shutdown_scriptpubkey;
1418
1461
1419
1462
let obscure_factor = self . get_commitment_transaction_number_obscure_factor ( ) ;
1420
1463
self . channel_monitor . set_commitment_obscure_factor ( obscure_factor) ;
0 commit comments