htlcswitch: rename policy check functions
This commit is contained in:
parent
566680defb
commit
5404348f51
@ -100,22 +100,21 @@ type ChannelLink interface {
|
|||||||
// policy to govern if it an incoming HTLC should be forwarded or not.
|
// policy to govern if it an incoming HTLC should be forwarded or not.
|
||||||
UpdateForwardingPolicy(ForwardingPolicy)
|
UpdateForwardingPolicy(ForwardingPolicy)
|
||||||
|
|
||||||
// HtlcSatifiesPolicy should return a nil error if the passed HTLC
|
// CheckHtlcForward should return a nil error if the passed HTLC details
|
||||||
// details satisfy the current forwarding policy fo the target link.
|
// satisfy the current forwarding policy fo the target link. Otherwise,
|
||||||
// Otherwise, a valid protocol failure message should be returned in
|
// a valid protocol failure message should be returned in order to
|
||||||
// order to signal to the source of the HTLC, the policy consistency
|
// signal to the source of the HTLC, the policy consistency issue.
|
||||||
// issue.
|
CheckHtlcForward(payHash [32]byte, incomingAmt lnwire.MilliSatoshi,
|
||||||
HtlcSatifiesPolicy(payHash [32]byte, incomingAmt lnwire.MilliSatoshi,
|
|
||||||
amtToForward lnwire.MilliSatoshi,
|
amtToForward lnwire.MilliSatoshi,
|
||||||
incomingTimeout, outgoingTimeout uint32,
|
incomingTimeout, outgoingTimeout uint32,
|
||||||
heightNow uint32) lnwire.FailureMessage
|
heightNow uint32) lnwire.FailureMessage
|
||||||
|
|
||||||
// HtlcSatifiesPolicyLocal should return a nil error if the passed HTLC
|
// CheckHtlcTransit should return a nil error if the passed HTLC details
|
||||||
// details satisfy the current channel policy. Otherwise, a valid
|
// satisfy the current channel policy. Otherwise, a valid protocol
|
||||||
// protocol failure message should be returned in order to signal the
|
// failure message should be returned in order to signal the violation.
|
||||||
// violation. This call is intended to be used for locally initiated
|
// This call is intended to be used for locally initiated payments for
|
||||||
// payments for which there is no corresponding incoming htlc.
|
// which there is no corresponding incoming htlc.
|
||||||
HtlcSatifiesPolicyLocal(payHash [32]byte, amt lnwire.MilliSatoshi,
|
CheckHtlcTransit(payHash [32]byte, amt lnwire.MilliSatoshi,
|
||||||
timeout uint32, heightNow uint32) lnwire.FailureMessage
|
timeout uint32, heightNow uint32) lnwire.FailureMessage
|
||||||
|
|
||||||
// Bandwidth returns the amount of milli-satoshis which current link
|
// Bandwidth returns the amount of milli-satoshis which current link
|
||||||
|
@ -2184,13 +2184,13 @@ func (l *channelLink) UpdateForwardingPolicy(newPolicy ForwardingPolicy) {
|
|||||||
l.cfg.FwrdingPolicy = newPolicy
|
l.cfg.FwrdingPolicy = newPolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
// HtlcSatifiesPolicy should return a nil error if the passed HTLC details
|
// CheckHtlcForward should return a nil error if the passed HTLC details satisfy
|
||||||
// satisfy the current forwarding policy fo the target link. Otherwise, a
|
// the current forwarding policy fo the target link. Otherwise, a valid
|
||||||
// valid protocol failure message should be returned in order to signal to the
|
// protocol failure message should be returned in order to signal to the source
|
||||||
// source of the HTLC, the policy consistency issue.
|
// of the HTLC, the policy consistency issue.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the ChannelLink interface.
|
// NOTE: Part of the ChannelLink interface.
|
||||||
func (l *channelLink) HtlcSatifiesPolicy(payHash [32]byte,
|
func (l *channelLink) CheckHtlcForward(payHash [32]byte,
|
||||||
incomingHtlcAmt, amtToForward lnwire.MilliSatoshi,
|
incomingHtlcAmt, amtToForward lnwire.MilliSatoshi,
|
||||||
incomingTimeout, outgoingTimeout uint32,
|
incomingTimeout, outgoingTimeout uint32,
|
||||||
heightNow uint32) lnwire.FailureMessage {
|
heightNow uint32) lnwire.FailureMessage {
|
||||||
@ -2200,7 +2200,7 @@ func (l *channelLink) HtlcSatifiesPolicy(payHash [32]byte,
|
|||||||
l.RUnlock()
|
l.RUnlock()
|
||||||
|
|
||||||
// First check whether the outgoing htlc satisfies the channel policy.
|
// First check whether the outgoing htlc satisfies the channel policy.
|
||||||
err := l.htlcSatifiesPolicyOutgoing(
|
err := l.canSendHtlc(
|
||||||
policy, payHash, amtToForward, outgoingTimeout, heightNow,
|
policy, payHash, amtToForward, outgoingTimeout, heightNow,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2259,12 +2259,12 @@ func (l *channelLink) HtlcSatifiesPolicy(payHash [32]byte,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HtlcSatifiesPolicyLocal should return a nil error if the passed HTLC details
|
// CheckHtlcTransit should return a nil error if the passed HTLC details satisfy the
|
||||||
// satisfy the current channel policy. Otherwise, a valid protocol failure
|
// current channel policy. Otherwise, a valid protocol failure message should
|
||||||
// message should be returned in order to signal the violation. This call is
|
// be returned in order to signal the violation. This call is intended to be
|
||||||
// intended to be used for locally initiated payments for which there is no
|
// used for locally initiated payments for which there is no corresponding
|
||||||
// corresponding incoming htlc.
|
// incoming htlc.
|
||||||
func (l *channelLink) HtlcSatifiesPolicyLocal(payHash [32]byte,
|
func (l *channelLink) CheckHtlcTransit(payHash [32]byte,
|
||||||
amt lnwire.MilliSatoshi, timeout uint32,
|
amt lnwire.MilliSatoshi, timeout uint32,
|
||||||
heightNow uint32) lnwire.FailureMessage {
|
heightNow uint32) lnwire.FailureMessage {
|
||||||
|
|
||||||
@ -2272,14 +2272,14 @@ func (l *channelLink) HtlcSatifiesPolicyLocal(payHash [32]byte,
|
|||||||
policy := l.cfg.FwrdingPolicy
|
policy := l.cfg.FwrdingPolicy
|
||||||
l.RUnlock()
|
l.RUnlock()
|
||||||
|
|
||||||
return l.htlcSatifiesPolicyOutgoing(
|
return l.canSendHtlc(
|
||||||
policy, payHash, amt, timeout, heightNow,
|
policy, payHash, amt, timeout, heightNow,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// htlcSatifiesPolicyOutgoing checks whether the given htlc parameters satisfy
|
// htlcSatifiesPolicyOutgoing checks whether the given htlc parameters satisfy
|
||||||
// the channel's amount and time lock constraints.
|
// 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,
|
payHash [32]byte, amt lnwire.MilliSatoshi, timeout uint32,
|
||||||
heightNow uint32) lnwire.FailureMessage {
|
heightNow uint32) lnwire.FailureMessage {
|
||||||
|
|
||||||
|
@ -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.
|
// forwarding policy.
|
||||||
func TestHtlcSatisfyPolicy(t *testing.T) {
|
func TestCheckHtlcForward(t *testing.T) {
|
||||||
|
|
||||||
fetchLastChannelUpdate := func(lnwire.ShortChannelID) (
|
fetchLastChannelUpdate := func(lnwire.ShortChannelID) (
|
||||||
*lnwire.ChannelUpdate, error) {
|
*lnwire.ChannelUpdate, error) {
|
||||||
@ -5423,7 +5423,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) {
|
|||||||
var hash [32]byte
|
var hash [32]byte
|
||||||
|
|
||||||
t.Run("satisfied", func(t *testing.T) {
|
t.Run("satisfied", func(t *testing.T) {
|
||||||
result := link.HtlcSatifiesPolicy(hash, 1500, 1000,
|
result := link.CheckHtlcForward(hash, 1500, 1000,
|
||||||
200, 150, 0)
|
200, 150, 0)
|
||||||
if result != nil {
|
if result != nil {
|
||||||
t.Fatalf("expected policy to be satisfied")
|
t.Fatalf("expected policy to be satisfied")
|
||||||
@ -5431,7 +5431,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("below minhtlc", func(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)
|
200, 150, 0)
|
||||||
if _, ok := result.(*lnwire.FailAmountBelowMinimum); !ok {
|
if _, ok := result.(*lnwire.FailAmountBelowMinimum); !ok {
|
||||||
t.Fatalf("expected FailAmountBelowMinimum failure code")
|
t.Fatalf("expected FailAmountBelowMinimum failure code")
|
||||||
@ -5439,7 +5439,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("above maxhtlc", func(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)
|
200, 150, 0)
|
||||||
if _, ok := result.(*lnwire.FailTemporaryChannelFailure); !ok {
|
if _, ok := result.(*lnwire.FailTemporaryChannelFailure); !ok {
|
||||||
t.Fatalf("expected FailTemporaryChannelFailure failure code")
|
t.Fatalf("expected FailTemporaryChannelFailure failure code")
|
||||||
@ -5447,7 +5447,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("insufficient fee", func(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)
|
200, 150, 0)
|
||||||
if _, ok := result.(*lnwire.FailFeeInsufficient); !ok {
|
if _, ok := result.(*lnwire.FailFeeInsufficient); !ok {
|
||||||
t.Fatalf("expected FailFeeInsufficient failure code")
|
t.Fatalf("expected FailFeeInsufficient failure code")
|
||||||
@ -5455,7 +5455,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("expiry too soon", func(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)
|
200, 150, 190)
|
||||||
if _, ok := result.(*lnwire.FailExpiryTooSoon); !ok {
|
if _, ok := result.(*lnwire.FailExpiryTooSoon); !ok {
|
||||||
t.Fatalf("expected FailExpiryTooSoon failure code")
|
t.Fatalf("expected FailExpiryTooSoon failure code")
|
||||||
@ -5463,7 +5463,7 @@ func TestHtlcSatisfyPolicy(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("incorrect cltv expiry", func(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)
|
200, 190, 0)
|
||||||
if _, ok := result.(*lnwire.FailIncorrectCltvExpiry); !ok {
|
if _, ok := result.(*lnwire.FailIncorrectCltvExpiry); !ok {
|
||||||
t.Fatalf("expected FailIncorrectCltvExpiry failure code")
|
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) {
|
t.Run("cltv expiry too far in the future", func(t *testing.T) {
|
||||||
// Check that expiry isn't too far in the future.
|
// 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)
|
10200, 10100, 0)
|
||||||
if _, ok := result.(*lnwire.FailExpiryTooFar); !ok {
|
if _, ok := result.(*lnwire.FailExpiryTooFar); !ok {
|
||||||
t.Fatalf("expected FailExpiryTooFar failure code")
|
t.Fatalf("expected FailExpiryTooFar failure code")
|
||||||
|
@ -696,12 +696,12 @@ func (f *mockChannelLink) HandleChannelUpdate(lnwire.Message) {
|
|||||||
|
|
||||||
func (f *mockChannelLink) UpdateForwardingPolicy(_ ForwardingPolicy) {
|
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 {
|
lnwire.MilliSatoshi, uint32, uint32, uint32) lnwire.FailureMessage {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *mockChannelLink) HtlcSatifiesPolicyLocal(payHash [32]byte,
|
func (f *mockChannelLink) CheckHtlcTransit(payHash [32]byte,
|
||||||
amt lnwire.MilliSatoshi, timeout uint32,
|
amt lnwire.MilliSatoshi, timeout uint32,
|
||||||
heightNow uint32) lnwire.FailureMessage {
|
heightNow uint32) lnwire.FailureMessage {
|
||||||
|
|
||||||
|
@ -775,7 +775,7 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
|||||||
|
|
||||||
// Ensure that the htlc satisfies the outgoing channel policy.
|
// Ensure that the htlc satisfies the outgoing channel policy.
|
||||||
currentHeight := atomic.LoadUint32(&s.bestHeight)
|
currentHeight := atomic.LoadUint32(&s.bestHeight)
|
||||||
htlcErr := link.HtlcSatifiesPolicyLocal(
|
htlcErr := link.CheckHtlcTransit(
|
||||||
htlc.PaymentHash,
|
htlc.PaymentHash,
|
||||||
htlc.Amount,
|
htlc.Amount,
|
||||||
htlc.Expiry, currentHeight,
|
htlc.Expiry, currentHeight,
|
||||||
@ -1050,7 +1050,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
// that the HTLC satisfies the current forwarding
|
// that the HTLC satisfies the current forwarding
|
||||||
// policy of this target link.
|
// policy of this target link.
|
||||||
currentHeight := atomic.LoadUint32(&s.bestHeight)
|
currentHeight := atomic.LoadUint32(&s.bestHeight)
|
||||||
err := link.HtlcSatifiesPolicy(
|
err := link.CheckHtlcForward(
|
||||||
htlc.PaymentHash, packet.incomingAmount,
|
htlc.PaymentHash, packet.incomingAmount,
|
||||||
packet.amount, packet.incomingTimeout,
|
packet.amount, packet.incomingTimeout,
|
||||||
packet.outgoingTimeout, currentHeight,
|
packet.outgoingTimeout, currentHeight,
|
||||||
|
Loading…
Reference in New Issue
Block a user