channeldb: make chanStatus unexported
Since the ChanStatus field can be changed from concurrent callers, we make it unexported and add the method ChanStatus() for safe retrieval.
This commit is contained in:
parent
eed052eba5
commit
ea6aca26a5
@ -8,14 +8,14 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/coreos/bbolt"
|
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/coreos/bbolt"
|
||||||
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -354,9 +354,9 @@ type OpenChannel struct {
|
|||||||
// negotiate fees, or close the channel.
|
// negotiate fees, or close the channel.
|
||||||
IsInitiator bool
|
IsInitiator bool
|
||||||
|
|
||||||
// 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.
|
// the state Default, it should not be used for forwarding payments.
|
||||||
ChanStatus ChannelStatus
|
chanStatus ChannelStatus
|
||||||
|
|
||||||
// FundingBroadcastHeight is the height in which the funding
|
// FundingBroadcastHeight is the height in which the funding
|
||||||
// transaction was broadcast. This value can be used by higher level
|
// transaction was broadcast. This value can be used by higher level
|
||||||
@ -468,6 +468,14 @@ func (c *OpenChannel) ShortChanID() lnwire.ShortChannelID {
|
|||||||
return c.ShortChannelID
|
return c.ShortChannelID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChanStatus returns the current ChannelStatus of this channel.
|
||||||
|
func (c *OpenChannel) ChanStatus() ChannelStatus {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
return c.chanStatus
|
||||||
|
}
|
||||||
|
|
||||||
// RefreshShortChanID updates the in-memory short channel ID using the latest
|
// RefreshShortChanID updates the in-memory short channel ID using the latest
|
||||||
// value observed on disk.
|
// value observed on disk.
|
||||||
func (c *OpenChannel) RefreshShortChanID() error {
|
func (c *OpenChannel) RefreshShortChanID() error {
|
||||||
@ -705,7 +713,7 @@ func (c *OpenChannel) putChanStatus(status ChannelStatus) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.ChanStatus = status
|
channel.chanStatus = status
|
||||||
|
|
||||||
return putOpenChannel(chanBucket, channel)
|
return putOpenChannel(chanBucket, channel)
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -713,7 +721,7 @@ func (c *OpenChannel) putChanStatus(status ChannelStatus) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the in-memory representation to keep it in sync with the DB.
|
// Update the in-memory representation to keep it in sync with the DB.
|
||||||
c.ChanStatus = status
|
c.chanStatus = status
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -2067,7 +2075,7 @@ func putChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
|||||||
if err := WriteElements(&w,
|
if err := WriteElements(&w,
|
||||||
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
|
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
|
||||||
channel.ShortChannelID, channel.IsPending, channel.IsInitiator,
|
channel.ShortChannelID, channel.IsPending, channel.IsInitiator,
|
||||||
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,
|
||||||
@ -2177,7 +2185,7 @@ func fetchChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
|||||||
if err := ReadElements(r,
|
if err := ReadElements(r,
|
||||||
&channel.ChanType, &channel.ChainHash, &channel.FundingOutpoint,
|
&channel.ChanType, &channel.ChainHash, &channel.FundingOutpoint,
|
||||||
&channel.ShortChannelID, &channel.IsPending, &channel.IsInitiator,
|
&channel.ShortChannelID, &channel.IsPending, &channel.IsInitiator,
|
||||||
&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,
|
||||||
|
@ -456,7 +456,7 @@ func fetchChannels(d *DB, pending, waitingClose bool) ([]*OpenChannel, error) {
|
|||||||
// than Default, then it means it is
|
// than Default, then it means it is
|
||||||
// waiting to be closed.
|
// waiting to be closed.
|
||||||
channelWaitingClose :=
|
channelWaitingClose :=
|
||||||
channel.ChanStatus != Default
|
channel.ChanStatus() != Default
|
||||||
|
|
||||||
// Only include it if we requested
|
// Only include it if we requested
|
||||||
// channels with the same waitingClose
|
// channels with the same waitingClose
|
||||||
|
2
peer.go
2
peer.go
@ -333,7 +333,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
|
|
||||||
// Skip adding any permanently irreconcilable channels to the
|
// Skip adding any permanently irreconcilable channels to the
|
||||||
// htlcswitch.
|
// htlcswitch.
|
||||||
if dbChan.ChanStatus != channeldb.Default {
|
if dbChan.ChanStatus() != channeldb.Default {
|
||||||
peerLog.Warnf("ChannelPoint(%v) has status %v, won't "+
|
peerLog.Warnf("ChannelPoint(%v) has status %v, won't "+
|
||||||
"start.", chanPoint, dbChan.ChanStatus)
|
"start.", chanPoint, dbChan.ChanStatus)
|
||||||
lnChan.Stop()
|
lnChan.Stop()
|
||||||
|
Loading…
Reference in New Issue
Block a user