Skip to content

Commit b63e5de

Browse files
authored
Merge pull request #8886 from bitromortac/buildroute-inbound-fees
routing: inbound fees support for BuildRoute
2 parents 75ec6da + f622b43 commit b63e5de

File tree

7 files changed

+897
-209
lines changed

7 files changed

+897
-209
lines changed

channeldb/graph_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ func TestLightningNodeSigVerification(t *testing.T) {
36883688
}
36893689
}
36903690

3691-
// TestComputeFee tests fee calculation based on both in- and outgoing amt.
3691+
// TestComputeFee tests fee calculation based on the outgoing amt.
36923692
func TestComputeFee(t *testing.T) {
36933693
var (
36943694
policy = models.ChannelEdgePolicy{
@@ -3703,11 +3703,6 @@ func TestComputeFee(t *testing.T) {
37033703
if fee != expectedFee {
37043704
t.Fatalf("expected fee %v, got %v", expectedFee, fee)
37053705
}
3706-
3707-
fwdFee := policy.ComputeFeeFromIncoming(outgoingAmt + fee)
3708-
if fwdFee != expectedFee {
3709-
t.Fatalf("expected fee %v, but got %v", fee, fwdFee)
3710-
}
37113706
}
37123707

37133708
// TestBatchedAddChannelEdge asserts that BatchedAddChannelEdge properly

channeldb/models/cached_edge_policy.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ func (c *CachedEdgePolicy) ComputeFee(
7171
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
7272
}
7373

74-
// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
75-
// amount.
76-
func (c *CachedEdgePolicy) ComputeFeeFromIncoming(
77-
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
78-
79-
return incomingAmt - divideCeil(
80-
feeRateParts*(incomingAmt-c.FeeBaseMSat),
81-
feeRateParts+c.FeeProportionalMillionths,
82-
)
83-
}
84-
8574
// NewCachedPolicy turns a full policy into a minimal one that can be cached.
8675
func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
8776
return &CachedEdgePolicy{

channeldb/models/channel_edge_policy.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,3 @@ func (c *ChannelEdgePolicy) ComputeFee(
113113

114114
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
115115
}
116-
117-
// divideCeil divides dividend by factor and rounds the result up.
118-
func divideCeil(dividend, factor lnwire.MilliSatoshi) lnwire.MilliSatoshi {
119-
return (dividend + factor - 1) / factor
120-
}
121-
122-
// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
123-
// amount.
124-
func (c *ChannelEdgePolicy) ComputeFeeFromIncoming(
125-
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
126-
127-
return incomingAmt - divideCeil(
128-
feeRateParts*(incomingAmt-c.FeeBaseMSat),
129-
feeRateParts+c.FeeProportionalMillionths,
130-
)
131-
}

docs/release-notes/release-notes-0.18.3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ commitment when the channel was force closed.
102102
* [`ChanInfoRequest`](https://github.com/lightningnetwork/lnd/pull/8813)
103103
adds support for channel points.
104104

105+
* [BuildRoute](https://github.com/lightningnetwork/lnd/pull/8886) now supports
106+
inbound fees.
107+
105108
## lncli Updates
106109

107110
* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts

lnrpc/routerrpc/router_server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/btcsuite/btcd/wire"
1616
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1717
"github.com/lightningnetwork/lnd/channeldb"
18+
"github.com/lightningnetwork/lnd/fn"
1819
"github.com/lightningnetwork/lnd/lnrpc"
1920
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
2021
"github.com/lightningnetwork/lnd/lntypes"
@@ -1400,6 +1401,10 @@ func (s *Server) trackPaymentStream(context context.Context,
14001401
func (s *Server) BuildRoute(_ context.Context,
14011402
req *BuildRouteRequest) (*BuildRouteResponse, error) {
14021403

1404+
if len(req.HopPubkeys) == 0 {
1405+
return nil, errors.New("no hops specified")
1406+
}
1407+
14031408
// Unmarshall hop list.
14041409
hops := make([]route.Vertex, len(req.HopPubkeys))
14051410
for i, pubkeyBytes := range req.HopPubkeys {
@@ -1411,10 +1416,10 @@ func (s *Server) BuildRoute(_ context.Context,
14111416
}
14121417

14131418
// Prepare BuildRoute call parameters from rpc request.
1414-
var amt *lnwire.MilliSatoshi
1419+
var amt fn.Option[lnwire.MilliSatoshi]
14151420
if req.AmtMsat != 0 {
14161421
rpcAmt := lnwire.MilliSatoshi(req.AmtMsat)
1417-
amt = &rpcAmt
1422+
amt = fn.Some(rpcAmt)
14181423
}
14191424

14201425
var outgoingChan *uint64

0 commit comments

Comments
 (0)