From 36956d390fa77906cffb91eea50ac39403aad35e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 5 Dec 2017 17:48:28 -0800 Subject: [PATCH] htlcswitch: add new method to the ChannelLink interface, EligibleToForward MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we add a new method to the ChanneLink interface: EligibleToForward. This method allows a link to be added to the switch, but in an intermediate state which indicates that it isn’t yet ready to forward any incoming HTLC’s. --- htlcswitch/interfaces.go | 7 +++++++ htlcswitch/link.go | 8 ++++++++ htlcswitch/mock.go | 1 + 3 files changed, 16 insertions(+) diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index 8f1a48f7..6ba43466 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -85,6 +85,13 @@ type ChannelLink interface { // the channel link opened. Peer() Peer + // EligibleToForward returns a bool indicating if the channel is able + // to actively accept requests to forward HTLC's. A channel may be + // active, but not able to forward HTLC's if it hasn't yet finalized + // the pre-channel operation protocol with the remote peer. The switch + // will use this function in forwarding decisions accordingly. + EligibleToForward() bool + // Start/Stop are used to initiate the start/stop of the channel link // functioning. Start() error diff --git a/htlcswitch/link.go b/htlcswitch/link.go index bc0556cc..f96acec5 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -292,6 +292,14 @@ func (l *channelLink) Stop() { l.cfg.BlockEpochs.Cancel() } +// EligibleToForward returns a bool indicating if the channel is able to +// actively accept requests to forward HTLC's. We're able to forward HTLC's if +// we know the remote party's next revocation point. Otherwise, we can't +// initiate new channel state. +func (l *channelLink) EligibleToForward() bool { + return l.channel.RemoteNextRevocation() != nil +} + // sampleNetworkFee samples the current fee rate on the network to get into the // chain in a timely manner. The returned value is expressed in fee-per-kw, as // this is the native rate used when computing the fee for commitment diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 8721ccb3..73e2c214 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -430,6 +430,7 @@ func (f *mockChannelLink) Bandwidth() lnwire.MilliSatoshi { return 99999999 func (f *mockChannelLink) Peer() Peer { return f.peer } func (f *mockChannelLink) Start() error { return nil } func (f *mockChannelLink) Stop() {} +func (f *mockChannelLink) EligibleToForward() bool { return true } var _ ChannelLink = (*mockChannelLink)(nil)