routing: account for blinded routes in fee calculation

When we introduce blinded routes, some of our hops are expected
to have zero amounts to forward in their hop payload. This commit
updates our hop fee logic to attribute the full blinded route's
fees to the introduction node. We can't actually know where/how
these fees are distributed, so we collect them all at the
introduction node.
This commit is contained in:
Carla Kirk-Cohen
2022-12-20 14:00:27 -05:00
committed by Olaoluwa Osuntokun
parent 940b491051
commit 11a007dc16
2 changed files with 94 additions and 2 deletions

View File

@@ -296,3 +296,42 @@ func testPayloadSize(t *testing.T, hops []*Hop) {
}
}
}
// TestBlindedHopFee tests calculation of hop fees for blinded routes.
func TestBlindedHopFee(t *testing.T) {
t.Parallel()
route := &Route{
TotalAmount: 1500,
Hops: []*Hop{
// Start with two un-blinded hops.
{
AmtToForward: 1450,
},
{
AmtToForward: 1300,
},
{
// Our introduction node will have a zero
// forward amount.
AmtToForward: 0,
},
{
// An intermediate blinded hop will also have
// a zero forward amount.
AmtToForward: 0,
},
{
// Our final blinded hop should have a forward
// amount set.
AmtToForward: 1000,
},
},
}
require.Equal(t, lnwire.MilliSatoshi(50), route.HopFee(0))
require.Equal(t, lnwire.MilliSatoshi(150), route.HopFee(1))
require.Equal(t, lnwire.MilliSatoshi(300), route.HopFee(2))
require.Equal(t, lnwire.MilliSatoshi(0), route.HopFee(3))
require.Equal(t, lnwire.MilliSatoshi(0), route.HopFee(4))
}