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
Enhance update_add_htlc
with remote peer's custom records
#8660
base: 0-19-staging
Are you sure you want to change the base?
Enhance update_add_htlc
with remote peer's custom records
#8660
Conversation
Important Auto Review SkippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@@ -93,6 +93,7 @@ func (r *forwardInterceptor) onIntercept( | |||
CustomRecords: htlc.CustomRecords, | |||
OnionBlob: htlc.OnionBlob[:], | |||
AutoFailHeight: htlc.AutoFailHeight, | |||
WireCustomRecords: htlc.CustomPeerRecords, |
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.
I think this should just be htlc.ExtraData
. This is everything else left over after we read all the current hard wired fields. Start on the latter commits, so this may have been something added elsewhere to manipulate the map version?
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.
also CustomPeerRecords
doesn't exist yet
lnwallet/channel.go
Outdated
|
||
// WireRecordsBlob contains the TLV records blob that was included in | ||
// the original wire message that added this HTLC. | ||
WireRecordsBlob lnwire.CustomRecordsBlob |
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.
So I have something of this logic in: 99db910
Later commits then ensure that this is threaded all the way down to disk. This takes an approach of just accepting the blob, instead of the wire record map.
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 attempt to rebase over that. That also handles all the accounting for restart/retransmission logic not in this PR.
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.
first pass done, need to go over it again though
@@ -119,6 +121,24 @@ func (r *forwardInterceptor) resolveFromClient( | |||
Action: htlcswitch.FwdActionResume, | |||
}) | |||
|
|||
case ResolveHoldForwardAction_RESUME_MODIFIED: | |||
// Modify HTLC and resume forward. | |||
outgoingAmtMsat := lnwire.MilliSatoshi(in.OutgoingAmountMsat) |
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.
I think this value always needs to be set o/w it will set the outgoing amt to 0?
if err := firstHopRecords.Validate(); err != nil { | ||
return nil, err | ||
} | ||
payIntent.FirstHopCustomRecords = firstHopRecords |
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.
FirstHopCustomRecords
introduced in a later commit so this commit won't compile
@@ -713,7 +713,7 @@ func (r *ChannelRouter) Start() error { | |||
// be tried. | |||
_, _, err := r.sendPayment( | |||
0, payment.Info.PaymentIdentifier, 0, | |||
paySession, shardTracker, | |||
paySession, shardTracker, nil, |
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.
If we resume the payment, shouldn't we include the TLVs?
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.
Yeah, we want to include this information on resume.
I think we want to add this to channeldb.PaymentCreationInfo
as a new optional TLV field. We store the bytes in its own key, so no issue w.r.t migrations or anything.
@@ -93,6 +93,7 @@ func (r *forwardInterceptor) onIntercept( | |||
CustomRecords: htlc.CustomRecords, | |||
OnionBlob: htlc.OnionBlob[:], | |||
AutoFailHeight: htlc.AutoFailHeight, | |||
WireCustomRecords: htlc.CustomPeerRecords, |
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.
also CustomPeerRecords
doesn't exist yet
@@ -713,7 +713,7 @@ func (r *ChannelRouter) Start() error { | |||
// be tried. | |||
_, _, err := r.sendPayment( | |||
0, payment.Info.PaymentIdentifier, 0, | |||
paySession, shardTracker, | |||
paySession, shardTracker, nil, |
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.
Yeah, we want to include this information on resume.
I think we want to add this to channeldb.PaymentCreationInfo
as a new optional TLV field. We store the bytes in its own key, so no issue w.r.t migrations or anything.
@@ -963,6 +963,9 @@ message ForwardHtlcInterceptRequest { | |||
// The block height at which this htlc will be auto-failed to prevent the | |||
// channel from force-closing. | |||
int32 auto_fail_height = 10; | |||
|
|||
// The custom records of the peer's wire message. | |||
map<uint64, bytes> wire_custom_records = 11; |
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.
To make this explicit, I think we should name the field: incoming_htlc_custom_wire_records
.
htlcswitch/interceptable_switch.go
Outdated
@@ -486,6 +486,21 @@ func (s *InterceptableSwitch) interceptForward(packet *htlcPacket, | |||
return false, nil | |||
} | |||
|
|||
var customRecordsBlob []byte | |||
|
|||
htlc.CustomRecordsBlob.WhenSome( |
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.
Other comment re ExtraData
also applies here. Will only note it here to avoid duplicate comments.
htlcswitch/interceptable_switch.go
Outdated
) | ||
|
||
customPeerRecords := new(record.CustomSet) | ||
customPeerRecords.Decode(bytes.NewReader(customRecordsBlob)) |
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 propagate the decode error. IIUC, that can fail if the incoming wire records aren't canonical for w/e reason.
htlcswitch/interceptable_switch.go
Outdated
customPeerRecords := new(record.CustomSet) | ||
customPeerRecords.Decode(bytes.NewReader(customRecordsBlob)) | ||
|
||
packet.wireRecords = *customPeerRecords |
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.
incomingWireRecords
?
htlcswitch/interceptable_switch.go
Outdated
CustomRecords: f.packet.customRecords, | ||
OnionBlob: f.htlc.OnionBlob, | ||
AutoFailHeight: f.autoFailHeight, | ||
CustomPeerRecords: f.packet.wireRecords, |
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 add the Incoming
prefix.
htlcswitch/link.go
Outdated
Amount: fwdInfo.AmountToForward, | ||
PaymentHash: pd.RHash, | ||
BlindingPoint: fwdInfo.NextBlinding, | ||
CustomRecordsBlob: pd.WireRecordsBlob, |
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.
Hmm, I don't think we want to store this here. Instead, we should add it only to the htlcPacket
field we generate. This'll transport the wire TLV records of the incoming HTLC. But here we've already modified the outgoing HTLC to have these values (the interceptor might wnat them to be different, or they shouldn't propagate to this hop as well).
htlcswitch/link.go
Outdated
Amount: fwdInfo.AmountToForward, | ||
PaymentHash: pd.RHash, | ||
BlindingPoint: fwdInfo.NextBlinding, | ||
CustomRecordsBlob: pd.WireRecordsBlob, |
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.
Same here re only adding it to the htlcPacket
.
lnwallet/channel.go
Outdated
|
||
// WireRecordsBlob contains the TLV records blob that was included in | ||
// the original wire message that added this HTLC. | ||
WireRecordsBlob lnwire.CustomRecordsBlob |
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 attempt to rebase over that. That also handles all the accounting for restart/retransmission logic not in this PR.
lnwallet/channel.go
Outdated
HtlcIndex: lc.remoteUpdateLog.htlcCounter, | ||
OnionBlob: htlc.OnionBlob[:], | ||
BlindingPoint: htlc.BlindingPoint, | ||
WireRecordsBlob: htlc.CustomRecordsBlob, |
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.
ExtraData
see: a0f19a5#r1569611486
833c121
to
ffb0718
Compare
e9bd133
to
5203776
Compare
5203776
to
a3033a9
Compare
15abb14
to
09b34f1
Compare
@GeorgeTsagk, remember to re-request review from reviewers when ready |
ac58e73
to
3163902
Compare
update_add_htlc
remote peer's custom recordsupdate_add_htlc
with remote peer's custom records
3163902
to
ff58154
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.
@@ -2550,6 +2550,8 @@ type HTLC struct { | |||
// HTLC. It is stored in the ExtraData field, which is used to store | |||
// a TLV stream of additional information associated with the HTLC. | |||
BlindingPoint lnwire.BlindingPointRecord | |||
|
|||
CustomRecords lnwire.CustomRecords |
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: missing Godoc comment. And maybe we should mention here that this will be encoded into the ExtraData
alongside the BlindingPoint
when encoded (for sending on the wire or storing to the DB).
@@ -3924,7 +4014,8 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment, | |||
|
|||
// getUnsignedAckedUpdates returns all remote log updates that we haven't | |||
// signed for yet ourselves. | |||
func (lc *LightningChannel) getUnsignedAckedUpdates() []channeldb.LogUpdate { | |||
func (lc *LightningChannel) getUnsignedAckedUpdates() ([]channeldb.LogUpdate, | |||
error) { |
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: add newline after multi-line method definition.
auxLeaves, err := AuxLeavesFromCommit( | ||
chanState, *remoteCommitView.toDiskCommit(false), leafStore, | ||
chanState, *diskCommit, leafStore, |
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: can all fit on a single line now (same further below).
|
||
lc.Lock() | ||
defer lc.Unlock() | ||
|
||
pd := lc.htlcAddDescriptor(htlc, openKey) | ||
if err := lc.validateAddHtlc(pd, buffer); err != nil { | ||
pd, err := lc.htlcAddDescriptor(htlc, openKey) |
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.
Looks like we dropped the call to lc.validateAddHtlc()
here. Perhaps by accident? Sounds like that's still needed.
@@ -14,6 +14,26 @@ const ( | |||
MinCustomRecordsTlvType = 65536 | |||
) | |||
|
|||
// ParseCustomRecords decodes a set of custom records from a byte slice. | |||
func ParseCustomRecords(b tlv.Blob) (CustomRecords, error) { |
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.
Looks like this ended up a duplicate of NewCustomRecordsFromTlvBlob
below. So can just use that.
Or maybe rename NewCustomRecordsFromTlvBlob
to ParseCustomRecords
which is way shorter.
ff58154
to
ce2a005
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.
First pass, a few high level comments:
- Already noted by other reviewers, but restart flows need some more attention here (both including the custom fields and ensuring we always have this data persisted)
- Meta/personal preference: move itest to the end of the PR rather than having several iterations of it throughout the code
- One consideration that this PR introduces is that we're now going to store all the custom records that we're send with a HTLC, which could result in our storing a whole lot of junk that our peers send us - this was originally discussed when we added the update that allows us to store this data. I originally thought that a good way to approach this would be to allow users to specify the custom TLV values they want to store (or hardcode some notable ones that we want to keep by default), but I haven't fully thought that design through tbh.
dbgInfo, err := bob.RPC.LN.GetDebugInfo( | ||
ctx, &lnrpc.GetDebugInfoRequest{}, | ||
) | ||
require.NoError(ht, err, "failed to get Barol node debug info") |
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.
:s/Barol/Carol
// testForwardInterceptorFirstHopRecords | ||
func testForwardInterceptorFirstHopRecords(ht *lntest.HarnessTest) { |
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: needs godoc
65537: []byte("test"), | ||
}, | ||
} | ||
stream := alice.RPC.SendPayment(sendReq) |
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.
Would be good to test across restarts as well to get coverage for this comment
@@ -357,6 +357,10 @@ type InterceptedPacket struct { | |||
// OnionBlob is the onion packet for the next hop | |||
OnionBlob [lnwire.OnionPacketSize]byte | |||
|
|||
// WireCustomRecords are user-defined records that were defined by the | |||
// peer that forwarded this htlc to us. | |||
WireCustomRecords record.CustomSet |
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.
This name is a little ambiguous to me (since everything arrives on the wire), WDYT of IncomingAddCustomRecords
- a little longer but it's clearer about where these records come from, when I read the name without seeing the godoc for the field it's unclear to me whether these are from update_add_htlc
or the htlc's payload.
itest/list_on_test.go
Outdated
@@ -426,6 +426,10 @@ var allTestCases = []*lntest.TestCase{ | |||
Name: "forward interceptor modified htlc", | |||
TestFunc: testForwardInterceptorModifiedHtlc, | |||
}, | |||
{ | |||
Name: "forward interceptor first hop records", |
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.
structural comment: seems to me that it would make sense to move this itest commit to the end of the PR so that we don't have to have two iterations of it (one here, one adding coverage using the interceptor later)
@@ -894,8 +931,12 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight, | |||
|
|||
// Ensure that we'll restore any custom records which were stored as | |||
// extra data on disk. | |||
if len(htlc.ExtraData) != 0 { | |||
pd.CustomRecords = fn.Some[tlv.Blob](htlc.ExtraData) | |||
if len(htlc.CustomRecords) != 0 { |
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.
While we're setting the CustomRecords
values above, we're not actually persisting them using the workaround added in #7710, which means that in certain restart cases we won't restore these records (diff to test db restore here).
So as-is we'll always have htlc.CustomRecords
=0 because we're not persisting them with the channeldb.HTLC
that needs to be turned into a PaymentDescriptor
here.
The restart flow always takes me forever to reload into my brain, tried to write it all down here if that's at all helpful.
@@ -6416,6 +6570,16 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err | |||
BlindingPoint: htlc.BlindingPoint, | |||
} | |||
|
|||
if len(htlc.CustomRecords) > 0 { |
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.
If ExtraData
contains a protocol-range TLV that isn't blinding point, all of our htlc.CustomRecords
will be overwritten because we'll hit ExtraData != nil
?
While we're not expecting this (there aren't any other defined protocol TLVs for update_add_htlc
right now), I think we should account for the possibility that other nodes in the network may relay these fields in the future because as-is it'll break our code.
return err | ||
} | ||
|
||
addMsg.CustomRecords = r |
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.
Do we want to be overloading the CustomRecords
field here?
pd.CustomRecords
are the records we received on the incoming HTLC'supdate_add_htlc
addMsg.CustomRecords
are the records that we're going to pack for the outgoing HTLC'supdate_add_htlc
This has the impact of always relaying all of the custom TLVs that we get on the incoming update_add_htlc
to the outgoing update_add_htlc
- confirmed this with a quick itest hack - and I don't see anything in the original issue saying that we want to do this?
Description
Based on #8633
This PR enhances the
update_add_htlc
message with a "custom records" field which may contain custom records that are meant to be transmitted to the direct peer.This extra field is included in
routerrpc.SendPaymentRequest
and is also exposed in the forward interceptorCloses #8618