@@ -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 )
@@ -626,13 +627,14 @@ object Helpers {
626627
627628 object MutualClose {
628629
629- def isValidFinalScriptPubkey (scriptPubKey : ByteVector , allowAnySegwit : Boolean ): Boolean = {
630+ def isValidFinalScriptPubkey (scriptPubKey : ByteVector , allowAnySegwit : Boolean , allowOpReturn : Boolean ): Boolean = {
630631 Try (Script .parse(scriptPubKey)) match {
631632 case Success (OP_DUP :: OP_HASH160 :: OP_PUSHDATA (pubkeyHash, _) :: OP_EQUALVERIFY :: OP_CHECKSIG :: Nil ) if pubkeyHash.size == 20 => true
632633 case Success (OP_HASH160 :: OP_PUSHDATA (scriptHash, _) :: OP_EQUAL :: Nil ) if scriptHash.size == 20 => true
633634 case Success (OP_0 :: OP_PUSHDATA (pubkeyHash, _) :: Nil ) if pubkeyHash.size == 20 => true
634635 case Success (OP_0 :: OP_PUSHDATA (scriptHash, _) :: Nil ) if scriptHash.size == 32 => true
635636 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
637+ case Success (OP_RETURN :: _) if allowOpReturn => true
636638 case _ => false
637639 }
638640 }
@@ -699,16 +701,7 @@ object Helpers {
699701 * The various dust limits are detailed in https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#dust-limits
700702 */
701703 def checkClosingDustAmounts (closingTx : ClosingTx ): Boolean = {
702- closingTx.tx.txOut.forall(txOut => {
703- Try (Script .parse(txOut.publicKeyScript)) match {
704- case Success (OP_DUP :: OP_HASH160 :: OP_PUSHDATA (pubkeyHash, _) :: OP_EQUALVERIFY :: OP_CHECKSIG :: Nil ) if pubkeyHash.size == 20 => txOut.amount >= 546 .sat
705- case Success (OP_HASH160 :: OP_PUSHDATA (scriptHash, _) :: OP_EQUAL :: Nil ) if scriptHash.size == 20 => txOut.amount >= 540 .sat
706- case Success (OP_0 :: OP_PUSHDATA (pubkeyHash, _) :: Nil ) if pubkeyHash.size == 20 => txOut.amount >= 294 .sat
707- case Success (OP_0 :: OP_PUSHDATA (scriptHash, _) :: Nil ) if scriptHash.size == 32 => txOut.amount >= 330 .sat
708- 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
709- case _ => txOut.amount >= 546 .sat
710- }
711- })
704+ closingTx.tx.txOut.forall(txOut => txOut.amount >= Transactions .dustLimit(txOut.publicKeyScript))
712705 }
713706 }
714707
0 commit comments