Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Wire shutdown#185

Merged
bmancini55 merged 9 commits intonode-lightning:mainfrom
Vib-UX:wire_shutdown
Aug 4, 2021
Merged

Wire shutdown#185
bmancini55 merged 9 commits intonode-lightning:mainfrom
Vib-UX:wire_shutdown

Conversation

@Vib-UX
Copy link
Contributor

@Vib-UX Vib-UX commented Jul 31, 2021

wire: create shutdown message type #179

BOLT #2

  • Parameters are defined according to shutdown in BOLT #2
  • Implementation is as per the standards given
  • UT is work in progress

@codecov-commenter
Copy link

codecov-commenter commented Jul 31, 2021

Codecov Report

Merging #185 (f8c76cb) into main (a95e7d5) will increase coverage by 0.00%.
The diff coverage is 95.45%.

❗ Current head f8c76cb differs from pull request most recent head dd83c8a. Consider uploading reports for the commit dd83c8a to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main     #185   +/-   ##
=======================================
  Coverage   93.70%   93.71%           
=======================================
  Files         178      179    +1     
  Lines        4672     4693   +21     
  Branches      547      547           
=======================================
+ Hits         4378     4398   +20     
- Misses        162      163    +1     
  Partials      132      132           
Impacted Files Coverage Δ
packages/wire/lib/MessageFactory.ts 68.57% <50.00%> (-1.13%) ⬇️
packages/wire/lib/MessageType.ts 100.00% <100.00%> (ø)
packages/wire/lib/messages/ShutdownMessage.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a95e7d5...dd83c8a. Read the comment docs.

Copy link
Member

@bmancini55 bmancini55 left a comment

Choose a reason for hiding this comment

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

Looking good, couple comment changes and you'll need to fix the de/ser methods to properly handle the scriptPubKey len.


/**
* ShutdownMessage represents the `shutdown` message defined in
* BOLT #2 of the Lightning Specification. This message can be sent by the
Copy link
Member

Choose a reason for hiding this comment

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

s/sent by either/sent by the either/

/**
* ShutdownMessage represents the `shutdown` message defined in
* BOLT #2 of the Lightning Specification. This message can be sent by the
* either node. The scriptPubKey must follow the standards which are accepted
Copy link
Member

Choose a reason for hiding this comment

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

The scriptPubKey has stricter requirements than this. Must be a valid P2WPKH, P2WSH, P2SH-P2WPKH, P2SH-P2WSH, or any valid witness script if option_shutdown_anysegwit is negotiated.

Also may want to make a note that this scriptPubKey must be the same as the shutdown_scriptpubkey value if it was sent during channel open/accept.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1st remark comment added, For 2nd I have updated the scriptPubKey in test file!

* by Bitcoin network that ensures the resulting transaction will propagate
* to miners. If shutdown is sent by either node , corresponding node should send
* commitment_signed to commit any outstanding changes before replying shutdown. Once
* shutdown is sent by both nodes no new HTLCs should be added or accepted by the channel.
Copy link
Member

Choose a reason for hiding this comment

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

Add one more note that after this, fee negotiation and signature sending can begin with closing_signed

const writer = new BufferWriter();
writer.writeUInt16BE(this.type);
writer.writeBytes(this.channelId.toBuffer());
writer.writeBytes(this.len);
Copy link
Member

Choose a reason for hiding this comment

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

Length should be a u16be


reader.readUInt16BE(); // read type
instance.channelId = new ChannelId(reader.readBytes(32));
instance.len = reader.readBytes(16);
Copy link
Member

Choose a reason for hiding this comment

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

Len should be a uint16be and used as input when reading the scriptPubKey bytes

@Vib-UX Vib-UX requested a review from bmancini55 August 3, 2021 18:19
Copy link
Member

@bmancini55 bmancini55 left a comment

Choose a reason for hiding this comment

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

Comments are looking good. Just need to add some info to the scriptPubKey property.

Biggest issue is we can get rid of the len property on the class. The length is implicit in the scriptPubKey buffer. During serialization you can just use the length property of the Buffer. For deserialization, you can read len into a temp variable and then call readBytes with len to read the scriptPubKey buffer.


reader.readUInt16BE(); // read type
instance.channelId = new ChannelId(reader.readBytes(32));
instance.len = reader.readUInt16BE();
Copy link
Member

Choose a reason for hiding this comment

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

Just read this into a temp variable instead of a class property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yep!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it! Thanks for being patient with me!.🙇

Copy link
Member

Choose a reason for hiding this comment

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

No worries at all, you're doing great!

*/
public channelId: ChannelId;

public len: number;
Copy link
Member

Choose a reason for hiding this comment

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

Don't need a class property. The value is implicit in the scriptPubKey buffer.

const writer = new BufferWriter();
writer.writeUInt16BE(this.type);
writer.writeBytes(this.channelId.toBuffer());
writer.writeUInt16BE(this.len);
Copy link
Member

Choose a reason for hiding this comment

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

Use the length of scriptPubKey

* outstanding changes before replying shutdown. Once shutdown is sent by both nodes no new HTLCs should be added or accepted by the channel.
* After successful handshake of shutdown message, fee negotiation and signature sending can begin with `closing_signed` message.
*/

Copy link
Member

Choose a reason for hiding this comment

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

nit: remove newline between comment block and class and watch comment line length.


public len: number;
/**
* scriptPubKey is used by the sender to get paid.
Copy link
Member

Choose a reason for hiding this comment

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

Beef up the comment on what this value should or move comment from class to here. Either is fine.

@Vib-UX Vib-UX requested a review from bmancini55 August 4, 2021 14:05
Copy link
Member

@bmancini55 bmancini55 left a comment

Choose a reason for hiding this comment

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

Awesome, looks great! Thanks!

@bmancini55 bmancini55 marked this pull request as ready for review August 4, 2021 16:10
@bmancini55 bmancini55 merged commit de8afec into node-lightning:main Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants