Merge pull request #3440 from joostjager/buildroute
routing: add build route functionality
This commit is contained in:
12 files changed
+1007
-145
No files matched your search
@@ -155,6 +155,9 @@ const (
|
||||
// would be possible for a node to create a ton of updates and slowly
|
||||
// fill our disk, and also waste bandwidth due to relaying.
|
||||
MaxAllowedExtraOpaqueBytes = 10000
|
||||
|
||||
// feeRateParts is the total number of parts used to express fee rates.
|
||||
feeRateParts = 1e6
|
||||
)
|
||||
|
||||
// ChannelGraph is a persistent, on-disk graph representation of the Lightning
|
||||
@@ -2828,6 +2831,31 @@ func (c *ChannelEdgePolicy) IsDisabled() bool {
|
||||
lnwire.ChanUpdateDisabled
|
||||
}
|
||||
|
||||
// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over
|
||||
// the passed active payment channel. This value is currently computed as
|
||||
// specified in BOLT07, but will likely change in the near future.
|
||||
func (c *ChannelEdgePolicy) ComputeFee(
|
||||
amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||
|
||||
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
|
||||
}
|
||||
|
||||
// divideCeil divides dividend by factor and rounds the result up.
|
||||
func divideCeil(dividend, factor lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||
return (dividend + factor - 1) / factor
|
||||
}
|
||||
|
||||
// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
|
||||
// amount.
|
||||
func (c *ChannelEdgePolicy) ComputeFeeFromIncoming(
|
||||
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||
|
||||
return incomingAmt - divideCeil(
|
||||
feeRateParts*(incomingAmt-c.FeeBaseMSat),
|
||||
feeRateParts+c.FeeProportionalMillionths,
|
||||
)
|
||||
}
|
||||
|
||||
// FetchChannelEdgesByOutpoint attempts to lookup the two directed edges for
|
||||
// the channel identified by the funding outpoint. If the channel can't be
|
||||
// found, then ErrEdgeNotFound is returned. A struct which houses the general
|
||||
|
||||
@@ -3173,3 +3173,25 @@ func TestLightningNodeSigVerification(t *testing.T) {
|
||||
t.Fatalf("unable to verify sig")
|
||||
}
|
||||
}
|
||||
|
||||
// TestComputeFee tests fee calculation based on both in- and outgoing amt.
|
||||
func TestComputeFee(t *testing.T) {
|
||||
var (
|
||||
policy = ChannelEdgePolicy{
|
||||
FeeBaseMSat: 10000,
|
||||
FeeProportionalMillionths: 30000,
|
||||
}
|
||||
outgoingAmt = lnwire.MilliSatoshi(1000000)
|
||||
expectedFee = lnwire.MilliSatoshi(40000)
|
||||
)
|
||||
|
||||
fee := policy.ComputeFee(outgoingAmt)
|
||||
if fee != expectedFee {
|
||||
t.Fatalf("expected fee %v, got %v", expectedFee, fee)
|
||||
}
|
||||
|
||||
fwdFee := policy.ComputeFeeFromIncoming(outgoingAmt + fee)
|
||||
if fwdFee != expectedFee {
|
||||
t.Fatalf("expected fee %v, but got %v", fee, fwdFee)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user