mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-23 17:59:41 +02:00
lnwallet: add update_fee message support.
This commit adds the possibility for the initiator of a channel to send the update_fee message, as specified in BOLT#2. After the message is sent and both parties have committed to the updated fee, all new commitment messages in the channel will use the specified fee.
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
a3836d5241
commit
ebe05f6568
@@ -428,6 +428,7 @@ func (c *OpenChannel) UpdateCommitment(newCommitment *wire.MsgTx,
|
||||
c.NumUpdates = delta.UpdateNum
|
||||
c.Htlcs = delta.Htlcs
|
||||
c.CommitFee = delta.CommitFee
|
||||
c.FeePerKw = delta.FeePerKw
|
||||
|
||||
// First we'll write out the current latest dynamic channel
|
||||
// state: the current channel balance, the number of updates,
|
||||
@@ -445,6 +446,9 @@ func (c *OpenChannel) UpdateCommitment(newCommitment *wire.MsgTx,
|
||||
if err := putChanCommitFee(chanBucket, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := putChanFeePerKw(chanBucket, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := putChanCommitTxns(nodeChanBucket, c); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -517,6 +521,10 @@ type ChannelDelta struct {
|
||||
// initiator's balance at this point in the commitment chain.
|
||||
CommitFee btcutil.Amount
|
||||
|
||||
// FeePerKw is the fee per kw used to calculate the commit fee at this point
|
||||
// in the commit chain.
|
||||
FeePerKw btcutil.Amount
|
||||
|
||||
// UpdateNum is the update number that this ChannelDelta represents the
|
||||
// total number of commitment updates to this point. This can be viewed
|
||||
// as sort of a "commitment height" as this number is monotonically
|
||||
@@ -2206,6 +2214,11 @@ func serializeChannelDelta(w io.Writer, delta *ChannelDelta) error {
|
||||
return err
|
||||
}
|
||||
|
||||
byteOrder.PutUint64(scratch[:], uint64(delta.FeePerKw))
|
||||
if _, err := w.Write(scratch[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2249,6 +2262,11 @@ func deserializeChannelDelta(r io.Reader) (*ChannelDelta, error) {
|
||||
}
|
||||
delta.CommitFee = btcutil.Amount(byteOrder.Uint64(scratch[:]))
|
||||
|
||||
if _, err := r.Read(scratch[:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
delta.FeePerKw = btcutil.Amount(byteOrder.Uint64(scratch[:]))
|
||||
|
||||
return delta, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user