Skip to content

Fix bogus Event::PaymentSent serialization #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

Event::PaymentSent serialization has a bug where we
double-serialize the payment_preimage field but do not attempt to
read it twice. This results in a failure to read ChannelManagers
from disk if we have a pending Event::PaymentSent pending
awaiting handling when we serialize.

Instead of attempting to read both versions, we opt to simply fix
the serialization, assuming it is exceedingly rare for such a
scenario to appear (and if it does, we can assist in manual
recovery).

The release notes have been updated to note this inconsistency.

Found by the chanmon_consistency fuzz target.

`Event::PaymentSent` serialization has a bug where we
double-serialize the payment_preimage field but do not attempt to
read it twice. This results in a failure to read `ChannelManager`s
from disk if we have a pending `Event::PaymentSent` pending
awaiting handling when we serialize.

Instead of attempting to read both versions, we opt to simply fix
the serialization, assuming it is exceedingly rare for such a
scenario to appear (and if it does, we can assist in manual
recovery).

The release notes have been updated to note this inconsistency.

Found by the chanmon_consistency fuzz target.
@codecov
Copy link

codecov bot commented Jun 28, 2021

Codecov Report

Merging #973 (dec7ec1) into main (ecddfe1) will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #973      +/-   ##
==========================================
- Coverage   90.65%   90.65%   -0.01%     
==========================================
  Files          60       60              
  Lines       30398    30397       -1     
==========================================
- Hits        27558    27556       -2     
- Misses       2840     2841       +1     
Impacted Files Coverage Δ
lightning/src/util/events.rs 17.42% <ø> (+0.13%) ⬆️
lightning/src/ln/channelmanager.rs 83.85% <0.00%> (-0.05%) ⬇️
lightning/src/ln/functional_tests.rs 97.14% <0.00%> (-0.02%) ⬇️

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 ecddfe1...dec7ec1. Read the comment docs.

@TheBlueMatt TheBlueMatt added this to the 0.0.99 milestone Jun 29, 2021
@@ -160,7 +160,6 @@ impl Writeable for Event {
write_tlv_fields!(writer, {
(0, payment_preimage, required),
});
payment_preimage.write(writer)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Darn! If anyone wants to post-mortem, this seems to be the commit where this occurred: 263bf9e#diff-3b5c370b404e2f5a8f3c35093b97406f149a9340c177c05252574083d68df0daR160-R163 At least serialization was a bit of a one-off big PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, good thing we have fuzzers (when I remember to check their output...).

Copy link

Choose a reason for hiding this comment

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

AFAICT, it was introduced by #935 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I believe so.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Code Review ACK dec7ec1

* Due to a bug discovered in 0.0.98, if a `ChannelManager` is serialized on
version 0.0.98 while an `Event::PaymentSent` is pending processing, the
`ChannelManager` will fail to deserialize both on version 0.0.98 and later
versions. If you have such a `ChannelManager` available, a simple patch will
Copy link

Choose a reason for hiding this comment

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

What would the patch ? Adding back a payment.preimage: Readable::read(reader)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, just reading (and throwing away) an extra 32 bytes.

@@ -160,7 +160,6 @@ impl Writeable for Event {
write_tlv_fields!(writer, {
(0, payment_preimage, required),
});
payment_preimage.write(writer)?;
Copy link

Choose a reason for hiding this comment

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

AFAICT, it was introduced by #935 ?

@TheBlueMatt TheBlueMatt merged commit e75d41b into lightningdevkit:main Jun 30, 2021
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