implement option_shutdown_anysegwit
https://github.com/lightningnetwork/lightning-rfc/pull/672 We check the received shutdown script against higher segwit versions and accept closing to that script if option_shutdown_anysegwit has been negotiated.
This commit is contained in:
@@ -495,6 +495,9 @@ class Peer(Logger):
|
||||
self.lnworker.peer_closed(self)
|
||||
self.got_disconnected.set()
|
||||
|
||||
def is_shutdown_anysegwit(self):
|
||||
return self.features.supports(LnFeatures.OPTION_SHUTDOWN_ANYSEGWIT_OPT)
|
||||
|
||||
def is_static_remotekey(self):
|
||||
return self.features.supports(LnFeatures.OPTION_STATIC_REMOTEKEY_OPT)
|
||||
|
||||
@@ -1692,11 +1695,20 @@ class Peer(Logger):
|
||||
if their_upfront_scriptpubkey:
|
||||
if not (their_scriptpubkey == their_upfront_scriptpubkey):
|
||||
raise UpfrontShutdownScriptViolation("remote didn't use upfront shutdown script it commited to in channel opening")
|
||||
# BOLT-02 restrict the scriptpubkey to some templates:
|
||||
if not (match_script_against_template(their_scriptpubkey, transaction.SCRIPTPUBKEY_TEMPLATE_WITNESS_V0)
|
||||
or match_script_against_template(their_scriptpubkey, transaction.SCRIPTPUBKEY_TEMPLATE_P2SH)
|
||||
or match_script_against_template(their_scriptpubkey, transaction.SCRIPTPUBKEY_TEMPLATE_P2PKH)):
|
||||
raise Exception(f'scriptpubkey in received shutdown message does not conform to any template: {their_scriptpubkey.hex()}')
|
||||
else:
|
||||
# BOLT-02 restrict the scriptpubkey to some templates:
|
||||
# order by decreasing dust limit
|
||||
if match_script_against_template(their_scriptpubkey, transaction.SCRIPTPUBKEY_TEMPLATE_P2PKH):
|
||||
pass
|
||||
elif match_script_against_template(their_scriptpubkey, transaction.SCRIPTPUBKEY_TEMPLATE_P2SH):
|
||||
pass
|
||||
elif self.is_shutdown_anysegwit() and match_script_against_template(their_scriptpubkey, transaction.SCRIPTPUBKEY_TEMPLATE_ANYSEGWIT):
|
||||
pass
|
||||
elif match_script_against_template(their_scriptpubkey, transaction.SCRIPTPUBKEY_TEMPLATE_WITNESS_V0):
|
||||
pass
|
||||
else:
|
||||
raise Exception(f'scriptpubkey in received shutdown message does not conform to any template: {their_scriptpubkey.hex()}')
|
||||
|
||||
chan_id = chan.channel_id
|
||||
if chan_id in self.shutdown_received:
|
||||
self.shutdown_received[chan_id].set_result(payload)
|
||||
|
||||
Reference in New Issue
Block a user