lnwallet: track ChannelID on PaymentDescriptor

In this commit we track the ChannelID on the PaymentDescriptor.
This will be useful in upcoming commits that need to be able to
reconstruct lnwire.Message values from PaymentDescriptors as the
Messages that are exchanged to update channel state all include
the ChannelID.
This commit is contained in:
Keagan McClelland 2024-06-06 11:44:44 -07:00 committed by Oliver Gugger
parent a40d363936
commit 391370de20
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 33 additions and 0 deletions

View File

@ -196,6 +196,7 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
case *lnwire.UpdateAddHTLC:
pd = PaymentDescriptor{
ChanID: wireMsg.ChanID,
RHash: wireMsg.PaymentHash,
Timeout: wireMsg.Expiry,
Amount: wireMsg.Amount,
@ -214,6 +215,7 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
case *lnwire.UpdateFulfillHTLC:
pd = PaymentDescriptor{
ChanID: wireMsg.ChanID,
RPreimage: wireMsg.PaymentPreimage,
ParentIndex: wireMsg.ID,
EntryType: Settle,
@ -226,6 +228,7 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
case *lnwire.UpdateFailHTLC:
pd = PaymentDescriptor{
ChanID: wireMsg.ChanID,
ParentIndex: wireMsg.ID,
EntryType: Fail,
FailReason: wireMsg.Reason[:],
@ -238,6 +241,7 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
case *lnwire.UpdateFailMalformedHTLC:
pd = PaymentDescriptor{
ChanID: wireMsg.ChanID,
ParentIndex: wireMsg.ID,
EntryType: MalformedFail,
FailCode: wireMsg.FailureCode,
@ -646,6 +650,7 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
// vs theirs or a pending commit for the remote party), we can now
// re-create the original payment descriptor.
return PaymentDescriptor{
ChanID: lc.ChannelID(),
RHash: htlc.RHash,
Timeout: htlc.RefundTimeout,
Amount: htlc.Amt,
@ -1147,6 +1152,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
// as we've included this HTLC in our local commitment chain
// for the remote party.
pd = &PaymentDescriptor{
ChanID: wireMsg.ChanID,
RHash: wireMsg.PaymentHash,
Timeout: wireMsg.Expiry,
Amount: wireMsg.Amount,
@ -1192,6 +1198,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID)
pd = &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
RPreimage: wireMsg.PaymentPreimage,
@ -1209,6 +1216,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID)
pd = &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
ParentIndex: ogHTLC.HtlcIndex,
@ -1225,6 +1233,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
// TODO(roasbeef): err if nil?
pd = &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
ParentIndex: ogHTLC.HtlcIndex,
@ -1243,6 +1252,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
// adding and removing it at the same height.
case *lnwire.UpdateFee:
pd = &PaymentDescriptor{
ChanID: wireMsg.ChanID,
LogIndex: logUpdate.LogIndex,
Amount: lnwire.NewMSatFromSatoshis(
btcutil.Amount(wireMsg.FeePerKw),
@ -1279,6 +1289,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda
ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID)
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
RPreimage: wireMsg.PaymentPreimage,
@ -1295,6 +1306,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda
ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID)
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
ParentIndex: ogHTLC.HtlcIndex,
@ -1310,6 +1322,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda
ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID)
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
ParentIndex: ogHTLC.HtlcIndex,
@ -1322,6 +1335,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda
case *lnwire.UpdateFee:
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
LogIndex: logUpdate.LogIndex,
Amount: lnwire.NewMSatFromSatoshis(
btcutil.Amount(wireMsg.FeePerKw),
@ -1353,6 +1367,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
switch wireMsg := logUpdate.UpdateMsg.(type) {
case *lnwire.UpdateAddHTLC:
pd := &PaymentDescriptor{
ChanID: wireMsg.ChanID,
RHash: wireMsg.PaymentHash,
Timeout: wireMsg.Expiry,
Amount: wireMsg.Amount,
@ -1378,6 +1393,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
ogHTLC := localUpdateLog.lookupHtlc(wireMsg.ID)
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
RPreimage: wireMsg.PaymentPreimage,
@ -1394,6 +1410,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
ogHTLC := localUpdateLog.lookupHtlc(wireMsg.ID)
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
ParentIndex: ogHTLC.HtlcIndex,
@ -1409,6 +1426,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
ogHTLC := localUpdateLog.lookupHtlc(wireMsg.ID)
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
Amount: ogHTLC.Amount,
RHash: ogHTLC.RHash,
ParentIndex: ogHTLC.HtlcIndex,
@ -1427,6 +1445,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd
// adding and removing it at the same height.
case *lnwire.UpdateFee:
return &PaymentDescriptor{
ChanID: wireMsg.ChanID,
LogIndex: logUpdate.LogIndex,
Amount: lnwire.NewMSatFromSatoshis(
btcutil.Amount(wireMsg.FeePerKw),
@ -5962,6 +5981,7 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
openKey *models.CircuitKey) *PaymentDescriptor {
return &PaymentDescriptor{
ChanID: htlc.ChanID,
EntryType: Add,
RHash: PaymentHash(htlc.PaymentHash),
Timeout: htlc.Expiry,
@ -6024,6 +6044,7 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64,
}
pd := &PaymentDescriptor{
ChanID: htlc.ChanID,
EntryType: Add,
RHash: PaymentHash(htlc.PaymentHash),
Timeout: htlc.Expiry,
@ -6104,6 +6125,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
}
pd := &PaymentDescriptor{
ChanID: lc.ChannelID(),
Amount: htlc.Amount,
RPreimage: preimage,
LogIndex: lc.updateLogs.Local.logIndex,
@ -6149,6 +6171,7 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
}
pd := &PaymentDescriptor{
ChanID: lc.ChannelID(),
Amount: htlc.Amount,
RPreimage: preimage,
ParentIndex: htlc.HtlcIndex,
@ -6210,6 +6233,7 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
}
pd := &PaymentDescriptor{
ChanID: lc.ChannelID(),
Amount: htlc.Amount,
RHash: htlc.RHash,
ParentIndex: htlcIndex,
@ -6260,6 +6284,7 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
}
pd := &PaymentDescriptor{
ChanID: lc.ChannelID(),
Amount: htlc.Amount,
RHash: htlc.RHash,
ParentIndex: htlcIndex,
@ -6302,6 +6327,7 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
}
pd := &PaymentDescriptor{
ChanID: lc.ChannelID(),
Amount: htlc.Amount,
RHash: htlc.RHash,
ParentIndex: htlc.HtlcIndex,
@ -8421,6 +8447,7 @@ func (lc *LightningChannel) UpdateFee(feePerKw chainfee.SatPerKWeight) error {
}
pd := &PaymentDescriptor{
ChanID: lc.ChannelID(),
LogIndex: lc.updateLogs.Local.logIndex,
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
EntryType: FeeUpdate,
@ -8493,6 +8520,7 @@ func (lc *LightningChannel) ReceiveUpdateFee(feePerKw chainfee.SatPerKWeight) er
// TODO(roasbeef): or just modify to use the other balance?
pd := &PaymentDescriptor{
ChanID: lc.ChannelID(),
LogIndex: lc.updateLogs.Remote.logIndex,
Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)),
EntryType: FeeUpdate,

View File

@ -70,6 +70,11 @@ func (u updateType) String() string {
// TODO(roasbeef): LogEntry interface??
// - need to separate attrs for cancel/add/settle/feeupdate
type PaymentDescriptor struct {
// ChanID is the ChannelID of the LightningChannel that this
// PaymentDescriptor belongs to. We track this here so we can
// reconstruct the Messages that this PaymentDescriptor is built from.
ChanID lnwire.ChannelID
// RHash is the payment hash for this HTLC. The HTLC can be settled iff
// the preimage to this hash is presented.
RHash PaymentHash