multi: use fwding policy from models pkg
This commit is contained in:
1 parent
59b5fb1565
commit
d5c504c8de
12 files changed
+52
-105
No files matched your search
@@ -191,7 +191,7 @@ type ChannelLink interface {
|
||||
// UpdateForwardingPolicy updates the forwarding policy for the target
|
||||
// ChannelLink. Once updated, the link will use the new forwarding
|
||||
// policy to govern if it an incoming HTLC should be forwarded or not.
|
||||
UpdateForwardingPolicy(ForwardingPolicy)
|
||||
UpdateForwardingPolicy(models.ForwardingPolicy)
|
||||
|
||||
// CheckHtlcForward should return a nil error if the passed HTLC details
|
||||
// satisfy the current forwarding policy fo the target link. Otherwise,
|
||||
|
||||
+6
-42
@@ -64,44 +64,6 @@ const (
|
||||
DefaultMaxLinkFeeAllocation float64 = 0.5
|
||||
)
|
||||
|
||||
// ForwardingPolicy describes the set of constraints that a given ChannelLink
|
||||
// is to adhere to when forwarding HTLC's. For each incoming HTLC, this set of
|
||||
// constraints will be consulted in order to ensure that adequate fees are
|
||||
// paid, and our time-lock parameters are respected. In the event that an
|
||||
// incoming HTLC violates any of these constraints, it is to be _rejected_ with
|
||||
// the error possibly carrying along a ChannelUpdate message that includes the
|
||||
// latest policy.
|
||||
type ForwardingPolicy struct {
|
||||
// MinHTLC is the smallest HTLC that is to be forwarded.
|
||||
MinHTLCOut lnwire.MilliSatoshi
|
||||
|
||||
// MaxHTLC is the largest HTLC that is to be forwarded.
|
||||
MaxHTLC lnwire.MilliSatoshi
|
||||
|
||||
// BaseFee is the base fee, expressed in milli-satoshi that must be
|
||||
// paid for each incoming HTLC. This field, combined with FeeRate is
|
||||
// used to compute the required fee for a given HTLC.
|
||||
BaseFee lnwire.MilliSatoshi
|
||||
|
||||
// FeeRate is the fee rate, expressed in milli-satoshi that must be
|
||||
// paid for each incoming HTLC. This field combined with BaseFee is
|
||||
// used to compute the required fee for a given HTLC.
|
||||
FeeRate lnwire.MilliSatoshi
|
||||
|
||||
// TimeLockDelta is the absolute time-lock value, expressed in blocks,
|
||||
// that will be subtracted from an incoming HTLC's timelock value to
|
||||
// create the time-lock value for the forwarded outgoing HTLC. The
|
||||
// following constraint MUST hold for an HTLC to be forwarded:
|
||||
//
|
||||
// * incomingHtlc.timeLock - timeLockDelta = fwdInfo.OutgoingCTLV
|
||||
//
|
||||
// where fwdInfo is the forwarding information extracted from the
|
||||
// per-hop payload of the incoming HTLC's onion packet.
|
||||
TimeLockDelta uint32
|
||||
|
||||
// TODO(roasbeef): add fee module inside of switch
|
||||
}
|
||||
|
||||
// ExpectedFee computes the expected fee for a given htlc amount. The value
|
||||
// returned from this function is to be used as a sanity check when forwarding
|
||||
// HTLC's to ensure that an incoming HTLC properly adheres to our propagated
|
||||
@@ -109,7 +71,7 @@ type ForwardingPolicy struct {
|
||||
//
|
||||
// TODO(roasbeef): also add in current available channel bandwidth, inverse
|
||||
// func
|
||||
func ExpectedFee(f ForwardingPolicy,
|
||||
func ExpectedFee(f models.ForwardingPolicy,
|
||||
htlcAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||
|
||||
return f.BaseFee + (htlcAmt*f.FeeRate)/1000000
|
||||
@@ -123,7 +85,7 @@ type ChannelLinkConfig struct {
|
||||
// deciding whether to forwarding incoming HTLC's or not. This value
|
||||
// can be updated with subsequent calls to UpdateForwardingPolicy
|
||||
// targeted at a given ChannelLink concrete interface implementation.
|
||||
FwrdingPolicy ForwardingPolicy
|
||||
FwrdingPolicy models.ForwardingPolicy
|
||||
|
||||
// Circuits provides restricted access to the switch's circuit map,
|
||||
// allowing the link to open and close circuits.
|
||||
@@ -2522,7 +2484,9 @@ func (l *channelLink) AttachMailBox(mailbox MailBox) {
|
||||
// update all of the link's FwrdingPolicy's values.
|
||||
//
|
||||
// NOTE: Part of the ChannelLink interface.
|
||||
func (l *channelLink) UpdateForwardingPolicy(newPolicy ForwardingPolicy) {
|
||||
func (l *channelLink) UpdateForwardingPolicy(
|
||||
newPolicy models.ForwardingPolicy) {
|
||||
|
||||
l.Lock()
|
||||
defer l.Unlock()
|
||||
|
||||
@@ -2627,7 +2591,7 @@ func (l *channelLink) CheckHtlcTransit(payHash [32]byte,
|
||||
|
||||
// canSendHtlc checks whether the given htlc parameters satisfy
|
||||
// the channel's amount and time lock constraints.
|
||||
func (l *channelLink) canSendHtlc(policy ForwardingPolicy,
|
||||
func (l *channelLink) canSendHtlc(policy models.ForwardingPolicy,
|
||||
payHash [32]byte, amt lnwire.MilliSatoshi, timeout uint32,
|
||||
heightNow uint32, originalScid lnwire.ShortChannelID) *LinkError {
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hodl"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
@@ -1925,7 +1926,7 @@ func newSingleLinkTestHarness(t *testing.T, chanAmt, chanReserve btcutil.Amount)
|
||||
sentMsgs: make(chan lnwire.Message, 2000),
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
globalPolicy = ForwardingPolicy{
|
||||
globalPolicy = models.ForwardingPolicy{
|
||||
MinHTLCOut: lnwire.NewMSatFromSatoshis(5),
|
||||
MaxHTLC: lnwire.NewMSatFromSatoshis(chanAmt),
|
||||
BaseFee: lnwire.NewMSatFromSatoshis(1),
|
||||
@@ -4374,7 +4375,7 @@ func (h *persistentLinkHarness) restartLink(
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
globalPolicy = ForwardingPolicy{
|
||||
globalPolicy = models.ForwardingPolicy{
|
||||
MinHTLCOut: lnwire.NewMSatFromSatoshis(5),
|
||||
BaseFee: lnwire.NewMSatFromSatoshis(1),
|
||||
TimeLockDelta: 6,
|
||||
@@ -5630,7 +5631,7 @@ func TestExpectedFee(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
f := ForwardingPolicy{
|
||||
f := models.ForwardingPolicy{
|
||||
BaseFee: test.baseFee,
|
||||
FeeRate: test.feeRate,
|
||||
}
|
||||
@@ -5716,7 +5717,7 @@ func TestCheckHtlcForward(t *testing.T) {
|
||||
|
||||
link := channelLink{
|
||||
cfg: ChannelLinkConfig{
|
||||
FwrdingPolicy: ForwardingPolicy{
|
||||
FwrdingPolicy: models.ForwardingPolicy{
|
||||
TimeLockDelta: 20,
|
||||
MinHTLCOut: 500,
|
||||
MaxHTLC: 1000,
|
||||
|
||||
+1
-1
@@ -840,7 +840,7 @@ func (f *mockChannelLink) getDustClosure() dustClosure {
|
||||
func (f *mockChannelLink) HandleChannelUpdate(lnwire.Message) {
|
||||
}
|
||||
|
||||
func (f *mockChannelLink) UpdateForwardingPolicy(_ ForwardingPolicy) {
|
||||
func (f *mockChannelLink) UpdateForwardingPolicy(_ models.ForwardingPolicy) {
|
||||
}
|
||||
func (f *mockChannelLink) CheckHtlcForward([32]byte, lnwire.MilliSatoshi,
|
||||
lnwire.MilliSatoshi, uint32, uint32, uint32,
|
||||
|
||||
@@ -611,7 +611,7 @@ func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, attemptID uint64,
|
||||
// forwarding policies for all links have been updated, or the switch shuts
|
||||
// down.
|
||||
func (s *Switch) UpdateForwardingPolicies(
|
||||
chanPolicies map[wire.OutPoint]ForwardingPolicy) {
|
||||
chanPolicies map[wire.OutPoint]models.ForwardingPolicy) {
|
||||
|
||||
log.Tracef("Updating link policies: %v", newLogClosure(func() string {
|
||||
return spew.Sdump(chanPolicies)
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/go-errors/errors"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
@@ -1069,7 +1070,7 @@ func createTwoClusterChannels(t *testing.T, aliceToBob,
|
||||
// hopNetwork is the base struct for two and three hop networks
|
||||
type hopNetwork struct {
|
||||
feeEstimator *mockFeeEstimator
|
||||
globalPolicy ForwardingPolicy
|
||||
globalPolicy models.ForwardingPolicy
|
||||
obfuscator hop.ErrorEncrypter
|
||||
|
||||
defaultDelta uint32
|
||||
@@ -1078,7 +1079,7 @@ type hopNetwork struct {
|
||||
func newHopNetwork() *hopNetwork {
|
||||
defaultDelta := uint32(6)
|
||||
|
||||
globalPolicy := ForwardingPolicy{
|
||||
globalPolicy := models.ForwardingPolicy{
|
||||
MinHTLCOut: lnwire.NewMSatFromSatoshis(5),
|
||||
BaseFee: lnwire.NewMSatFromSatoshis(1),
|
||||
TimeLockDelta: defaultDelta,
|
||||
|
||||
Reference in new issue
Block a user