@@ -67,14 +67,15 @@ object Helpers {
6767 private def extractShutdownScript (channelId : ByteVector32 , localFeatures : Features [InitFeature ], remoteFeatures : Features [InitFeature ], upfrontShutdownScript_opt : Option [ByteVector ]): Either [ChannelException , Option [ByteVector ]] = {
6868 val canUseUpfrontShutdownScript = Features .canUseFeature(localFeatures, remoteFeatures, Features .UpfrontShutdownScript )
6969 val canUseAnySegwit = Features .canUseFeature(localFeatures, remoteFeatures, Features .ShutdownAnySegwit )
70- extractShutdownScript(channelId, canUseUpfrontShutdownScript, canUseAnySegwit, upfrontShutdownScript_opt)
70+ val canUseOpReturn = Features .canUseFeature(localFeatures, remoteFeatures, Features .SimpleClose )
71+ extractShutdownScript(channelId, canUseUpfrontShutdownScript, canUseAnySegwit, canUseOpReturn, upfrontShutdownScript_opt)
7172 }
7273
73- private def extractShutdownScript (channelId : ByteVector32 , hasOptionUpfrontShutdownScript : Boolean , allowAnySegwit : Boolean , upfrontShutdownScript_opt : Option [ByteVector ]): Either [ChannelException , Option [ByteVector ]] = {
74+ private def extractShutdownScript (channelId : ByteVector32 , hasOptionUpfrontShutdownScript : Boolean , allowAnySegwit : Boolean , allowOpReturn : Boolean , upfrontShutdownScript_opt : Option [ByteVector ]): Either [ChannelException , Option [ByteVector ]] = {
7475 (hasOptionUpfrontShutdownScript, upfrontShutdownScript_opt) match {
7576 case (true , None ) => Left (MissingUpfrontShutdownScript (channelId))
7677 case (true , Some (script)) if script.isEmpty => Right (None ) // but the provided script can be empty
77- case (true , Some (script)) if ! Closing .MutualClose .isValidFinalScriptPubkey(script, allowAnySegwit) => Left (InvalidFinalScript (channelId))
78+ case (true , Some (script)) if ! Closing .MutualClose .isValidFinalScriptPubkey(script, allowAnySegwit, allowOpReturn ) => Left (InvalidFinalScript (channelId))
7879 case (true , Some (script)) => Right (Some (script))
7980 case (false , Some (_)) => Right (None ) // they provided a script but the feature is not active, we just ignore it
8081 case _ => Right (None )
@@ -644,13 +645,14 @@ object Helpers {
644645
645646 object MutualClose {
646647
647- def isValidFinalScriptPubkey (scriptPubKey : ByteVector , allowAnySegwit : Boolean ): Boolean = {
648+ def isValidFinalScriptPubkey (scriptPubKey : ByteVector , allowAnySegwit : Boolean , allowOpReturn : Boolean ): Boolean = {
648649 Try (Script .parse(scriptPubKey)) match {
649650 case Success (OP_DUP :: OP_HASH160 :: OP_PUSHDATA (pubkeyHash, _) :: OP_EQUALVERIFY :: OP_CHECKSIG :: Nil ) if pubkeyHash.size == 20 => true
650651 case Success (OP_HASH160 :: OP_PUSHDATA (scriptHash, _) :: OP_EQUAL :: Nil ) if scriptHash.size == 20 => true
651652 case Success (OP_0 :: OP_PUSHDATA (pubkeyHash, _) :: Nil ) if pubkeyHash.size == 20 => true
652653 case Success (OP_0 :: OP_PUSHDATA (scriptHash, _) :: Nil ) if scriptHash.size == 32 => true
653654 case Success ((OP_1 | OP_2 | OP_3 | OP_4 | OP_5 | OP_6 | OP_7 | OP_8 | OP_9 | OP_10 | OP_11 | OP_12 | OP_13 | OP_14 | OP_15 | OP_16 ) :: OP_PUSHDATA (program, _) :: Nil ) if allowAnySegwit && 2 <= program.length && program.length <= 40 => true
655+ case Success (OP_RETURN :: _) if allowOpReturn => true
654656 case _ => false
655657 }
656658 }
@@ -717,16 +719,7 @@ object Helpers {
717719 * The various dust limits are detailed in https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#dust-limits
718720 */
719721 def checkClosingDustAmounts (closingTx : ClosingTx ): Boolean = {
720- closingTx.tx.txOut.forall(txOut => {
721- Try (Script .parse(txOut.publicKeyScript)) match {
722- case Success (OP_DUP :: OP_HASH160 :: OP_PUSHDATA (pubkeyHash, _) :: OP_EQUALVERIFY :: OP_CHECKSIG :: Nil ) if pubkeyHash.size == 20 => txOut.amount >= 546 .sat
723- case Success (OP_HASH160 :: OP_PUSHDATA (scriptHash, _) :: OP_EQUAL :: Nil ) if scriptHash.size == 20 => txOut.amount >= 540 .sat
724- case Success (OP_0 :: OP_PUSHDATA (pubkeyHash, _) :: Nil ) if pubkeyHash.size == 20 => txOut.amount >= 294 .sat
725- case Success (OP_0 :: OP_PUSHDATA (scriptHash, _) :: Nil ) if scriptHash.size == 32 => txOut.amount >= 330 .sat
726- case Success ((OP_1 | OP_2 | OP_3 | OP_4 | OP_5 | OP_6 | OP_7 | OP_8 | OP_9 | OP_10 | OP_11 | OP_12 | OP_13 | OP_14 | OP_15 | OP_16 ) :: OP_PUSHDATA (program, _) :: Nil ) if 2 <= program.length && program.length <= 40 => txOut.amount >= 354 .sat
727- case _ => txOut.amount >= 546 .sat
728- }
729- })
722+ closingTx.tx.txOut.forall(txOut => txOut.amount >= Transactions .dustLimit(txOut.publicKeyScript))
730723 }
731724 }
732725
0 commit comments