lnwallet/channel: add lnwire<->PaymentDescriptor FeeUpdate conversion
This commit adds conversion between the lnwire.UpdateFee message and the new FeeUpdate PaymentDescriptor. We re-purpose the existing Amount field in the PaymentDescriptor stuct to hold the feerate.
This commit is contained in:
3 files changed
+57
-5
No files matched your search
+39
-2
@@ -351,7 +351,7 @@ type PaymentDescriptor struct {
|
||||
// NOTE: The provided `logUpdates` MUST corresponding exactly to either the Adds
|
||||
// or SettleFails in this channel's forwarding package at `height`.
|
||||
func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
|
||||
logUpdates []channeldb.LogUpdate) []*PaymentDescriptor {
|
||||
logUpdates []channeldb.LogUpdate) ([]*PaymentDescriptor, error) {
|
||||
|
||||
// Allocate enough space to hold all of the payment descriptors we will
|
||||
// reconstruct, and also the list of pointers that will be returned to
|
||||
@@ -423,13 +423,18 @@ func PayDescsFromRemoteLogUpdates(chanID lnwire.ShortChannelID, height uint64,
|
||||
Index: uint16(i),
|
||||
},
|
||||
}
|
||||
|
||||
// NOTE: UpdateFee is not expected since they are not forwarded.
|
||||
case *lnwire.UpdateFee:
|
||||
return nil, fmt.Errorf("unexpected update fee")
|
||||
|
||||
}
|
||||
|
||||
payDescs = append(payDescs, pd)
|
||||
payDescPtrs = append(payDescPtrs, &payDescs[i])
|
||||
}
|
||||
|
||||
return payDescPtrs
|
||||
return payDescPtrs, nil
|
||||
}
|
||||
|
||||
// commitment represents a commitment to a new state within an active channel.
|
||||
@@ -1568,6 +1573,23 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate,
|
||||
ShaOnionBlob: wireMsg.ShaOnionBlob,
|
||||
removeCommitHeightRemote: commitHeight,
|
||||
}
|
||||
|
||||
// For fee updates we'll create a FeeUpdate type to add to the log. We
|
||||
// reuse the amount field to hold the fee rate. Since the amount field
|
||||
// is denominated in msat we won't lose precision when storing the
|
||||
// sat/kw denominated feerate. Note that we set both the add and remove
|
||||
// height to the same value, as we consider the fee update locked in by
|
||||
// adding and removing it at the same height.
|
||||
case *lnwire.UpdateFee:
|
||||
pd = &PaymentDescriptor{
|
||||
LogIndex: logUpdate.LogIndex,
|
||||
Amount: lnwire.NewMSatFromSatoshis(
|
||||
btcutil.Amount(wireMsg.FeePerKw),
|
||||
),
|
||||
EntryType: FeeUpdate,
|
||||
addCommitHeightRemote: commitHeight,
|
||||
removeCommitHeightRemote: commitHeight,
|
||||
}
|
||||
}
|
||||
|
||||
return pd, nil
|
||||
@@ -2883,6 +2905,15 @@ func (lc *LightningChannel) createCommitDiff(
|
||||
ShaOnionBlob: pd.ShaOnionBlob,
|
||||
FailureCode: pd.FailCode,
|
||||
}
|
||||
|
||||
case FeeUpdate:
|
||||
// The Amount field holds the feerate denominated in
|
||||
// msat. Since feerates are only denominated in sat/kw,
|
||||
// we can convert it without loss of precision.
|
||||
logUpdate.UpdateMsg = &lnwire.UpdateFee{
|
||||
ChanID: chanID,
|
||||
FeePerKw: uint32(pd.Amount.ToSatoshis()),
|
||||
}
|
||||
}
|
||||
|
||||
// Gather the fwd pkg references from any settle or fail
|
||||
@@ -4254,6 +4285,12 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
|
||||
for e := lc.remoteUpdateLog.Front(); e != nil; e = e.Next() {
|
||||
pd := e.Value.(*PaymentDescriptor)
|
||||
|
||||
// Fee updates are local to this particular channel, and should
|
||||
// never be forwarded.
|
||||
if pd.EntryType == FeeUpdate {
|
||||
continue
|
||||
}
|
||||
|
||||
if pd.isForwarded {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user