mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-20 21:30:06 +02:00
multi: export channel status field in migration25
Previously, in `migration25.OpenChannel`, there was a private field `chanStatus` used to keep track of the channel status. The following migrations, `migration26` and `migration27` also have their own `OpenChannel` defined, with `migration26` inherited from `migration25`, and `migration27` inherited from `migration26`. The private field `chanStatus`, however, is NOT inherited and each of the migrations uses its own. This is fine for reading and writing as, under the hood, the `chanStatus` is just a `uint8` value. Because each migration has its own fetcher and putter, it can safely access its private field to read and write it correctly. The issue pops up when we use the method `migration25.FundingTxPresent()`. Because it's evaluating its channel status using its own private field `chanStatus`, this field would always be the default value(`ChanStatusDefault`), leading the statement `!c.hasChanStatus(ChanStatusRestored)` to always be true. Thus a restored channel will be mistakenly considered to have funding tx present, causing failures in reading the channel info in the following migrations. We fix this by exporting the `ChanStatus` field so its value can be set by following migrations.
This commit is contained in:
@@ -277,9 +277,13 @@ type OpenChannel struct {
|
||||
// ChanType denotes which type of channel this is.
|
||||
ChanType ChannelType
|
||||
|
||||
// chanStatus is the current status of this channel. If it is not in
|
||||
// ChanStatus is the current status of this channel. If it is not in
|
||||
// the state Default, it should not be used for forwarding payments.
|
||||
chanStatus ChannelStatus
|
||||
//
|
||||
// NOTE: In `channeldb.OpenChannel`, this field is private. We choose
|
||||
// to export this private field such that following migrations can
|
||||
// access this field directly.
|
||||
ChanStatus ChannelStatus
|
||||
|
||||
// InitialLocalBalance is the balance we have during the channel
|
||||
// opening. When we are not the initiator, this value represents the
|
||||
@@ -320,10 +324,10 @@ func (c *OpenChannel) hasChanStatus(status ChannelStatus) bool {
|
||||
// Special case ChanStatusDefualt since it isn't actually flag, but a
|
||||
// particular combination (or lack-there-of) of flags.
|
||||
if status == ChanStatusDefault {
|
||||
return c.chanStatus == ChanStatusDefault
|
||||
return c.ChanStatus == ChanStatusDefault
|
||||
}
|
||||
|
||||
return c.chanStatus&status == status
|
||||
return c.ChanStatus&status == status
|
||||
}
|
||||
|
||||
// FundingTxPresent returns true if expect the funding transcation to be found
|
||||
@@ -361,7 +365,7 @@ func fetchChanInfo(chanBucket kvdb.RBucket, c *OpenChannel, legacy bool) error {
|
||||
}
|
||||
|
||||
c.ChanType = ChannelType(chanType)
|
||||
c.chanStatus = ChannelStatus(chanStatus)
|
||||
c.ChanStatus = ChannelStatus(chanStatus)
|
||||
|
||||
// If this is not the legacy format, we need to read the extra two new
|
||||
// fields.
|
||||
@@ -432,7 +436,7 @@ func putChanInfo(chanBucket kvdb.RwBucket, c *OpenChannel, legacy bool) error {
|
||||
if err := mig.WriteElements(&w,
|
||||
mig.ChannelType(c.ChanType), c.ChainHash, c.FundingOutpoint,
|
||||
c.ShortChannelID, c.IsPending, c.IsInitiator,
|
||||
mig.ChannelStatus(c.chanStatus), c.FundingBroadcastHeight,
|
||||
mig.ChannelStatus(c.ChanStatus), c.FundingBroadcastHeight,
|
||||
c.NumConfsRequired, c.ChannelFlags,
|
||||
c.IdentityPub, c.Capacity, c.TotalMSatSent,
|
||||
c.TotalMSatReceived,
|
||||
|
Reference in New Issue
Block a user