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.
|
||||
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
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user