-
Notifications
You must be signed in to change notification settings - Fork 411
Provide payment preimages to signer on HTLC success #1251
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
Provide payment preimages to signer on HTLC success #1251
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from one trivial MSRV violation, this basically LGTM - do you want to land this as-is or do you want to do the signer changes in the same pr (fine with me either way)
732e196
to
6c4cf86
Compare
Codecov Report
@@ Coverage Diff @@
## main #1251 +/- ##
==========================================
- Coverage 90.38% 90.38% -0.01%
==========================================
Files 71 70 -1
Lines 38135 38165 +30
==========================================
+ Hits 34470 34495 +25
- Misses 3665 3670 +5
Continue to review full report at Codecov.
|
I added the signer changes, they were not complex |
6c4cf86
to
ade4454
Compare
Just to make sure - it looks to me that the lifetime of |
That is correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically LGTM, docs could be clearer, though.
let preimage_opt = match htlc.state { | ||
OutboundHTLCState::RemoteRemoved(OutboundHTLCOutcome::Success(p)) => p, | ||
OutboundHTLCState::AwaitingRemoteRevokeToRemove(OutboundHTLCOutcome::Success(p)) => p, | ||
OutboundHTLCState::AwaitingRemovedRemoteRevoke(OutboundHTLCOutcome::Success(p)) => p, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this state, we've already sent a CS with the HTLCs removed, and are just waiting on a remote RAA to "forget" the HTLC. IIUC, because the HTLC will be removed before we sign the next remote CS, this won't lead to entries in sign_counterparty_commitment
that we don't actually need (though we may need to re-sign the same CS again in case of reconnect), but it may mean we include the preimage in a validate_holder_commitment
call even though, from the pov of the signer, its been fully and completely removed everywhere.
For a 1st pass, I think this is fine, but we should definitely document in the signer interface that we can include some preimages that were already fully removed and we prefer to over-provide preimages rather than under-provide them - its up to the signer to figure out what to do with them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we just say:
/// NOTE: a preimage may be provided here even if it has been already provided previously
/// in [`sign_counterparty_commitment`].
in validate_holder_commitment
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likely, yea, I would word it even more aggressively and just disclaim any guarantees that the preimages are at all relevant and aren't just random strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed doc changes
ade4454
to
5ece12a
Compare
lightning/src/ln/channel.rs
Outdated
log_trace!(logger, "Updating HTLC {} to AwaitingRemoteRevokeToRemove due to commitment_signed in channel {}.", | ||
log_bytes!(htlc.payment_hash.0), log_bytes!(self.channel_id)); | ||
htlc.state = OutboundHTLCState::AwaitingRemoteRevokeToRemove(fail_reason); | ||
htlc.state = OutboundHTLCState::AwaitingRemoteRevokeToRemove(fail_reason.clone().into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yuck. Can we mem::swap
with a dummy value to avoid cloning Vecs just to drop? Same below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of all the clones of Vecs, which I think we can avoid, but otherwise looks good.
lightning/src/ln/channel.rs
Outdated
if let OutboundHTLCOutcome::Success(preimage) = outcome { | ||
preimages.push(preimage); | ||
} | ||
let reason: Option<HTLCFailReason> = outcome.clone().into(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid this clone as well? Instead of cloneing and converting, we can add a method to write as an option with a reference inside the option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, and the one below too
5ece12a
to
30b408b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM, I believe.
lightning/src/ln/channel.rs
Outdated
// Grab the preimage, if it exists, instead of cloning | ||
let mut reason = OutboundHTLCOutcome::Success(None); | ||
mem::swap(fail_reason, &mut reason); | ||
htlc.state = OutboundHTLCState::AwaitingRemoteRevokeToRemove(reason.into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I believe the .into()
here is unnecessary, and below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
30b408b
to
94a3db9
Compare
lightning/src/ln/channel.rs
Outdated
if let Some(fail_reason) = if let &mut OutboundHTLCState::RemoteRemoved(ref mut fail_reason) = &mut htlc.state { | ||
Some(fail_reason.take()) | ||
} else { None } { | ||
if let &mut OutboundHTLCState::RemoteRemoved(ref mut fail_reason) = &mut htlc.state { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would be nice to rename fail_reason
to outcome
here, similar below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here and in a few other places
94a3db9
to
735a0fa
Compare
Rebased. Sorry @TheBlueMatt - it dismissed your review even though there was no change. |
735a0fa
to
6e19d1f
Compare
So that signer can validate that the local balance decrease is justified by a successful payment.