channeldb+lnwallet: save initial balances during channel opening

This commit is contained in:
yyforyongyu 2022-04-08 02:04:50 +08:00
parent 291a8e4eff
commit 22f8f6ed4a
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
3 changed files with 22 additions and 7 deletions

View file

@ -129,9 +129,9 @@ var (
// bucket for a given channel.
frozenChanKey = []byte("frozen-chans")
// lastWasRevokeKey is a key that stores true when the last update we sent
// was a revocation and false when it was a commitment signature. This is
// nil in the case of new channels with no updates exchanged.
// lastWasRevokeKey is a key that stores true when the last update we
// sent was a revocation and false when it was a commitment signature.
// This is nil in the case of new channels with no updates exchanged.
lastWasRevokeKey = []byte("last-was-revoke")
)
@ -657,6 +657,15 @@ type OpenChannel struct {
// received within this channel.
TotalMSatReceived lnwire.MilliSatoshi
// InitialLocalBalance is the balance we have during the channel
// opening. When we are not the initiator, this value represents the
// push amount.
InitialLocalBalance lnwire.MilliSatoshi
// InitialRemoteBalance is the balance they have during the channel
// opening.
InitialRemoteBalance lnwire.MilliSatoshi
// LocalChanCfg is the channel configuration for the local node.
LocalChanCfg ChannelConfig
@ -3322,7 +3331,8 @@ func putChanInfo(chanBucket kvdb.RwBucket, channel *OpenChannel) error {
channel.chanStatus, channel.FundingBroadcastHeight,
channel.NumConfsRequired, channel.ChannelFlags,
channel.IdentityPub, channel.Capacity, channel.TotalMSatSent,
channel.TotalMSatReceived,
channel.TotalMSatReceived, channel.InitialLocalBalance,
channel.InitialRemoteBalance,
); err != nil {
return err
}
@ -3509,7 +3519,8 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error {
&channel.chanStatus, &channel.FundingBroadcastHeight,
&channel.NumConfsRequired, &channel.ChannelFlags,
&channel.IdentityPub, &channel.Capacity, &channel.TotalMSatSent,
&channel.TotalMSatReceived,
&channel.TotalMSatReceived, &channel.InitialLocalBalance,
&channel.InitialRemoteBalance,
); err != nil {
return err
}

View file

@ -352,6 +352,8 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
Packager: NewChannelPackager(chanID),
FundingTxn: channels.TestFundingTx,
ThawHeight: uint32(defaultPendingHeight),
InitialLocalBalance: lnwire.MilliSatoshi(9000),
InitialRemoteBalance: lnwire.MilliSatoshi(3000),
}
}

View file

@ -405,6 +405,8 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
},
ThawHeight: thawHeight,
Db: wallet.Cfg.Database,
InitialLocalBalance: ourBalance,
InitialRemoteBalance: theirBalance,
},
pushMSat: pushMSat,
pendingChanID: pendingChanID,