@@ -691,10 +691,12 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
691
691
return Err ( ChannelError :: Close ( "Insufficient funding amount for initial commitment" . to_owned ( ) ) ) ;
692
692
}
693
693
694
+ let is_outbound = false ;
695
+
694
696
let counterparty_shutdown_scriptpubkey = if their_features. supports_upfront_shutdown_script ( ) {
695
697
match & msg. shutdown_scriptpubkey {
696
698
& OptionalField :: Present ( ref script) => {
697
- if is_unsupported_shutdown_script ( & their_features, script) {
699
+ if is_unsupported_shutdown_script ( & their_features, script, is_outbound ) {
698
700
return Err ( ChannelError :: Close ( format ! ( "Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format. script: ({})" , script. to_bytes( ) . to_hex( ) ) ) ) ;
699
701
}
700
702
@@ -772,7 +774,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
772
774
channel_transaction_parameters : ChannelTransactionParameters {
773
775
holder_pubkeys : pubkeys,
774
776
holder_selected_contest_delay : config. own_channel_config . our_to_self_delay ,
775
- is_outbound_from_holder : false ,
777
+ is_outbound_from_holder : is_outbound ,
776
778
counterparty_parameters : Some ( CounterpartyChannelTransactionParameters {
777
779
selected_contest_delay : msg. to_self_delay ,
778
780
pubkeys : counterparty_pubkeys,
@@ -1390,7 +1392,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
1390
1392
let counterparty_shutdown_scriptpubkey = if their_features. supports_upfront_shutdown_script ( ) {
1391
1393
match & msg. shutdown_scriptpubkey {
1392
1394
& OptionalField :: Present ( ref script) => {
1393
- if is_unsupported_shutdown_script ( & their_features, script) {
1395
+ if is_unsupported_shutdown_script ( & their_features, script, self . is_outbound ( ) ) {
1394
1396
return Err ( ChannelError :: Close ( format ! ( "Peer is signaling upfront_shutdown but has provided a non-accepted scriptpubkey format. script: ({})" , script. to_bytes( ) . to_hex( ) ) ) ) ;
1395
1397
}
1396
1398
@@ -2903,15 +2905,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
2903
2905
}
2904
2906
assert_eq ! ( self . channel_state & ChannelState :: ShutdownComplete as u32 , 0 ) ;
2905
2907
2906
- // BOLT 2 says we must only send a scriptpubkey of certain standard forms,
2907
- // which for a a BIP-141-compliant witness program is at max 42 bytes in length.
2908
- // So don't let the remote peer feed us some super fee-heavy script.
2909
- if self . is_outbound ( ) && msg. scriptpubkey . len ( ) > 42 {
2910
- return Err ( ChannelError :: Close ( format ! ( "Got counterparty shutdown_scriptpubkey ({}) of absurd length from remote peer" , msg. scriptpubkey. to_bytes( ) . to_hex( ) ) ) ) ;
2911
- }
2912
-
2913
- //Check counterparty_shutdown_scriptpubkey form as BOLT says we must
2914
- if is_unsupported_shutdown_script ( & their_features, & msg. scriptpubkey ) {
2908
+ if is_unsupported_shutdown_script ( & their_features, & msg. scriptpubkey , self . is_outbound ( ) ) {
2915
2909
return Err ( ChannelError :: Close ( format ! ( "Got a nonstandard scriptpubkey ({}) from remote peer" , msg. scriptpubkey. to_bytes( ) . to_hex( ) ) ) ) ;
2916
2910
}
2917
2911
@@ -4019,8 +4013,12 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
4019
4013
}
4020
4014
}
4021
4015
4022
- fn is_unsupported_shutdown_script ( their_features : & InitFeatures , scriptpubkey : & Script ) -> bool {
4023
- return is_unsupported_witness_shutdown_script ( their_features, scriptpubkey) && !scriptpubkey. is_p2pkh ( ) && !scriptpubkey. is_p2sh ( ) && !scriptpubkey. is_v0_p2wpkh ( ) && !scriptpubkey. is_v0_p2wsh ( )
4016
+ fn is_unsupported_shutdown_script ( their_features : & InitFeatures , scriptpubkey : & Script , is_outbound : bool ) -> bool {
4017
+ // BOLT 2 says we must only send a scriptpubkey of certain standard forms,
4018
+ // which for a a BIP-141-compliant witness program is at max 42 bytes in length.
4019
+ // So don't let the remote peer feed us some super fee-heavy script.
4020
+ let is_script_too_long = is_outbound && scriptpubkey. len ( ) > 42 ;
4021
+ return is_script_too_long || ( is_unsupported_witness_shutdown_script ( their_features, scriptpubkey) && !scriptpubkey. is_p2pkh ( ) && !scriptpubkey. is_p2sh ( ) && !scriptpubkey. is_v0_p2wpkh ( ) && !scriptpubkey. is_v0_p2wsh ( ) )
4024
4022
}
4025
4023
4026
4024
fn is_unsupported_witness_shutdown_script ( their_features : & InitFeatures , scriptpubkey : & Script ) -> bool {
0 commit comments