htlcswitch/hodl: add flag BogusSettle

This commit adds a new hodl flag "BogusSettle" which will be used to
emulate a node trying to settle back an incoming HTLC with a fake
preimage.
This commit is contained in:
Johan T. Halseth 2018-05-18 13:59:11 +02:00
parent 88670175c7
commit 71a1aae417
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 15 additions and 0 deletions

@ -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"` 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"` 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 // Mask extracts the flags specified in the configuration, composing a Mask from
@ -52,6 +54,9 @@ func (c *Config) Mask() Mask {
if c.Commit { if c.Commit {
flags = append(flags, Commit) flags = append(flags, Commit)
} }
if c.BogusSettle {
flags = append(flags, BogusSettle)
}
// NOTE: The value returned here will only honor the configuration if // NOTE: The value returned here will only honor the configuration if
// the debug build flag is present. In production, this method always // the debug build flag is present. In production, this method always

@ -51,6 +51,10 @@ const (
// Commit drops all HTLC after any outgoing circuits have been // Commit drops all HTLC after any outgoing circuits have been
// opened, but before the in-memory commitment state is persisted. // opened, but before the in-memory commitment state is persisted.
Commit 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. // String returns a human-readable identifier for a given Flag.
@ -72,6 +76,8 @@ func (f Flag) String() string {
return "FailOutgoing" return "FailOutgoing"
case Commit: case Commit:
return "Commit" return "Commit"
case BogusSettle:
return "BogusSettle"
default: default:
return "UnknownHodlFlag" return "UnknownHodlFlag"
} }
@ -98,6 +104,8 @@ func (f Flag) Warning() string {
msg = "will not update channel state with downstream FAIL" msg = "will not update channel state with downstream FAIL"
case Commit: case Commit:
msg = "will not commit pending channel updates" msg = "will not commit pending channel updates"
case BogusSettle:
msg = "will settle HTLC with bogus preimage"
default: default:
msg = "incorrect hodl flag usage" msg = "incorrect hodl flag usage"
} }

@ -67,6 +67,7 @@ var hodlMaskTests = []struct {
hodl.SettleOutgoing, hodl.SettleOutgoing,
hodl.FailOutgoing, hodl.FailOutgoing,
hodl.Commit, hodl.Commit,
hodl.BogusSettle,
), ),
flags: map[hodl.Flag]struct{}{ flags: map[hodl.Flag]struct{}{
hodl.ExitSettle: {}, hodl.ExitSettle: {},
@ -77,6 +78,7 @@ var hodlMaskTests = []struct {
hodl.SettleOutgoing: {}, hodl.SettleOutgoing: {},
hodl.FailOutgoing: {}, hodl.FailOutgoing: {},
hodl.Commit: {}, hodl.Commit: {},
hodl.BogusSettle: {},
}, },
}, },
} }