github.com/decred/dcrlnd@v0.7.6/htlcswitch/hodl/flags.go (about)

     1  package hodl
     2  
     3  import "fmt"
     4  
     5  // MaskNone represents the empty Mask, in which no breakpoints are
     6  // active.
     7  const MaskNone = Mask(0)
     8  
     9  type (
    10  	// Flag represents a single breakpoint where an HTLC should be dropped
    11  	// during forwarding. Flags can be composed into a Mask to express more
    12  	// complex combinations.
    13  	Flag uint32
    14  
    15  	// Mask is a bitvector combining multiple Flags that can be queried to
    16  	// see which breakpoints are active.
    17  	Mask uint32
    18  )
    19  
    20  const (
    21  	// ExitSettle drops an incoming ADD for which we are the exit node,
    22  	// before processing in the link.
    23  	ExitSettle Flag = 1 << iota
    24  
    25  	// AddIncoming drops an incoming ADD before processing if we are not
    26  	// the exit node.
    27  	AddIncoming
    28  
    29  	// SettleIncoming drops an incoming SETTLE before processing if we
    30  	// are not the exit node.
    31  	SettleIncoming
    32  
    33  	// FailIncoming drops an incoming FAIL before processing if we are
    34  	// not the exit node.
    35  	FailIncoming
    36  
    37  	// TODO(conner): add  modes for switch breakpoints
    38  
    39  	// AddOutgoing drops an outgoing ADD before it is added to the
    40  	// in-memory commitment state of the link.
    41  	AddOutgoing
    42  
    43  	// SettleOutgoing drops an SETTLE before it is added to the
    44  	// in-memory commitment state of the link.
    45  	SettleOutgoing
    46  
    47  	// FailOutgoing drops an outgoing FAIL before is is added to the
    48  	// in-memory commitment state of the link.
    49  	FailOutgoing
    50  
    51  	// Commit drops all HTLC after any outgoing circuits have been
    52  	// opened, but before the in-memory commitment state is persisted.
    53  	Commit
    54  
    55  	// BogusSettle attempts to settle back any incoming HTLC for which we
    56  	// are the exit node with a bogus preimage.
    57  	BogusSettle
    58  )
    59  
    60  // String returns a human-readable identifier for a given Flag.
    61  func (f Flag) String() string {
    62  	switch f {
    63  	case ExitSettle:
    64  		return "ExitSettle"
    65  	case AddIncoming:
    66  		return "AddIncoming"
    67  	case SettleIncoming:
    68  		return "SettleIncoming"
    69  	case FailIncoming:
    70  		return "FailIncoming"
    71  	case AddOutgoing:
    72  		return "AddOutgoing"
    73  	case SettleOutgoing:
    74  		return "SettleOutgoing"
    75  	case FailOutgoing:
    76  		return "FailOutgoing"
    77  	case Commit:
    78  		return "Commit"
    79  	case BogusSettle:
    80  		return "BogusSettle"
    81  	default:
    82  		return "UnknownHodlFlag"
    83  	}
    84  }
    85  
    86  // Warning generates a warning message to log if a particular breakpoint is
    87  // triggered during execution.
    88  func (f Flag) Warning() string {
    89  	var msg string
    90  	switch f {
    91  	case ExitSettle:
    92  		msg = "will not attempt to settle ADD with sender"
    93  	case AddIncoming:
    94  		msg = "will not attempt to forward ADD to switch"
    95  	case SettleIncoming:
    96  		msg = "will not attempt to forward SETTLE to switch"
    97  	case FailIncoming:
    98  		msg = "will not attempt to forward FAIL to switch"
    99  	case AddOutgoing:
   100  		msg = "will not update channel state with downstream ADD"
   101  	case SettleOutgoing:
   102  		msg = "will not update channel state with downstream SETTLE"
   103  	case FailOutgoing:
   104  		msg = "will not update channel state with downstream FAIL"
   105  	case Commit:
   106  		msg = "will not commit pending channel updates"
   107  	case BogusSettle:
   108  		msg = "will settle HTLC with bogus preimage"
   109  	default:
   110  		msg = "incorrect hodl flag usage"
   111  	}
   112  
   113  	return fmt.Sprintf("%s mode enabled -- %s", f, msg)
   114  }
   115  
   116  // Mask returns the Mask consisting solely of this Flag.
   117  func (f Flag) Mask() Mask {
   118  	return Mask(f)
   119  }