Skip to content

Commit

Permalink
Merge pull request #1213 from halseth/fail-channel
Browse files Browse the repository at this point in the history
[htlcswitch] Optionally force close channel on link failure
  • Loading branch information
Roasbeef committed May 26, 2018
2 parents 42de440 + 4dfb454 commit dd2859d
Show file tree
Hide file tree
Showing 11 changed files with 864 additions and 166 deletions.
13 changes: 8 additions & 5 deletions contractcourt/channel_arbitrator.go
Expand Up @@ -85,8 +85,10 @@ type ChannelArbitratorConfig struct {

// ForceCloseChan should force close the contract that this attendant
// is watching over. We'll use this when we decide that we need to go
// to chain. The returned summary contains all items needed to
// eventually resolve all outputs on chain.
// to chain. It should in addition tell the switch to remove the
// corresponding link, such that we won't accept any new updates. The
// returned summary contains all items needed to eventually resolve all
// outputs on chain.
ForceCloseChan func() (*lnwallet.LocalForceCloseSummary, error)

// MarkCommitmentBroadcasted should mark the channel as the commitment
Expand Down Expand Up @@ -434,9 +436,10 @@ func (c *ChannelArbitrator) stateStep(triggerHeight uint32,
// Now that we have all the actions decided for the set of
// HTLC's, we'll broadcast the commitment transaction, and
// signal the link to exit.
//
// TODO(roasbeef): need to report to switch that channel is
// inactive, should close link

// We'll tell the switch that it should remove the link for
// this channel, in addition to fetching the force close
// summary needed to close this channel on chain.
closeSummary, err := c.cfg.ForceCloseChan()
if err != nil {
log.Errorf("ChannelArbitrator(%v): unable to "+
Expand Down
5 changes: 5 additions & 0 deletions htlcswitch/hodl/config.go
Expand Up @@ -21,6 +21,8 @@ type Config struct {
FailOutgoing bool `long:"fail-outgoing" description:"Instructs the node to drop outgoing FAILs before applying them to the channel state"`

Commit bool `long:"commit" description:"Instructs the node to add HTLCs to its local commitment state and to open circuits for any ADDs, but abort before committing the changes"`

BogusSettle bool `long:"bogus-settle" description:"Instructs the node to settle back any incoming HTLC with a bogus preimage"`
}

// Mask extracts the flags specified in the configuration, composing a Mask from
Expand Down Expand Up @@ -52,6 +54,9 @@ func (c *Config) Mask() Mask {
if c.Commit {
flags = append(flags, Commit)
}
if c.BogusSettle {
flags = append(flags, BogusSettle)
}

// NOTE: The value returned here will only honor the configuration if
// the debug build flag is present. In production, this method always
Expand Down
8 changes: 8 additions & 0 deletions htlcswitch/hodl/flags.go
Expand Up @@ -51,6 +51,10 @@ const (
// Commit drops all HTLC after any outgoing circuits have been
// opened, but before the in-memory commitment state is persisted.
Commit

// BogusSettle attempts to settle back any incoming HTLC for which we
// are the exit node with a bogus preimage.
BogusSettle
)

// String returns a human-readable identifier for a given Flag.
Expand All @@ -72,6 +76,8 @@ func (f Flag) String() string {
return "FailOutgoing"
case Commit:
return "Commit"
case BogusSettle:
return "BogusSettle"
default:
return "UnknownHodlFlag"
}
Expand All @@ -98,6 +104,8 @@ func (f Flag) Warning() string {
msg = "will not update channel state with downstream FAIL"
case Commit:
msg = "will not commit pending channel updates"
case BogusSettle:
msg = "will settle HTLC with bogus preimage"
default:
msg = "incorrect hodl flag usage"
}
Expand Down
2 changes: 2 additions & 0 deletions htlcswitch/hodl/mask_test.go
Expand Up @@ -67,6 +67,7 @@ var hodlMaskTests = []struct {
hodl.SettleOutgoing,
hodl.FailOutgoing,
hodl.Commit,
hodl.BogusSettle,
),
flags: map[hodl.Flag]struct{}{
hodl.ExitSettle: {},
Expand All @@ -77,6 +78,7 @@ var hodlMaskTests = []struct {
hodl.SettleOutgoing: {},
hodl.FailOutgoing: {},
hodl.Commit: {},
hodl.BogusSettle: {},
},
},
}
Expand Down
4 changes: 0 additions & 4 deletions htlcswitch/interfaces.go
Expand Up @@ -130,10 +130,6 @@ type Peer interface {

// PubKey returns the serialize public key of the source peer.
PubKey() [33]byte

// Disconnect disconnects with peer if we have error which we can't
// properly handle.
Disconnect(reason error)
}

// ForwardingLog is an interface that represents a time series database which
Expand Down

0 comments on commit dd2859d

Please sign in to comment.