Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routing: inbound fees support for BuildRoute #8886

Merged
merged 10 commits into from
Aug 7, 2024
7 changes: 1 addition & 6 deletions channeldb/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3688,7 +3688,7 @@ func TestLightningNodeSigVerification(t *testing.T) {
}
}

// TestComputeFee tests fee calculation based on both in- and outgoing amt.
// TestComputeFee tests fee calculation based on the outgoing amt.
func TestComputeFee(t *testing.T) {
var (
policy = models.ChannelEdgePolicy{
Expand All @@ -3703,11 +3703,6 @@ func TestComputeFee(t *testing.T) {
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)
}
}

// TestBatchedAddChannelEdge asserts that BatchedAddChannelEdge properly
Expand Down
11 changes: 0 additions & 11 deletions channeldb/models/cached_edge_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ func (c *CachedEdgePolicy) ComputeFee(
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
}

// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
// amount.
func (c *CachedEdgePolicy) ComputeFeeFromIncoming(
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {

return incomingAmt - divideCeil(
feeRateParts*(incomingAmt-c.FeeBaseMSat),
feeRateParts+c.FeeProportionalMillionths,
)
}

// NewCachedPolicy turns a full policy into a minimal one that can be cached.
func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
return &CachedEdgePolicy{
Expand Down
16 changes: 0 additions & 16 deletions channeldb/models/channel_edge_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,3 @@ func (c *ChannelEdgePolicy) ComputeFee(

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,
)
}
3 changes: 3 additions & 0 deletions docs/release-notes/release-notes-0.18.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
* [`ChanInfoRequest`](https://github.com/lightningnetwork/lnd/pull/8813)
adds support for channel points.

* [BuildRoute](https://github.com/lightningnetwork/lnd/pull/8886) now supports
inbound fees.

## lncli Updates

* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts
Expand Down
9 changes: 7 additions & 2 deletions lnrpc/routerrpc/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lntypes"
Expand Down Expand Up @@ -1400,6 +1401,10 @@ func (s *Server) trackPaymentStream(context context.Context,
func (s *Server) BuildRoute(_ context.Context,
req *BuildRouteRequest) (*BuildRouteResponse, error) {

if len(req.HopPubkeys) == 0 {
return nil, errors.New("no hops specified")
}

// Unmarshall hop list.
hops := make([]route.Vertex, len(req.HopPubkeys))
for i, pubkeyBytes := range req.HopPubkeys {
Expand All @@ -1411,10 +1416,10 @@ func (s *Server) BuildRoute(_ context.Context,
}

// Prepare BuildRoute call parameters from rpc request.
var amt *lnwire.MilliSatoshi
var amt fn.Option[lnwire.MilliSatoshi]
if req.AmtMsat != 0 {
rpcAmt := lnwire.MilliSatoshi(req.AmtMsat)
amt = &rpcAmt
amt = fn.Some(rpcAmt)
}

var outgoingChan *uint64
Expand Down
Loading
Loading