Skip to content

Commit

Permalink
Merge pull request #8886 from bitromortac/buildroute-inbound-fees
Browse files Browse the repository at this point in the history
routing: inbound fees support for BuildRoute
  • Loading branch information
guggero authored Aug 7, 2024
2 parents 75ec6da + f622b43 commit b63e5de
Show file tree
Hide file tree
Showing 7 changed files with 897 additions and 209 deletions.
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 @@ -102,6 +102,9 @@ commitment when the channel was force closed.
* [`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

0 comments on commit b63e5de

Please sign in to comment.