From 74322a99bedf301e14f787ca6ee8b264af209d81 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 31 Aug 2017 18:30:11 -0700 Subject: [PATCH] config+htlclink+peer: htlc hodl mode! This commit adds a new debug mode for lnd called hodlhtlc. This mode instructs a node to refrain from settling incoming HTLCs for which it is the exit node. We plan to use this in testing to more precisely control the states a node can take during execution. --- config.go | 1 + htlcswitch/link.go | 13 +++++++++++++ peer.go | 2 ++ 3 files changed, 16 insertions(+) diff --git a/config.go b/config.go index 3e4ea4ad..8879d62c 100644 --- a/config.go +++ b/config.go @@ -113,6 +113,7 @@ type config struct { RPCPort int `long:"rpcport" description:"The port for the rpc server"` RESTPort int `long:"restport" description:"The port for the REST server"` DebugHTLC bool `long:"debughtlc" description:"Activate the debug htlc mode. With the debug HTLC mode, all payments sent use a pre-determined R-Hash. Additionally, all HTLCs sent to a node with the debug HTLC R-Hash are immediately settled in the next available state transition."` + HodlHTLC bool `long:"hodlhtlc" description:"Activate the hodl HTLC mode. With hodl HTLC mode, all incoming HTLCs will be accepted by the receiving node, but no attempt will be made to settle the payment with the sender."` MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."` Litecoin *chainConfig `group:"Litecoin" namespace:"litecoin"` diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 3c253f91..4cd62592 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -132,6 +132,12 @@ type ChannelLinkConfig struct { // with the debug htlc R-Hash are immediately settled in the next // available state transition. DebugHTLC bool + + // HodlHTLC should be active if you want this node to refrain from + // settling all incoming HTLCs with the sender if it finds itself to be + // the exit node. + // NOTE: HodlHTLC should be active in conjunction with DebugHTLC. + HodlHTLC bool } // channelLink is the service which drives a channel's commitment update @@ -1176,6 +1182,13 @@ func (l *channelLink) processLockedInHtlcs( continue } + if l.cfg.DebugHTLC && l.cfg.HodlHTLC { + log.Warnf("hodl HTLC mode enabled, " + + "will not attempt to settle " + + "HTLC with sender") + continue + } + preimage := invoice.Terms.PaymentPreimage logIndex, err := l.channel.SettleHTLC(preimage) if err != nil { diff --git a/peer.go b/peer.go index 0e8011a2..600fbce1 100644 --- a/peer.go +++ b/peer.go @@ -368,6 +368,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { p.PubKey(), lnChan.ShortChanID()), SettledContracts: p.server.breachArbiter.settledContracts, DebugHTLC: cfg.DebugHTLC, + HodlHTLC: cfg.HodlHTLC, Registry: p.server.invoices, Switch: p.server.htlcSwitch, FwrdingPolicy: *forwardingPolicy, @@ -1018,6 +1019,7 @@ out: p.PubKey(), newChanReq.channel.ShortChanID()), SettledContracts: p.server.breachArbiter.settledContracts, DebugHTLC: cfg.DebugHTLC, + HodlHTLC: cfg.HodlHTLC, Registry: p.server.invoices, Switch: p.server.htlcSwitch, FwrdingPolicy: p.server.cc.routingPolicy,