github.com/decred/dcrlnd@v0.7.6/netann/channel_state.go (about)

     1  package netann
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/decred/dcrd/wire"
     7  )
     8  
     9  // ChanStatus is a type that enumerates the possible states a ChanStatusManager
    10  // tracks for its known channels.
    11  type ChanStatus uint8
    12  
    13  const (
    14  	// ChanStatusEnabled indicates that the channel's last announcement has
    15  	// the disabled bit cleared.
    16  	ChanStatusEnabled ChanStatus = iota
    17  
    18  	// ChanStatusPendingDisabled indicates that the channel's last
    19  	// announcement has the disabled bit cleared, but that the channel was
    20  	// detected in an inactive state. Channels in this state will have a
    21  	// disabling announcement sent after the ChanInactiveTimeout expires
    22  	// from the time of the first detection--unless the channel is
    23  	// explicitly reenabled before the disabling occurs.
    24  	ChanStatusPendingDisabled
    25  
    26  	// ChanStatusDisabled indicates that the channel's last announcement has
    27  	// the disabled bit set.
    28  	ChanStatusDisabled
    29  
    30  	// ChanStatusManuallyDisabled indicates that the channel's last
    31  	// announcement had the disabled bit set, and that a user manually
    32  	// requested disabling the channel. Channels in this state will ignore
    33  	// automatic / background attempts to re-enable the channel.
    34  	//
    35  	// Note that there's no corresponding ChanStatusManuallyEnabled state
    36  	// because even if a user manually requests enabling a channel, we still
    37  	// DO want to allow automatic / background processes to disable it.
    38  	// Otherwise, the network might be cluttered with channels that are
    39  	// advertised as enabled, but don't actually work or even exist.
    40  	ChanStatusManuallyDisabled
    41  )
    42  
    43  // ChannelState describes the ChanStatusManager's view of a channel, and
    44  // describes the current state the channel's disabled status on the network.
    45  type ChannelState struct {
    46  	// Status is the channel's current ChanStatus from the POV of the
    47  	// ChanStatusManager.
    48  	Status ChanStatus
    49  
    50  	// SendDisableTime is the earliest time at which the ChanStatusManager
    51  	// will passively send a new disable announcement on behalf of this
    52  	// channel.
    53  	//
    54  	// NOTE: This field is only non-zero if status is
    55  	// ChanStatusPendingDisabled.
    56  	SendDisableTime time.Time
    57  }
    58  
    59  // channelStates is a map of channel outpoints to their channelState. All
    60  // changes made after setting an entry initially should be made using receiver
    61  // methods below.
    62  type channelStates map[wire.OutPoint]ChannelState
    63  
    64  // markEnabled creates a channelState using ChanStatusEnabled.
    65  func (s *channelStates) markEnabled(outpoint wire.OutPoint) {
    66  	(*s)[outpoint] = ChannelState{
    67  		Status: ChanStatusEnabled,
    68  	}
    69  }
    70  
    71  // markDisabled creates a channelState using ChanStatusDisabled.
    72  func (s *channelStates) markDisabled(outpoint wire.OutPoint) {
    73  	(*s)[outpoint] = ChannelState{
    74  		Status: ChanStatusDisabled,
    75  	}
    76  }
    77  
    78  // markManuallyDisabled creates a channelState using
    79  // ChanStatusManuallyDisabled.
    80  func (s *channelStates) markManuallyDisabled(outpoint wire.OutPoint) {
    81  	(*s)[outpoint] = ChannelState{
    82  		Status: ChanStatusManuallyDisabled,
    83  	}
    84  }
    85  
    86  // markPendingDisabled creates a channelState using ChanStatusPendingDisabled
    87  // and sets the ChannelState's SendDisableTime to sendDisableTime.
    88  func (s *channelStates) markPendingDisabled(outpoint wire.OutPoint,
    89  	sendDisableTime time.Time) {
    90  
    91  	(*s)[outpoint] = ChannelState{
    92  		Status:          ChanStatusPendingDisabled,
    93  		SendDisableTime: sendDisableTime,
    94  	}
    95  }