Skip to content

UpfrontShutdownScript field#1290

Merged
t-bast merged 3 commits into
masterfrom
open-channel-tlv
Jan 29, 2020
Merged

UpfrontShutdownScript field#1290
t-bast merged 3 commits into
masterfrom
open-channel-tlv

Conversation

@t-bast
Copy link
Copy Markdown
Member

@t-bast t-bast commented Jan 23, 2020

We don't implement the upfront_shutdown_script feature yet.
However we update our encoding to always specify its field and support reading it.
This allows extending OpenChannel/AcceptChannel with tlv streams while staying compliant with the spec and other implementations (lnd just started to add the upfront_shutdown_script field to their OpenChannel message, even if we don't activate the feature bit).

There is one caveat: Phoenix shipped with a version that's incompatible because it interprets the upfront_shutdown_script fields as a TLV stream.
So we use a workaround to identify unpatched Phoenix versions and send them the old encoding.
This PR can be applied and deployed safely today.
Once Phoenix is upgraded with that code in the next release, and enough users have updated, we can remove that ugly switch and forget this ever happened :).

Tested against:

  • Eclair 0.3.2: ok
  • C-lightning master: ok
  • lnd 0.9.0-beta: ok

TODO:

  • Create an issue to remind ourselves to remove that code once Phoenix is updated

We don't implement the upfront_shutdown_script feature.
However we update our encoding to always specify it.
This allows extending OpenChannel/AcceptChannel with tlv streams.

There is one caveat: Phoenix shipped with a version that's incompatible.
So we use a workaround to identify unpatched Phoenix versions
and send them the old encoding.
@t-bast t-bast requested review from pm47 and sstone January 23, 2020 18:13
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 23, 2020

Codecov Report

Merging #1290 into master will increase coverage by 1.96%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1290      +/-   ##
==========================================
+ Coverage   77.18%   79.15%   +1.96%     
==========================================
  Files         143      144       +1     
  Lines        9976    11022    +1046     
  Branches      408      472      +64     
==========================================
+ Hits         7700     8724    +1024     
- Misses       2276     2298      +22
Impacted Files Coverage Δ
...a/fr/acinq/eclair/wire/LightningMessageTypes.scala 86.36% <ø> (ø) ⬆️
.../fr/acinq/eclair/wire/LightningMessageCodecs.scala 100% <100%> (ø) ⬆️
.../src/main/scala/fr/acinq/eclair/wire/OpenTlv.scala 100% <100%> (ø)
...ir-core/src/main/scala/fr/acinq/eclair/Setup.scala 72.76% <0%> (-0.95%) ⬇️
...q/eclair/blockchain/electrum/ElectrumWatcher.scala 50.42% <0%> (-0.86%) ⬇️
...r/acinq/eclair/payment/send/PaymentLifecycle.scala 91.97% <0%> (-0.83%) ⬇️
...scala/fr/acinq/eclair/payment/PaymentRequest.scala 91.79% <0%> (-0.76%) ⬇️
...clair/payment/send/MultiPartPaymentLifecycle.scala 97.65% <0%> (-0.57%) ⬇️
.../eclair/payment/relay/PostRestartHtlcCleaner.scala 90.06% <0%> (-0.57%) ⬇️
...core/src/main/scala/fr/acinq/eclair/Features.scala 100% <0%> (ø) ⬆️
... and 16 more

Remove the hack inside the metered codec.
We can actually encode this logic directly in the openChannel codec.
Comment thread eclair-core/src/main/scala/fr/acinq/eclair/wire/OpenTlv.scala Outdated
// Bolt 2 specifies that upfront_shutdown_scripts must be P2PKH/P2SH or segwit-v0 P2WPK/P2WSH.
// The length of such scripts will always start with 0x00, so we use that to discriminate whether we're decoding an
// upfront_shutdown_script or a tlv stream.
(b: BitVector) => Attempt.successful(DecodeResult(b.nonEmpty && b.startsWith(hex"00".bits), b))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something more explicit:

    // Bolt 2 specifies that upfront_shutdown_scripts must be P2PKH/P2SH or segwit-v0 P2WPK/P2WSH.
    // Those have predictable lengths, which we use to discriminate whether we're decoding an
    // upfront_shutdown_script or a tlv stream.
    (b: BitVector) => Attempt.successful(DecodeResult(b.startsWith(hex"0016".bits) || b.startsWith(hex"0017".bits) || b.startsWith(hex"0019".bits) || b.startsWith(hex"0022".bits), b))

* Clarify comment
* Use TLV type in custom range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants