htlcswitch+lnwallet: fix OnionBlob to 1366 bytes

This commit is contained in:
Keagan McClelland 2024-06-14 17:14:25 -07:00
parent df3c6b72ab
commit 5deb4c253a
No known key found for this signature in database
GPG key ID: FA7E65C951F12439
3 changed files with 14 additions and 18 deletions

View file

@ -3419,7 +3419,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
// parse the onion object in order to obtain the
// routing information with DecodeHopIterator function
// which process the Sphinx packet.
onionReader := bytes.NewReader(pd.OnionBlob)
onionReader := bytes.NewReader(pd.OnionBlob[:])
req := hop.DecodeHopIteratorRequest{
OnionReader: onionReader,
@ -3471,7 +3471,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
// Fetch the onion blob that was included within this processed
// payment descriptor.
var onionBlob [lnwire.OnionPacketSize]byte
copy(onionBlob[:], pd.OnionBlob)
copy(onionBlob[:], pd.OnionBlob[:])
// Before adding the new htlc to the state machine, parse the
// onion object in order to obtain the routing information with

View file

@ -210,8 +210,7 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
BlindingPoint: wireMsg.BlindingPoint,
CustomRecords: wireMsg.CustomRecords.Copy(),
}
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
copy(pd.OnionBlob[:], wireMsg.OnionBlob[:])
pd.OnionBlob = wireMsg.OnionBlob
case *lnwire.UpdateFulfillHTLC:
pd = PaymentDescriptor{
@ -532,10 +531,10 @@ func (c *commitment) toDiskCommit(
HtlcIndex: htlc.HtlcIndex,
LogIndex: htlc.LogIndex,
Incoming: false,
OnionBlob: htlc.OnionBlob,
BlindingPoint: htlc.BlindingPoint,
CustomRecords: htlc.CustomRecords.Copy(),
}
copy(h.OnionBlob[:], htlc.OnionBlob)
if whoseCommit.IsLocal() && htlc.sig != nil {
h.Signature = htlc.sig.Serialize()
@ -558,11 +557,10 @@ func (c *commitment) toDiskCommit(
HtlcIndex: htlc.HtlcIndex,
LogIndex: htlc.LogIndex,
Incoming: true,
OnionBlob: htlc.OnionBlob,
BlindingPoint: htlc.BlindingPoint,
CustomRecords: htlc.CustomRecords.Copy(),
}
copy(h.OnionBlob[:], htlc.OnionBlob)
if whoseCommit.IsLocal() && htlc.sig != nil {
h.Signature = htlc.sig.Serialize()
}
@ -657,7 +655,7 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
EntryType: Add,
HtlcIndex: htlc.HtlcIndex,
LogIndex: htlc.LogIndex,
OnionBlob: htlc.OnionBlob[:],
OnionBlob: htlc.OnionBlob,
localOutputIndex: localOutputIndex,
remoteOutputIndex: remoteOutputIndex,
ourPkScript: ourP2WSH,
@ -1160,11 +1158,10 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
HtlcIndex: wireMsg.ID,
LogIndex: logUpdate.LogIndex,
addCommitHeightRemote: commitHeight,
OnionBlob: wireMsg.OnionBlob,
BlindingPoint: wireMsg.BlindingPoint,
CustomRecords: wireMsg.CustomRecords.Copy(),
}
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
copy(pd.OnionBlob[:], wireMsg.OnionBlob[:])
isDustRemote := HtlcIsDust(
lc.channelState.ChanType, false, lntypes.Remote,
@ -1375,11 +1372,10 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
HtlcIndex: wireMsg.ID,
LogIndex: logUpdate.LogIndex,
addCommitHeightLocal: commitHeight,
OnionBlob: wireMsg.OnionBlob,
BlindingPoint: wireMsg.BlindingPoint,
CustomRecords: wireMsg.CustomRecords.Copy(),
}
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
copy(pd.OnionBlob, wireMsg.OnionBlob[:])
// We don't need to generate an htlc script yet. This will be
// done once we sign our remote commitment.
@ -3424,10 +3420,10 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment,
Amount: pd.Amount,
Expiry: pd.Timeout,
PaymentHash: pd.RHash,
OnionBlob: pd.OnionBlob,
BlindingPoint: pd.BlindingPoint,
CustomRecords: pd.CustomRecords.Copy(),
}
copy(htlc.OnionBlob[:], pd.OnionBlob)
logUpdate.UpdateMsg = htlc
// Gather any references for circuits opened by this Add
@ -3565,10 +3561,10 @@ func (lc *LightningChannel) getUnsignedAckedUpdates() []channeldb.LogUpdate {
Amount: pd.Amount,
Expiry: pd.Timeout,
PaymentHash: pd.RHash,
OnionBlob: pd.OnionBlob,
BlindingPoint: pd.BlindingPoint,
CustomRecords: pd.CustomRecords.Copy(),
}
copy(htlc.OnionBlob[:], pd.OnionBlob)
logUpdate.UpdateMsg = htlc
case Settle:
@ -5643,10 +5639,10 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
Amount: pd.Amount,
Expiry: pd.Timeout,
PaymentHash: pd.RHash,
OnionBlob: pd.OnionBlob,
BlindingPoint: pd.BlindingPoint,
CustomRecords: pd.CustomRecords.Copy(),
}
copy(htlc.OnionBlob[:], pd.OnionBlob)
logUpdate.UpdateMsg = htlc
addUpdates = append(addUpdates, logUpdate)
@ -5988,7 +5984,7 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
Amount: htlc.Amount,
LogIndex: lc.updateLogs.Local.logIndex,
HtlcIndex: lc.updateLogs.Local.htlcCounter,
OnionBlob: htlc.OnionBlob[:],
OnionBlob: htlc.OnionBlob,
OpenCircuitKey: openKey,
BlindingPoint: htlc.BlindingPoint,
CustomRecords: htlc.CustomRecords.Copy(),
@ -6051,7 +6047,7 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64,
Amount: htlc.Amount,
LogIndex: lc.updateLogs.Remote.logIndex,
HtlcIndex: lc.updateLogs.Remote.htlcCounter,
OnionBlob: htlc.OnionBlob[:],
OnionBlob: htlc.OnionBlob,
BlindingPoint: htlc.BlindingPoint,
CustomRecords: htlc.CustomRecords.Copy(),
}

View file

@ -180,7 +180,7 @@ type PaymentDescriptor struct {
// routing.
//
// NOTE: Populated only on add payment descriptor entry types.
OnionBlob []byte
OnionBlob [lnwire.OnionPacketSize]byte
// ShaOnionBlob is a sha of the onion blob.
//