Skip to content

Commit

Permalink
channeldb: add prefix naming to ChannelStatus enum variables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Roasbeef committed Jan 29, 2019
1 parent f4054d2 commit f57f40e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
61 changes: 34 additions & 27 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,37 +293,44 @@ type ChannelCommitment struct {
type ChannelStatus uint8

var (
// Default is the normal state of an open channel.
Default ChannelStatus

// Borked indicates that the channel has entered an irreconcilable
// state, triggered by a state desynchronization or channel breach.
// Channels in this state should never be added to the htlc switch.
Borked ChannelStatus = 1

// CommitmentBroadcasted indicates that a commitment for this channel
// has been broadcasted.
CommitmentBroadcasted ChannelStatus = 1 << 1

// LocalDataLoss indicates that we have lost channel state for this
// channel, and broadcasting our latest commitment might be considered
// a breach.
// ChanStatusDefault is the normal state of an open channel.
ChanStatusDefault ChannelStatus

// ChanStatusBorked indicates that the channel has entered an
// irreconcilable state, triggered by a state desynchronization or
// channel breach. Channels in this state should never be added to the
// htlc switch.
ChanStatusBorked ChannelStatus = 1

// ChanStatusCommitBroadcasted indicates that a commitment for this
// channel has been broadcasted.
ChanStatusCommitBroadcasted ChannelStatus = 1 << 1

// ChanStatusLocalDataLoss indicates that we have lost channel state
// for this channel, and broadcasting our latest commitment might be
// considered a breach.
//
// TODO(halseh): actually enforce that we are not force closing such a
// 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.
func (c ChannelStatus) String() string {
switch c {
case Default:
return "Default"
case Borked:
return "Borked"
case CommitmentBroadcasted:
return "CommitmentBroadcasted"
case LocalDataLoss:
return "LocalDataLoss"
case ChanStatusDefault:
return "ChanStatusDefault"
case ChanStatusBorked:
return "ChanStatusBorked"
case ChanStatusCommitBroadcasted:
return "ChanStatusCommitBroadcasted"
case ChanStatusLocalDataLoss:
return "ChanStatusLocalDataLoss"
default:
return fmt.Sprintf("Unknown(%08b)", c)
}
Expand Down Expand Up @@ -664,7 +671,7 @@ func (c *OpenChannel) MarkDataLoss(commitPoint *btcec.PublicKey) error {

// Add status LocalDataLoss to the existing bitvector found in
// the DB.
status = channel.chanStatus | LocalDataLoss
status = channel.chanStatus | ChanStatusLocalDataLoss
channel.chanStatus = status

var b bytes.Buffer
Expand Down Expand Up @@ -730,7 +737,7 @@ func (c *OpenChannel) MarkBorked() error {
c.Lock()
defer c.Unlock()

return c.putChanStatus(Borked)
return c.putChanStatus(ChanStatusBorked)
}

// MarkCommitmentBroadcasted marks the channel as a commitment transaction has
Expand All @@ -740,7 +747,7 @@ func (c *OpenChannel) MarkCommitmentBroadcasted() error {
c.Lock()
defer c.Unlock()

return c.putChanStatus(CommitmentBroadcasted)
return c.putChanStatus(ChanStatusCommitBroadcasted)
}

func (c *OpenChannel) putChanStatus(status ChannelStatus) error {
Expand Down
2 changes: 1 addition & 1 deletion channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,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() != ChanStatusDefault

// Only include it if we requested
// channels with the same waitingClose
Expand Down
2 changes: 1 addition & 1 deletion peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,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.ChanStatusDefault {
peerLog.Warnf("ChannelPoint(%v) has status %v, won't "+
"start.", chanPoint, dbChan.ChanStatus())
continue
Expand Down

0 comments on commit f57f40e

Please sign in to comment.