multi: add blinding point to payment descriptor and persist
This commit adds an optional blinding point to payment descriptors and persists them in our HTLC's extra data. A get/set pattern is used to populate the ExtraData on our disk representation of the HTLC so that callers do not need to worry about the underlying storage detail.
This commit is contained in:
5 files changed
+246
-40
No files matched your search
+71
-13
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -371,6 +372,12 @@ type PaymentDescriptor struct {
|
||||
// isForwarded denotes if an incoming HTLC has been forwarded to any
|
||||
// possible upstream peers in the route.
|
||||
isForwarded bool
|
||||
|
||||
// BlindingPoint is an optional ephemeral key used in route blinding.
|
||||
// This value is set for nodes that are relaying payments inside of a
|
||||
// blinded route (ie, not the introduction node) from update_add_htlc's
|
||||
// TLVs.
|
||||
BlindingPoint *btcec.PublicKey
|
||||
}
|
||||
|
||||
// PayDescsFromRemoteLogUpdates converts a slice of LogUpdates received from the
|
||||
@@ -411,6 +418,7 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
|
||||
Height: height,
|
||||
Index: uint16(i),
|
||||
},
|
||||
BlindingPoint: wireMsg.BlingingPointOrNil(),
|
||||
}
|
||||
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
|
||||
copy(pd.OnionBlob[:], wireMsg.OnionBlob[:])
|
||||
@@ -736,6 +744,14 @@ func (c *commitment) toDiskCommit(ourCommit bool) *channeldb.ChannelCommitment {
|
||||
Incoming: false,
|
||||
}
|
||||
copy(h.OnionBlob[:], htlc.OnionBlob)
|
||||
if htlc.BlindingPoint != nil {
|
||||
h.BlindingPoint = tlv.SomeRecordT(
|
||||
//nolint:lll
|
||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](
|
||||
htlc.BlindingPoint,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
if ourCommit && htlc.sig != nil {
|
||||
h.Signature = htlc.sig.Serialize()
|
||||
@@ -760,7 +776,14 @@ func (c *commitment) toDiskCommit(ourCommit bool) *channeldb.ChannelCommitment {
|
||||
Incoming: true,
|
||||
}
|
||||
copy(h.OnionBlob[:], htlc.OnionBlob)
|
||||
|
||||
if htlc.BlindingPoint != nil {
|
||||
h.BlindingPoint = tlv.SomeRecordT(
|
||||
//nolint:lll
|
||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](
|
||||
htlc.BlindingPoint,
|
||||
),
|
||||
)
|
||||
}
|
||||
if ourCommit && htlc.sig != nil {
|
||||
h.Signature = htlc.sig.Serialize()
|
||||
}
|
||||
@@ -859,6 +882,12 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
|
||||
theirWitnessScript: theirWitnessScript,
|
||||
}
|
||||
|
||||
htlc.BlindingPoint.WhenSome(func(b tlv.RecordT[
|
||||
lnwire.BlindingPointTlvType, *btcec.PublicKey]) {
|
||||
|
||||
pd.BlindingPoint = b.Val
|
||||
})
|
||||
|
||||
return pd, nil
|
||||
}
|
||||
|
||||
@@ -1548,6 +1577,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
|
||||
HtlcIndex: wireMsg.ID,
|
||||
LogIndex: logUpdate.LogIndex,
|
||||
addCommitHeightRemote: commitHeight,
|
||||
BlindingPoint: wireMsg.BlingingPointOrNil(),
|
||||
}
|
||||
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
|
||||
copy(pd.OnionBlob[:], wireMsg.OnionBlob[:])
|
||||
@@ -1745,6 +1775,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
|
||||
HtlcIndex: wireMsg.ID,
|
||||
LogIndex: logUpdate.LogIndex,
|
||||
addCommitHeightLocal: commitHeight,
|
||||
BlindingPoint: wireMsg.BlingingPointOrNil(),
|
||||
}
|
||||
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
|
||||
copy(pd.OnionBlob, wireMsg.OnionBlob[:])
|
||||
@@ -3607,6 +3638,14 @@ func (lc *LightningChannel) createCommitDiff(
|
||||
PaymentHash: pd.RHash,
|
||||
}
|
||||
copy(htlc.OnionBlob[:], pd.OnionBlob)
|
||||
if pd.BlindingPoint != nil {
|
||||
htlc.BlindingPoint = tlv.SomeRecordT(
|
||||
//nolint:lll
|
||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](
|
||||
pd.BlindingPoint,
|
||||
),
|
||||
)
|
||||
}
|
||||
logUpdate.UpdateMsg = htlc
|
||||
|
||||
// Gather any references for circuits opened by this Add
|
||||
@@ -3736,12 +3775,21 @@ func (lc *LightningChannel) getUnsignedAckedUpdates() []channeldb.LogUpdate {
|
||||
// four messages that it corresponds to.
|
||||
switch pd.EntryType {
|
||||
case Add:
|
||||
var b lnwire.BlindingPointRecord
|
||||
if pd.BlindingPoint != nil {
|
||||
tlv.SomeRecordT(
|
||||
//nolint:lll
|
||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](pd.BlindingPoint),
|
||||
)
|
||||
}
|
||||
|
||||
htlc := &lnwire.UpdateAddHTLC{
|
||||
ChanID: chanID,
|
||||
ID: pd.HtlcIndex,
|
||||
Amount: pd.Amount,
|
||||
Expiry: pd.Timeout,
|
||||
PaymentHash: pd.RHash,
|
||||
ChanID: chanID,
|
||||
ID: pd.HtlcIndex,
|
||||
Amount: pd.Amount,
|
||||
Expiry: pd.Timeout,
|
||||
PaymentHash: pd.RHash,
|
||||
BlindingPoint: b,
|
||||
}
|
||||
copy(htlc.OnionBlob[:], pd.OnionBlob)
|
||||
logUpdate.UpdateMsg = htlc
|
||||
@@ -5742,6 +5790,14 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
||||
Expiry: pd.Timeout,
|
||||
PaymentHash: pd.RHash,
|
||||
}
|
||||
if pd.BlindingPoint != nil {
|
||||
htlc.BlindingPoint = tlv.SomeRecordT(
|
||||
//nolint:lll
|
||||
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](
|
||||
pd.BlindingPoint,
|
||||
),
|
||||
)
|
||||
}
|
||||
copy(htlc.OnionBlob[:], pd.OnionBlob)
|
||||
logUpdate.UpdateMsg = htlc
|
||||
addUpdates = append(addUpdates, logUpdate)
|
||||
@@ -6079,6 +6135,7 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
|
||||
HtlcIndex: lc.localUpdateLog.htlcCounter,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
OpenCircuitKey: openKey,
|
||||
BlindingPoint: htlc.BlingingPointOrNil(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6129,13 +6186,14 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
EntryType: Add,
|
||||
RHash: PaymentHash(htlc.PaymentHash),
|
||||
Timeout: htlc.Expiry,
|
||||
Amount: htlc.Amount,
|
||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
||||
HtlcIndex: lc.remoteUpdateLog.htlcCounter,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
EntryType: Add,
|
||||
RHash: PaymentHash(htlc.PaymentHash),
|
||||
Timeout: htlc.Expiry,
|
||||
Amount: htlc.Amount,
|
||||
LogIndex: lc.remoteUpdateLog.logIndex,
|
||||
HtlcIndex: lc.remoteUpdateLog.htlcCounter,
|
||||
OnionBlob: htlc.OnionBlob[:],
|
||||
BlindingPoint: htlc.BlingingPointOrNil(),
|
||||
}
|
||||
|
||||
localACKedIndex := lc.remoteCommitChain.tail().ourMessageIndex
|
||||
|
||||
Reference in new issue
Block a user