From 5404348f5159e2223169d84807acc9d3fbd5048f Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 27 Sep 2019 16:21:34 +0200 Subject: [PATCH] htlcswitch: rename policy check functions --- htlcswitch/interfaces.go | 23 +++++++++++------------ htlcswitch/link.go | 28 ++++++++++++++-------------- htlcswitch/link_test.go | 18 +++++++++--------- htlcswitch/mock.go | 4 ++-- htlcswitch/switch.go | 4 ++-- 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index 5e162795..cd050856 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -100,22 +100,21 @@ type ChannelLink interface { // policy to govern if it an incoming HTLC should be forwarded or not. UpdateForwardingPolicy(ForwardingPolicy) - // HtlcSatifiesPolicy should return a nil error if the passed HTLC - // details satisfy the current forwarding policy fo the target link. - // Otherwise, a valid protocol failure message should be returned in - // order to signal to the source of the HTLC, the policy consistency - // issue. - HtlcSatifiesPolicy(payHash [32]byte, incomingAmt lnwire.MilliSatoshi, + // CheckHtlcForward should return a nil error if the passed HTLC details + // satisfy the current forwarding policy fo the target link. Otherwise, + // a valid protocol failure message should be returned in order to + // signal to the source of the HTLC, the policy consistency issue. + CheckHtlcForward(payHash [32]byte, incomingAmt lnwire.MilliSatoshi, amtToForward lnwire.MilliSatoshi, incomingTimeout, outgoingTimeout uint32, heightNow uint32) lnwire.FailureMessage - // HtlcSatifiesPolicyLocal should return a nil error if the passed HTLC - // details satisfy the current channel policy. Otherwise, a valid - // protocol failure message should be returned in order to signal the - // violation. This call is intended to be used for locally initiated - // payments for which there is no corresponding incoming htlc. - HtlcSatifiesPolicyLocal(payHash [32]byte, amt lnwire.MilliSatoshi, + // CheckHtlcTransit should return a nil error if the passed HTLC details + // satisfy the current channel policy. Otherwise, a valid protocol + // failure message should be returned in order to signal the violation. + // This call is intended to be used for locally initiated payments for + // which there is no corresponding incoming htlc. + CheckHtlcTransit(payHash [32]byte, amt lnwire.MilliSatoshi, timeout uint32, heightNow uint32) lnwire.FailureMessage // Bandwidth returns the amount of milli-satoshis which current link diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 5c5bdbde..46b58f17 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -2184,13 +2184,13 @@ func (l *channelLink) UpdateForwardingPolicy(newPolicy ForwardingPolicy) { l.cfg.FwrdingPolicy = newPolicy } -// HtlcSatifiesPolicy should return a nil error if the passed HTLC details -// satisfy the current forwarding policy fo the target link. Otherwise, a -// valid protocol failure message should be returned in order to signal to the -// source of the HTLC, the policy consistency issue. +// CheckHtlcForward should return a nil error if the passed HTLC details satisfy +// the current forwarding policy fo the target link. Otherwise, a valid +// protocol failure message should be returned in order to signal to the source +// of the HTLC, the policy consistency issue. // // NOTE: Part of the ChannelLink interface. -func (l *channelLink) HtlcSatifiesPolicy(payHash [32]byte, +func (l *channelLink) CheckHtlcForward(payHash [32]byte, incomingHtlcAmt, amtToForward lnwire.MilliSatoshi, incomingTimeout, outgoingTimeout uint32, heightNow uint32) lnwire.FailureMessage { @@ -2200,7 +2200,7 @@ func (l *channelLink) HtlcSatifiesPolicy(payHash [32]byte, l.RUnlock() // First check whether the outgoing htlc satisfies the channel policy. - err := l.htlcSatifiesPolicyOutgoing( + err := l.canSendHtlc( policy, payHash, amtToForward, outgoingTimeout, heightNow, ) if err != nil { @@ -2259,12 +2259,12 @@ func (l *channelLink) HtlcSatifiesPolicy(payHash [32]byte, return nil } -// HtlcSatifiesPolicyLocal should return a nil error if the passed HTLC details -// satisfy the current channel policy. Otherwise, a valid protocol failure -// message should be returned in order to signal the violation. This call is -// intended to be used for locally initiated payments for which there is no -// corresponding incoming htlc. -func (l *channelLink) HtlcSatifiesPolicyLocal(payHash [32]byte, +// CheckHtlcTransit should return a nil error if the passed HTLC details satisfy the +// current channel policy. Otherwise, a valid protocol failure message should +// be returned in order to signal the violation. This call is intended to be +// used for locally initiated payments for which there is no corresponding +// incoming htlc. +func (l *channelLink) CheckHtlcTransit(payHash [32]byte, amt lnwire.MilliSatoshi, timeout uint32, heightNow uint32) lnwire.FailureMessage { @@ -2272,14 +2272,14 @@ func (l *channelLink) HtlcSatifiesPolicyLocal(payHash [32]byte, policy := l.cfg.FwrdingPolicy l.RUnlock() - return l.htlcSatifiesPolicyOutgoing( + return l.canSendHtlc( policy, payHash, amt, timeout, heightNow, ) } // htlcSatifiesPolicyOutgoing checks whether the given htlc parameters satisfy // the channel's amount and time lock constraints. -func (l *channelLink) htlcSatifiesPolicyOutgoing(policy ForwardingPolicy, +func (l *channelLink) canSendHtlc(policy ForwardingPolicy, payHash [32]byte, amt lnwire.MilliSatoshi, timeout uint32, heightNow uint32) lnwire.FailureMessage { diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 60d05eca..b70b966f 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -5396,9 +5396,9 @@ func TestForwardingAsymmetricTimeLockPolicies(t *testing.T) { } } -// TestHtlcSatisfyPolicy tests that a link is properly enforcing the HTLC +// TestCheckHtlcForward tests that a link is properly enforcing the HTLC // forwarding policy. -func TestHtlcSatisfyPolicy(t *testing.T) { +func TestCheckHtlcForward(t *testing.T) { fetchLastChannelUpdate := func(lnwire.ShortChannelID) ( *lnwire.ChannelUpdate, error) { @@ -5423,7 +5423,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) { var hash [32]byte t.Run("satisfied", func(t *testing.T) { - result := link.HtlcSatifiesPolicy(hash, 1500, 1000, + result := link.CheckHtlcForward(hash, 1500, 1000, 200, 150, 0) if result != nil { t.Fatalf("expected policy to be satisfied") @@ -5431,7 +5431,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) { }) t.Run("below minhtlc", func(t *testing.T) { - result := link.HtlcSatifiesPolicy(hash, 100, 50, + result := link.CheckHtlcForward(hash, 100, 50, 200, 150, 0) if _, ok := result.(*lnwire.FailAmountBelowMinimum); !ok { t.Fatalf("expected FailAmountBelowMinimum failure code") @@ -5439,7 +5439,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) { }) t.Run("above maxhtlc", func(t *testing.T) { - result := link.HtlcSatifiesPolicy(hash, 1500, 1200, + result := link.CheckHtlcForward(hash, 1500, 1200, 200, 150, 0) if _, ok := result.(*lnwire.FailTemporaryChannelFailure); !ok { t.Fatalf("expected FailTemporaryChannelFailure failure code") @@ -5447,7 +5447,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) { }) t.Run("insufficient fee", func(t *testing.T) { - result := link.HtlcSatifiesPolicy(hash, 1005, 1000, + result := link.CheckHtlcForward(hash, 1005, 1000, 200, 150, 0) if _, ok := result.(*lnwire.FailFeeInsufficient); !ok { t.Fatalf("expected FailFeeInsufficient failure code") @@ -5455,7 +5455,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) { }) t.Run("expiry too soon", func(t *testing.T) { - result := link.HtlcSatifiesPolicy(hash, 1500, 1000, + result := link.CheckHtlcForward(hash, 1500, 1000, 200, 150, 190) if _, ok := result.(*lnwire.FailExpiryTooSoon); !ok { t.Fatalf("expected FailExpiryTooSoon failure code") @@ -5463,7 +5463,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) { }) t.Run("incorrect cltv expiry", func(t *testing.T) { - result := link.HtlcSatifiesPolicy(hash, 1500, 1000, + result := link.CheckHtlcForward(hash, 1500, 1000, 200, 190, 0) if _, ok := result.(*lnwire.FailIncorrectCltvExpiry); !ok { t.Fatalf("expected FailIncorrectCltvExpiry failure code") @@ -5473,7 +5473,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) { t.Run("cltv expiry too far in the future", func(t *testing.T) { // Check that expiry isn't too far in the future. - result := link.HtlcSatifiesPolicy(hash, 1500, 1000, + result := link.CheckHtlcForward(hash, 1500, 1000, 10200, 10100, 0) if _, ok := result.(*lnwire.FailExpiryTooFar); !ok { t.Fatalf("expected FailExpiryTooFar failure code") diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 626ebe82..12067040 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -696,12 +696,12 @@ func (f *mockChannelLink) HandleChannelUpdate(lnwire.Message) { func (f *mockChannelLink) UpdateForwardingPolicy(_ ForwardingPolicy) { } -func (f *mockChannelLink) HtlcSatifiesPolicy([32]byte, lnwire.MilliSatoshi, +func (f *mockChannelLink) CheckHtlcForward([32]byte, lnwire.MilliSatoshi, lnwire.MilliSatoshi, uint32, uint32, uint32) lnwire.FailureMessage { return nil } -func (f *mockChannelLink) HtlcSatifiesPolicyLocal(payHash [32]byte, +func (f *mockChannelLink) CheckHtlcTransit(payHash [32]byte, amt lnwire.MilliSatoshi, timeout uint32, heightNow uint32) lnwire.FailureMessage { diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index e2c38d1b..eb3357e4 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -775,7 +775,7 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error { // Ensure that the htlc satisfies the outgoing channel policy. currentHeight := atomic.LoadUint32(&s.bestHeight) - htlcErr := link.HtlcSatifiesPolicyLocal( + htlcErr := link.CheckHtlcTransit( htlc.PaymentHash, htlc.Amount, htlc.Expiry, currentHeight, @@ -1050,7 +1050,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error { // that the HTLC satisfies the current forwarding // policy of this target link. currentHeight := atomic.LoadUint32(&s.bestHeight) - err := link.HtlcSatifiesPolicy( + err := link.CheckHtlcForward( htlc.PaymentHash, packet.incomingAmount, packet.amount, packet.incomingTimeout, packet.outgoingTimeout, currentHeight,