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:
Johan T. Halseth 2018-07-31 11:31:28 +02:00
parent eed052eba5
commit ea6aca26a5
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 20 additions and 12 deletions

@ -8,14 +8,14 @@ import (
"net"
"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/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/coreos/bbolt"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/shachain"
)
var (
@ -354,9 +354,9 @@ type OpenChannel struct {
// negotiate fees, or close the channel.
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.
ChanStatus ChannelStatus
chanStatus ChannelStatus
// FundingBroadcastHeight is the height in which the funding
// transaction was broadcast. This value can be used by higher level
@ -468,6 +468,14 @@ func (c *OpenChannel) ShortChanID() lnwire.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
// value observed on disk.
func (c *OpenChannel) RefreshShortChanID() error {
@ -705,7 +713,7 @@ func (c *OpenChannel) putChanStatus(status ChannelStatus) error {
return err
}
channel.ChanStatus = status
channel.chanStatus = status
return putOpenChannel(chanBucket, channel)
}); 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.
c.ChanStatus = status
c.chanStatus = status
return nil
}
@ -2067,7 +2075,7 @@ func putChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
if err := WriteElements(&w,
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
channel.ShortChannelID, channel.IsPending, channel.IsInitiator,
channel.ChanStatus, channel.FundingBroadcastHeight,
channel.chanStatus, channel.FundingBroadcastHeight,
channel.NumConfsRequired, channel.ChannelFlags,
channel.IdentityPub, channel.Capacity, channel.TotalMSatSent,
channel.TotalMSatReceived,
@ -2177,7 +2185,7 @@ func fetchChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
if err := ReadElements(r,
&channel.ChanType, &channel.ChainHash, &channel.FundingOutpoint,
&channel.ShortChannelID, &channel.IsPending, &channel.IsInitiator,
&channel.ChanStatus, &channel.FundingBroadcastHeight,
&channel.chanStatus, &channel.FundingBroadcastHeight,
&channel.NumConfsRequired, &channel.ChannelFlags,
&channel.IdentityPub, &channel.Capacity, &channel.TotalMSatSent,
&channel.TotalMSatReceived,

@ -456,7 +456,7 @@ func fetchChannels(d *DB, pending, waitingClose bool) ([]*OpenChannel, error) {
// than Default, then it means it is
// waiting to be closed.
channelWaitingClose :=
channel.ChanStatus != Default
channel.ChanStatus() != Default
// Only include it if we requested
// channels with the same waitingClose

@ -333,7 +333,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
// Skip adding any permanently irreconcilable channels to the
// htlcswitch.
if dbChan.ChanStatus != channeldb.Default {
if dbChan.ChanStatus() != channeldb.Default {
peerLog.Warnf("ChannelPoint(%v) has status %v, won't "+
"start.", chanPoint, dbChan.ChanStatus)
lnChan.Stop()