lnwallet: add CommitFee field to OpenChannel
In order to cleanly handle shutdowns and restarts during state machine operation, the fee for the current commitment transaction must be persisted. This allows the fee to be reapplied when the current state is reloaded.
This commit is contained in:
1 parent
7768415adc
commit
320bed7e6b
3 files changed
+90
-7
No files matched your search
+15
-6
@@ -232,6 +232,11 @@ type commitment struct {
|
||||
ourBalance btcutil.Amount
|
||||
theirBalance btcutil.Amount
|
||||
|
||||
// fee is the amount that will be paid as fees for this commitment
|
||||
// transaction. The fee is recorded here so that it can be added
|
||||
// back and recalculated for each new update to the channel state.
|
||||
fee btcutil.Amount
|
||||
|
||||
// htlcs is the set of HTLCs which remain unsettled within this
|
||||
// commitment.
|
||||
outgoingHTLCs []PaymentDescriptor
|
||||
@@ -251,6 +256,7 @@ func (c *commitment) toChannelDelta(ourCommit bool) (*channeldb.ChannelDelta, er
|
||||
LocalBalance: c.ourBalance,
|
||||
RemoteBalance: c.theirBalance,
|
||||
UpdateNum: c.height,
|
||||
CommitFee: c.fee,
|
||||
Htlcs: make([]*channeldb.HTLC, 0, numHtlcs),
|
||||
}
|
||||
|
||||
@@ -1181,6 +1187,8 @@ func (lc *LightningChannel) restoreStateLogs() error {
|
||||
lc.localCommitChain.tail().theirMessageIndex = theirCounter
|
||||
lc.remoteCommitChain.tail().ourMessageIndex = ourCounter
|
||||
lc.remoteCommitChain.tail().theirMessageIndex = theirCounter
|
||||
lc.localCommitChain.tail().fee = lc.channelState.CommitFee
|
||||
lc.remoteCommitChain.tail().fee = lc.channelState.CommitFee
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1245,12 +1253,13 @@ func (lc *LightningChannel) fetchCommitmentView(remoteChain bool,
|
||||
|
||||
// TODO(roasbeef): don't assume view is always fetched from tip?
|
||||
var ourBalance, theirBalance btcutil.Amount
|
||||
if commitChain.tip() == nil {
|
||||
ourBalance = lc.channelState.OurBalance
|
||||
theirBalance = lc.channelState.TheirBalance
|
||||
} else {
|
||||
ourBalance = commitChain.tip().ourBalance
|
||||
theirBalance = commitChain.tip().theirBalance
|
||||
ourBalance = commitChain.tip().ourBalance
|
||||
theirBalance = commitChain.tip().theirBalance
|
||||
|
||||
if lc.channelState.IsInitiator {
|
||||
ourBalance = ourBalance + commitChain.tip().fee
|
||||
} else if !lc.channelState.IsInitiator {
|
||||
theirBalance = theirBalance + commitChain.tip().fee
|
||||
}
|
||||
|
||||
nextHeight := commitChain.tip().height + 1
|
||||
|
||||
@@ -215,6 +215,7 @@ func NewChannelReservation(capacity, fundingAmt btcutil.Amount, minFeeRate btcut
|
||||
TheirBalance: theirBalance,
|
||||
MinFeePerKb: minFeeRate,
|
||||
Db: wallet.ChannelDB,
|
||||
CommitFee: commitFee,
|
||||
},
|
||||
numConfsToOpen: numConfs,
|
||||
pushSat: pushSat,
|
||||
|
||||
Reference in new issue
Block a user