channeldb+lnwallet: save initial balances during channel opening

This commit is contained in:
yyforyongyu committed 2022-04-20 01:18:12 +08:00
1 parent 291a8e4eff
commit 22f8f6ed4a
3 files changed
+22 -7

No files matched your search

+16 -5
View File
@@ -129,9 +129,9 @@ var (
// bucket for a given channel. // bucket for a given channel.
frozenChanKey = []byte("frozen-chans") frozenChanKey = []byte("frozen-chans")
// lastWasRevokeKey is a key that stores true when the last update we sent // lastWasRevokeKey is a key that stores true when the last update we
// was a revocation and false when it was a commitment signature. This is // sent was a revocation and false when it was a commitment signature.
// nil in the case of new channels with no updates exchanged. // This is nil in the case of new channels with no updates exchanged.
lastWasRevokeKey = []byte("last-was-revoke") lastWasRevokeKey = []byte("last-was-revoke")
) )
@@ -657,6 +657,15 @@ type OpenChannel struct {
// received within this channel. // received within this channel.
TotalMSatReceived lnwire.MilliSatoshi 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 is the channel configuration for the local node.
LocalChanCfg ChannelConfig LocalChanCfg ChannelConfig
@@ -3322,7 +3331,8 @@ func putChanInfo(chanBucket kvdb.RwBucket, channel *OpenChannel) error {
channel.chanStatus, channel.FundingBroadcastHeight, channel.chanStatus, channel.FundingBroadcastHeight,
channel.NumConfsRequired, channel.ChannelFlags, channel.NumConfsRequired, channel.ChannelFlags,
channel.IdentityPub, channel.Capacity, channel.TotalMSatSent, channel.IdentityPub, channel.Capacity, channel.TotalMSatSent,
channel.TotalMSatReceived, channel.TotalMSatReceived, channel.InitialLocalBalance,
channel.InitialRemoteBalance,
); err != nil { ); err != nil {
return err return err
} }
@@ -3509,7 +3519,8 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error {
&channel.chanStatus, &channel.FundingBroadcastHeight, &channel.chanStatus, &channel.FundingBroadcastHeight,
&channel.NumConfsRequired, &channel.ChannelFlags, &channel.NumConfsRequired, &channel.ChannelFlags,
&channel.IdentityPub, &channel.Capacity, &channel.TotalMSatSent, &channel.IdentityPub, &channel.Capacity, &channel.TotalMSatSent,
&channel.TotalMSatReceived, &channel.TotalMSatReceived, &channel.InitialLocalBalance,
&channel.InitialRemoteBalance,
); err != nil { ); err != nil {
return err return err
} }
+2
View File
@@ -352,6 +352,8 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
Packager: NewChannelPackager(chanID), Packager: NewChannelPackager(chanID),
FundingTxn: channels.TestFundingTx, FundingTxn: channels.TestFundingTx,
ThawHeight: uint32(defaultPendingHeight), ThawHeight: uint32(defaultPendingHeight),
InitialLocalBalance: lnwire.MilliSatoshi(9000),
InitialRemoteBalance: lnwire.MilliSatoshi(3000),
} }
} }
+4 -2
View File
@@ -403,8 +403,10 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount,
FeePerKw: btcutil.Amount(commitFeePerKw), FeePerKw: btcutil.Amount(commitFeePerKw),
CommitFee: commitFee, CommitFee: commitFee,
}, },
ThawHeight: thawHeight, ThawHeight: thawHeight,
Db: wallet.Cfg.Database, Db: wallet.Cfg.Database,
InitialLocalBalance: ourBalance,
InitialRemoteBalance: theirBalance,
}, },
pushMSat: pushMSat, pushMSat: pushMSat,
pendingChanID: pendingChanID, pendingChanID: pendingChanID,