multi: use some record for payment descriptor blinding point

This commit is contained in:
Carla Kirk-Cohen committed 2024-04-02 15:44:05 -04:00
1 parent b1175514f9
commit 7fd9c2a7f8
4 files changed
+37 -89

No files matched your search

+9 -6
View File
@@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
sphinx "github.com/lightningnetwork/lightning-onion" sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tlv"
) )
// Iterator is an interface that abstracts away the routing information // Iterator is an interface that abstracts away the routing information
@@ -186,7 +187,7 @@ type DecodeHopIteratorRequest struct {
RHash []byte RHash []byte
IncomingCltv uint32 IncomingCltv uint32
IncomingAmount lnwire.MilliSatoshi IncomingAmount lnwire.MilliSatoshi
BlindingPoint *btcec.PublicKey BlindingPoint lnwire.BlindingPointRecord
} }
// DecodeHopIteratorResponse encapsulates the outcome of a batched sphinx onion // DecodeHopIteratorResponse encapsulates the outcome of a batched sphinx onion
@@ -243,12 +244,14 @@ func (p *OnionProcessor) DecodeHopIterators(id []byte,
} }
var opts []sphinx.ProcessOnionOpt var opts []sphinx.ProcessOnionOpt
if req.BlindingPoint != nil { req.BlindingPoint.WhenSome(func(
opts = append(opts, sphinx.WithBlindingPoint( b tlv.RecordT[lnwire.BlindingPointTlvType,
req.BlindingPoint, *btcec.PublicKey]) {
))
}
opts = append(opts, sphinx.WithBlindingPoint(
b.Val,
))
})
err = tx.ProcessOnionPacket( err = tx.ProcessOnionPacket(
seqNum, onionPkt, req.RHash, req.IncomingCltv, opts..., seqNum, onionPkt, req.RHash, req.IncomingCltv, opts...,
) )
+24 -68
View File
@@ -31,7 +31,6 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/chainfee" "github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/shachain" "github.com/lightningnetwork/lnd/shachain"
"github.com/lightningnetwork/lnd/tlv"
) )
var ( var (
@@ -377,7 +376,7 @@ type PaymentDescriptor struct {
// This value is set for nodes that are relaying payments inside of a // 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 // blinded route (ie, not the introduction node) from update_add_htlc's
// TLVs. // TLVs.
BlindingPoint *btcec.PublicKey BlindingPoint lnwire.BlindingPointRecord
} }
// PayDescsFromRemoteLogUpdates converts a slice of LogUpdates received from the // PayDescsFromRemoteLogUpdates converts a slice of LogUpdates received from the
@@ -418,7 +417,7 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
Height: height, Height: height,
Index: uint16(i), Index: uint16(i),
}, },
BlindingPoint: wireMsg.BlingingPointOrNil(), BlindingPoint: pd.BlindingPoint,
} }
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob)) pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
copy(pd.OnionBlob[:], wireMsg.OnionBlob[:]) copy(pd.OnionBlob[:], wireMsg.OnionBlob[:])
@@ -742,16 +741,9 @@ func (c *commitment) toDiskCommit(ourCommit bool) *channeldb.ChannelCommitment {
HtlcIndex: htlc.HtlcIndex, HtlcIndex: htlc.HtlcIndex,
LogIndex: htlc.LogIndex, LogIndex: htlc.LogIndex,
Incoming: false, Incoming: false,
BlindingPoint: htlc.BlindingPoint,
} }
copy(h.OnionBlob[:], htlc.OnionBlob) 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 { if ourCommit && htlc.sig != nil {
h.Signature = htlc.sig.Serialize() h.Signature = htlc.sig.Serialize()
@@ -774,16 +766,9 @@ func (c *commitment) toDiskCommit(ourCommit bool) *channeldb.ChannelCommitment {
HtlcIndex: htlc.HtlcIndex, HtlcIndex: htlc.HtlcIndex,
LogIndex: htlc.LogIndex, LogIndex: htlc.LogIndex,
Incoming: true, Incoming: true,
BlindingPoint: htlc.BlindingPoint,
} }
copy(h.OnionBlob[:], htlc.OnionBlob) 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 { if ourCommit && htlc.sig != nil {
h.Signature = htlc.sig.Serialize() h.Signature = htlc.sig.Serialize()
} }
@@ -866,7 +851,7 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
// With the scripts reconstructed (depending on if this is our commit // With the scripts reconstructed (depending on if this is our commit
// vs theirs or a pending commit for the remote party), we can now // vs theirs or a pending commit for the remote party), we can now
// re-create the original payment descriptor. // re-create the original payment descriptor.
pd = PaymentDescriptor{ return PaymentDescriptor{
RHash: htlc.RHash, RHash: htlc.RHash,
Timeout: htlc.RefundTimeout, Timeout: htlc.RefundTimeout,
Amount: htlc.Amt, Amount: htlc.Amt,
@@ -880,15 +865,8 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
ourWitnessScript: ourWitnessScript, ourWitnessScript: ourWitnessScript,
theirPkScript: theirP2WSH, theirPkScript: theirP2WSH,
theirWitnessScript: theirWitnessScript, theirWitnessScript: theirWitnessScript,
} BlindingPoint: htlc.BlindingPoint,
}, nil
htlc.BlindingPoint.WhenSome(func(b tlv.RecordT[
lnwire.BlindingPointTlvType, *btcec.PublicKey]) {
pd.BlindingPoint = b.Val
})
return pd, nil
} }
// extractPayDescs will convert all HTLC's present within a disk commit state // extractPayDescs will convert all HTLC's present within a disk commit state
@@ -1577,7 +1555,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
HtlcIndex: wireMsg.ID, HtlcIndex: wireMsg.ID,
LogIndex: logUpdate.LogIndex, LogIndex: logUpdate.LogIndex,
addCommitHeightRemote: commitHeight, addCommitHeightRemote: commitHeight,
BlindingPoint: wireMsg.BlingingPointOrNil(), BlindingPoint: wireMsg.BlindingPoint,
} }
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob)) pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
copy(pd.OnionBlob[:], wireMsg.OnionBlob[:]) copy(pd.OnionBlob[:], wireMsg.OnionBlob[:])
@@ -1775,7 +1753,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
HtlcIndex: wireMsg.ID, HtlcIndex: wireMsg.ID,
LogIndex: logUpdate.LogIndex, LogIndex: logUpdate.LogIndex,
addCommitHeightLocal: commitHeight, addCommitHeightLocal: commitHeight,
BlindingPoint: wireMsg.BlingingPointOrNil(), BlindingPoint: wireMsg.BlindingPoint,
} }
pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob)) pd.OnionBlob = make([]byte, len(wireMsg.OnionBlob))
copy(pd.OnionBlob, wireMsg.OnionBlob[:]) copy(pd.OnionBlob, wireMsg.OnionBlob[:])
@@ -3631,21 +3609,14 @@ func (lc *LightningChannel) createCommitDiff(
switch pd.EntryType { switch pd.EntryType {
case Add: case Add:
htlc := &lnwire.UpdateAddHTLC{ htlc := &lnwire.UpdateAddHTLC{
ChanID: chanID, ChanID: chanID,
ID: pd.HtlcIndex, ID: pd.HtlcIndex,
Amount: pd.Amount, Amount: pd.Amount,
Expiry: pd.Timeout, Expiry: pd.Timeout,
PaymentHash: pd.RHash, PaymentHash: pd.RHash,
BlindingPoint: pd.BlindingPoint,
} }
copy(htlc.OnionBlob[:], pd.OnionBlob) copy(htlc.OnionBlob[:], pd.OnionBlob)
if pd.BlindingPoint != nil {
htlc.BlindingPoint = tlv.SomeRecordT(
//nolint:lll
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](
pd.BlindingPoint,
),
)
}
logUpdate.UpdateMsg = htlc logUpdate.UpdateMsg = htlc
// Gather any references for circuits opened by this Add // Gather any references for circuits opened by this Add
@@ -3775,21 +3746,13 @@ func (lc *LightningChannel) getUnsignedAckedUpdates() []channeldb.LogUpdate {
// four messages that it corresponds to. // four messages that it corresponds to.
switch pd.EntryType { switch pd.EntryType {
case Add: case Add:
var b lnwire.BlindingPointRecord
if pd.BlindingPoint != nil {
tlv.SomeRecordT(
//nolint:lll
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](pd.BlindingPoint),
)
}
htlc := &lnwire.UpdateAddHTLC{ htlc := &lnwire.UpdateAddHTLC{
ChanID: chanID, ChanID: chanID,
ID: pd.HtlcIndex, ID: pd.HtlcIndex,
Amount: pd.Amount, Amount: pd.Amount,
Expiry: pd.Timeout, Expiry: pd.Timeout,
PaymentHash: pd.RHash, PaymentHash: pd.RHash,
BlindingPoint: b, BlindingPoint: pd.BlindingPoint,
} }
copy(htlc.OnionBlob[:], pd.OnionBlob) copy(htlc.OnionBlob[:], pd.OnionBlob)
logUpdate.UpdateMsg = htlc logUpdate.UpdateMsg = htlc
@@ -5784,19 +5747,12 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
switch pd.EntryType { switch pd.EntryType {
case Add: case Add:
htlc := &lnwire.UpdateAddHTLC{ htlc := &lnwire.UpdateAddHTLC{
ChanID: chanID, ChanID: chanID,
ID: pd.HtlcIndex, ID: pd.HtlcIndex,
Amount: pd.Amount, Amount: pd.Amount,
Expiry: pd.Timeout, Expiry: pd.Timeout,
PaymentHash: pd.RHash, PaymentHash: pd.RHash,
} BlindingPoint: pd.BlindingPoint,
if pd.BlindingPoint != nil {
htlc.BlindingPoint = tlv.SomeRecordT(
//nolint:lll
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](
pd.BlindingPoint,
),
)
} }
copy(htlc.OnionBlob[:], pd.OnionBlob) copy(htlc.OnionBlob[:], pd.OnionBlob)
logUpdate.UpdateMsg = htlc logUpdate.UpdateMsg = htlc
@@ -6135,7 +6091,7 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
HtlcIndex: lc.localUpdateLog.htlcCounter, HtlcIndex: lc.localUpdateLog.htlcCounter,
OnionBlob: htlc.OnionBlob[:], OnionBlob: htlc.OnionBlob[:],
OpenCircuitKey: openKey, OpenCircuitKey: openKey,
BlindingPoint: htlc.BlingingPointOrNil(), BlindingPoint: htlc.BlindingPoint,
} }
} }
@@ -6193,7 +6149,7 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, err
LogIndex: lc.remoteUpdateLog.logIndex, LogIndex: lc.remoteUpdateLog.logIndex,
HtlcIndex: lc.remoteUpdateLog.htlcCounter, HtlcIndex: lc.remoteUpdateLog.htlcCounter,
OnionBlob: htlc.OnionBlob[:], OnionBlob: htlc.OnionBlob[:],
BlindingPoint: htlc.BlingingPointOrNil(), BlindingPoint: htlc.BlindingPoint,
} }
localACKedIndex := lc.remoteCommitChain.tail().ourMessageIndex localACKedIndex := lc.remoteCommitChain.tail().ourMessageIndex
+4 -2
View File
@@ -11045,7 +11045,8 @@ func TestBlindingPointPersistence(t *testing.T) {
// Assert that the blinding point is restored from disk. // Assert that the blinding point is restored from disk.
remoteCommit := aliceChannel.remoteCommitChain.tip() remoteCommit := aliceChannel.remoteCommitChain.tip()
require.Len(t, remoteCommit.outgoingHTLCs, 1) require.Len(t, remoteCommit.outgoingHTLCs, 1)
require.Equal(t, blinding, remoteCommit.outgoingHTLCs[0].BlindingPoint) require.Equal(t, blinding,
remoteCommit.outgoingHTLCs[0].BlindingPoint.UnwrapOrFailV(t))
// Next, update bob's commitment and assert that we can still retrieve // Next, update bob's commitment and assert that we can still retrieve
// his incoming blinding point after restart. // his incoming blinding point after restart.
@@ -11061,5 +11062,6 @@ func TestBlindingPointPersistence(t *testing.T) {
// Assert that Bob is able to recover the blinding point from disk. // Assert that Bob is able to recover the blinding point from disk.
bobCommit := bobChannel.localCommitChain.tip() bobCommit := bobChannel.localCommitChain.tip()
require.Len(t, bobCommit.incomingHTLCs, 1) require.Len(t, bobCommit.incomingHTLCs, 1)
require.Equal(t, blinding, bobCommit.incomingHTLCs[0].BlindingPoint) require.Equal(t, blinding,
bobCommit.incomingHTLCs[0].BlindingPoint.UnwrapOrFailV(t))
} }
-13
View File
@@ -78,19 +78,6 @@ type UpdateAddHTLC struct {
ExtraData ExtraOpaqueData ExtraData ExtraOpaqueData
} }
// BlingingPointOrNil returns the blinding point associated with the update, or
// nil.
func (c *UpdateAddHTLC) BlingingPointOrNil() *btcec.PublicKey {
var blindingPoint *btcec.PublicKey
c.BlindingPoint.WhenSome(func(b tlv.RecordT[BlindingPointTlvType,
*btcec.PublicKey]) {
blindingPoint = b.Val
})
return blindingPoint
}
// NewUpdateAddHTLC returns a new empty UpdateAddHTLC message. // NewUpdateAddHTLC returns a new empty UpdateAddHTLC message.
func NewUpdateAddHTLC() *UpdateAddHTLC { func NewUpdateAddHTLC() *UpdateAddHTLC {
return &UpdateAddHTLC{} return &UpdateAddHTLC{}