channeldb: add prefix naming to ChannelStatus enum variables

In this commit, we add a prefix naming scheme to the ChannelStatus enum
variables. We do this as it enables outside callers to more easily
identify each individual enum variable as a part of the greater
enum-like type.
This commit is contained in:
Olaoluwa Osuntokun 2018-12-09 19:21:34 -08:00
parent f4054d2a66
commit f57f40e767
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2
3 changed files with 33 additions and 26 deletions

@ -293,37 +293,44 @@ type ChannelCommitment struct {
type ChannelStatus uint8 type ChannelStatus uint8
var ( var (
// Default is the normal state of an open channel. // ChanStatusDefault is the normal state of an open channel.
Default ChannelStatus ChanStatusDefault ChannelStatus
// Borked indicates that the channel has entered an irreconcilable // ChanStatusBorked indicates that the channel has entered an
// state, triggered by a state desynchronization or channel breach. // irreconcilable state, triggered by a state desynchronization or
// Channels in this state should never be added to the htlc switch. // channel breach. Channels in this state should never be added to the
Borked ChannelStatus = 1 // htlc switch.
ChanStatusBorked ChannelStatus = 1
// CommitmentBroadcasted indicates that a commitment for this channel // ChanStatusCommitBroadcasted indicates that a commitment for this
// has been broadcasted. // channel has been broadcasted.
CommitmentBroadcasted ChannelStatus = 1 << 1 ChanStatusCommitBroadcasted ChannelStatus = 1 << 1
// LocalDataLoss indicates that we have lost channel state for this // ChanStatusLocalDataLoss indicates that we have lost channel state
// channel, and broadcasting our latest commitment might be considered // for this channel, and broadcasting our latest commitment might be
// a breach. // considered a breach.
//
// TODO(halseh): actually enforce that we are not force closing such a // TODO(halseh): actually enforce that we are not force closing such a
// channel. // channel.
LocalDataLoss ChannelStatus = 1 << 2 ChanStatusLocalDataLoss ChannelStatus = 1 << 2
// ChanStatusRestored is a status flag that signals that the chanel has
// been restored, and doesn't have all the fields a typical channel
// will have.
ChanStatusRestored ChannelStatus = 1 << 3
) )
// String returns a human-readable representation of the ChannelStatus. // String returns a human-readable representation of the ChannelStatus.
func (c ChannelStatus) String() string { func (c ChannelStatus) String() string {
switch c { switch c {
case Default: case ChanStatusDefault:
return "Default" return "ChanStatusDefault"
case Borked: case ChanStatusBorked:
return "Borked" return "ChanStatusBorked"
case CommitmentBroadcasted: case ChanStatusCommitBroadcasted:
return "CommitmentBroadcasted" return "ChanStatusCommitBroadcasted"
case LocalDataLoss: case ChanStatusLocalDataLoss:
return "LocalDataLoss" return "ChanStatusLocalDataLoss"
default: default:
return fmt.Sprintf("Unknown(%08b)", c) return fmt.Sprintf("Unknown(%08b)", c)
} }
@ -664,7 +671,7 @@ func (c *OpenChannel) MarkDataLoss(commitPoint *btcec.PublicKey) error {
// Add status LocalDataLoss to the existing bitvector found in // Add status LocalDataLoss to the existing bitvector found in
// the DB. // the DB.
status = channel.chanStatus | LocalDataLoss status = channel.chanStatus | ChanStatusLocalDataLoss
channel.chanStatus = status channel.chanStatus = status
var b bytes.Buffer var b bytes.Buffer
@ -730,7 +737,7 @@ func (c *OpenChannel) MarkBorked() error {
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
return c.putChanStatus(Borked) return c.putChanStatus(ChanStatusBorked)
} }
// MarkCommitmentBroadcasted marks the channel as a commitment transaction has // MarkCommitmentBroadcasted marks the channel as a commitment transaction has
@ -740,7 +747,7 @@ func (c *OpenChannel) MarkCommitmentBroadcasted() error {
c.Lock() c.Lock()
defer c.Unlock() defer c.Unlock()
return c.putChanStatus(CommitmentBroadcasted) return c.putChanStatus(ChanStatusCommitBroadcasted)
} }
func (c *OpenChannel) putChanStatus(status ChannelStatus) error { func (c *OpenChannel) putChanStatus(status ChannelStatus) error {

@ -531,7 +531,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() != ChanStatusDefault
// Only include it if we requested // Only include it if we requested
// channels with the same waitingClose // channels with the same waitingClose

@ -409,7 +409,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.ChanStatusDefault {
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())
continue continue