Skip to content

Commit

Permalink
Merge branch 'v0.14.2-beta-6200' into v0.14.2-branch-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Jan 26, 2022
2 parents 4b9a23b + 8f12fe3 commit 09b1ae9
Show file tree
Hide file tree
Showing 8 changed files with 960 additions and 796 deletions.
25 changes: 22 additions & 3 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,16 @@ var updateChannelPolicyCommand = cli.Command{
Usage: "the fee rate that will be charged " +
"proportionally based on the value of each " +
"forwarded HTLC, the lowest possible rate is 0 " +
"with a granularity of 0.000001 (millionths)",
"with a granularity of 0.000001 (millionths). Can not " +
"be set at the same time as fee_rate_ppm.",
},
cli.Uint64Flag{
Name: "fee_rate_ppm",
Usage: "the fee rate ppm (parts per million) that " +
"will be charged proportionally based on the value of each " +
"forwarded HTLC, the lowest possible rate is 0 " +
"with a granularity of 0.000001 (millionths). Can not " +
"be set at the same time as fee_rate.",
},
cli.Int64Flag{
Name: "time_lock_delta",
Expand Down Expand Up @@ -2015,6 +2024,7 @@ func updateChannelPolicy(ctx *cli.Context) error {
var (
baseFee int64
feeRate float64
feeRatePpm uint64
timeLockDelta int64
err error
)
Expand All @@ -2034,8 +2044,12 @@ func updateChannelPolicy(ctx *cli.Context) error {
}

switch {
case ctx.IsSet("fee_rate") && ctx.IsSet("fee_rate_ppm"):
return fmt.Errorf("fee_rate or fee_rate_ppm can not both be set")
case ctx.IsSet("fee_rate"):
feeRate = ctx.Float64("fee_rate")
case ctx.IsSet("fee_rate_ppm"):
feeRatePpm = ctx.Uint64("fee_rate_ppm")
case args.Present():
feeRate, err = strconv.ParseFloat(args.First(), 64)
if err != nil {
Expand All @@ -2044,7 +2058,7 @@ func updateChannelPolicy(ctx *cli.Context) error {

args = args.Tail()
default:
return fmt.Errorf("fee_rate argument missing")
return fmt.Errorf("fee_rate or fee_rate_ppm argument missing")
}

switch {
Expand Down Expand Up @@ -2083,7 +2097,6 @@ func updateChannelPolicy(ctx *cli.Context) error {

req := &lnrpc.PolicyUpdateRequest{
BaseFeeMsat: baseFee,
FeeRate: feeRate,
TimeLockDelta: uint32(timeLockDelta),
MaxHtlcMsat: ctx.Uint64("max_htlc_msat"),
}
Expand All @@ -2103,6 +2116,12 @@ func updateChannelPolicy(ctx *cli.Context) error {
}
}

if feeRate != 0 {
req.FeeRate = feeRate
} else if feeRatePpm != 0 {
req.FeeRatePpm = uint32(feeRatePpm)
}

resp, err := client.UpdateChannelPolicy(ctxc, req)
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions docs/release-notes/release-notes-0.14.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ Postgres](https://github.com/lightningnetwork/lnd/pull/6111)

* [Fix an issue that would prevent very old nodes from starting up due to lack of a historical channel bucket](https://github.com/lightningnetwork/lnd/pull/6159)

* [Fixes a bug that would cause incorrect rounding when translating a decimal fee rate to ppm](https://github.com/lightningnetwork/lnd/pull/6200)


## RPC Server

Expand All @@ -145,6 +147,10 @@ Postgres](https://github.com/lightningnetwork/lnd/pull/6111)

* [Refactored itest to better manage contexts inside integration tests](https://github.com/lightningnetwork/lnd/pull/5756).

* [The `fee_rate_ppm` parameter/argument was added to
update channel policy](https://github.com/lightningnetwork/lnd/pull/5711)
to prevent truncation error with tiny fee rates.

* [Closing txid is now
exposed](https://github.com/lightningnetwork/lnd/pull/6146) inside
WaitingCloseResp from calling `PendingChannels`.
Expand All @@ -153,6 +159,8 @@ Postgres](https://github.com/lightningnetwork/lnd/pull/6111)
set](https://github.com/lightningnetwork/lnd/pull/6185) on
`RPCMiddlewareRequest` messages.

* [Adds a new FeeRatePpm to the UpdateChanPolicy call to allow fee rate expression in the native protocol unit](https://github.com/lightningnetwork/lnd/pull/6200)


## Routing

Expand All @@ -167,6 +175,7 @@ Postgres](https://github.com/lightningnetwork/lnd/pull/6111)
* Bjarne Magnussen
* Daniel McNally
* Elle Mouton
* Erik Ek
* Harsha Goli
* Joost Jager
* Martin Habovštiak
Expand Down
1,511 changes: 761 additions & 750 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3748,6 +3748,9 @@ message PolicyUpdateRequest {
// goes up to 6 decimal places, so 1e-6.
double fee_rate = 4;

// The effective fee rate in micro-satoshis (parts per million).
uint32 fee_rate_ppm = 9;

// The required timelock delta for HTLCs forwarded over the channel.
uint32 time_lock_delta = 5;

Expand Down
5 changes: 5 additions & 0 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5763,6 +5763,11 @@
"format": "double",
"description": "The effective fee rate in milli-satoshis. The precision of this value\ngoes up to 6 decimal places, so 1e-6."
},
"fee_rate_ppm": {
"type": "integer",
"format": "int64",
"description": "The effective fee rate in micro-satoshis (parts per million)."
},
"time_lock_delta": {
"type": "integer",
"format": "int64",
Expand Down
141 changes: 115 additions & 26 deletions lntest/itest/lnd_channel_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package itest

import (
"context"
"math"
"strings"
"time"

Expand All @@ -15,6 +16,19 @@ import (
"github.com/stretchr/testify/require"
)

// assertPolicyUpdate checks that a given policy update has been received by a
// list of given nodes.
func assertPolicyUpdate(t *harnessTest, nodes []*lntest.HarnessNode,
advertisingNode string, policy *lnrpc.RoutingPolicy,
chanPoint *lnrpc.ChannelPoint) {

for _, node := range nodes {
assertChannelPolicyUpdate(
t.t, node, advertisingNode, policy, chanPoint, false,
)
}
}

// testUpdateChannelPolicy tests that policy updates made to a channel
// gets propagated to other nodes in the network.
func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
Expand Down Expand Up @@ -45,21 +59,6 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
// make sure they all receive the expected updates.
nodes := []*lntest.HarnessNode{net.Alice, net.Bob}

// assertPolicyUpdate checks that a given policy update has been
// received by a list of given nodes.
assertPolicyUpdate := func(nodes []*lntest.HarnessNode,
advertisingNode string, policy *lnrpc.RoutingPolicy,
chanPoint *lnrpc.ChannelPoint) {

for _, node := range nodes {
assertChannelPolicyUpdate(
t.t, node, advertisingNode,
policy, chanPoint, false,
)
}

}

// Alice and Bob should see each other's ChannelUpdates, advertising the
// default routing policies.
expectedPolicy := &lnrpc.RoutingPolicy{
Expand All @@ -71,9 +70,11 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
}

assertPolicyUpdate(
nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
t, nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
)
assertPolicyUpdate(
t, nodes, net.Bob.PubKeyStr, expectedPolicy, chanPoint,
)
assertPolicyUpdate(nodes, net.Bob.PubKeyStr, expectedPolicy, chanPoint)

// They should now know about the default policies.
for _, node := range nodes {
Expand Down Expand Up @@ -144,10 +145,10 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
}

assertPolicyUpdate(
nodes, net.Bob.PubKeyStr, expectedPolicyBob, chanPoint2,
t, nodes, net.Bob.PubKeyStr, expectedPolicyBob, chanPoint2,
)
assertPolicyUpdate(
nodes, carol.PubKeyStr, expectedPolicyCarol, chanPoint2,
t, nodes, carol.PubKeyStr, expectedPolicyCarol, chanPoint2,
)

// Check that all nodes now know about the updated policies.
Expand Down Expand Up @@ -337,7 +338,9 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
}

// Wait for all nodes to have seen the policy update done by Bob.
assertPolicyUpdate(nodes, net.Bob.PubKeyStr, expectedPolicy, chanPoint)
assertPolicyUpdate(
t, nodes, net.Bob.PubKeyStr, expectedPolicy, chanPoint,
)

// Check that all nodes now know about Bob's updated policy.
for _, node := range nodes {
Expand Down Expand Up @@ -421,10 +424,10 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
// Wait for all nodes to have seen the policy updates for both of
// Alice's channels.
assertPolicyUpdate(
nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
t, nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
)
assertPolicyUpdate(
nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint3,
t, nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint3,
)

// And finally check that all nodes remembers the policy update they
Expand Down Expand Up @@ -456,11 +459,11 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
// of Alice's channels. Carol will not see the last update as
// the limit has been reached.
assertPolicyUpdate(
[]*lntest.HarnessNode{net.Alice, net.Bob},
t, []*lntest.HarnessNode{net.Alice, net.Bob},
net.Alice.PubKeyStr, expectedPolicy, chanPoint,
)
assertPolicyUpdate(
[]*lntest.HarnessNode{net.Alice, net.Bob},
t, []*lntest.HarnessNode{net.Alice, net.Bob},
net.Alice.PubKeyStr, expectedPolicy, chanPoint3,
)
// Check that all nodes remembers the policy update
Expand All @@ -481,11 +484,11 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) {
expectedPolicy = &prevAlicePolicy
}
assertPolicyUpdate(
[]*lntest.HarnessNode{carol},
t, []*lntest.HarnessNode{carol},
net.Alice.PubKeyStr, expectedPolicy, chanPoint,
)
assertPolicyUpdate(
[]*lntest.HarnessNode{carol},
t, []*lntest.HarnessNode{carol},
net.Alice.PubKeyStr, expectedPolicy, chanPoint3,
)
assertChannelPolicy(
Expand Down Expand Up @@ -818,3 +821,89 @@ func testUpdateChannelPolicyForPrivateChannel(net *lntest.NetworkHarness,
assertAmountPaid(t, "Alice(local) => Bob(remote)",
net.Alice, aliceFundPoint, amtExpected, 0)
}

// testUpdateChannelPolicyFeeRateAccuracy tests that updating the channel policy
// rounds fee rate values correctly as well as setting fee rate with ppm works
// as expected.
func testUpdateChannelPolicyFeeRateAccuracy(net *lntest.NetworkHarness,
t *harnessTest) {

chanAmt := funding.MaxBtcFundingAmount
pushAmt := chanAmt / 2

// Create a channel Alice -> Bob.
chanPoint := openChannelAndAssert(
t, net, net.Alice, net.Bob,
lntest.OpenChannelParams{
Amt: chanAmt,
PushAmt: pushAmt,
},
)
defer closeChannelAndAssert(t, net, net.Alice, chanPoint, false)

// Nodes that we need to make sure receive the channel updates.
nodes := []*lntest.HarnessNode{net.Alice, net.Bob}

baseFee := int64(1500)
timeLockDelta := uint32(66)
maxHtlc := uint64(500000)
defaultMinHtlc := int64(1000)

// Originally LND did not properly round up fee rates which caused
// inaccuracy where fee rates were simply rounded down due to the
// integer conversion.
//
// We'll use a fee rate of 0.031337 which without rounding up would
// have resulted in a fee rate ppm of 31336.
feeRate := 0.031337

// Expected fee rate will be rounded up.
expectedFeeRateMilliMsat := int64(math.Round(testFeeBase * feeRate))

expectedPolicy := &lnrpc.RoutingPolicy{
FeeBaseMsat: baseFee,
FeeRateMilliMsat: expectedFeeRateMilliMsat,
TimeLockDelta: timeLockDelta,
MinHtlc: defaultMinHtlc,
MaxHtlcMsat: maxHtlc,
}

req := &lnrpc.PolicyUpdateRequest{
BaseFeeMsat: baseFee,
FeeRate: feeRate,
TimeLockDelta: timeLockDelta,
MaxHtlcMsat: maxHtlc,
Scope: &lnrpc.PolicyUpdateRequest_ChanPoint{
ChanPoint: chanPoint,
},
}

ctxb := context.Background()
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
if _, err := net.Alice.UpdateChannelPolicy(ctxt, req); err != nil {
t.Fatalf("unable to get alice's balance: %v", err)
}

// Make sure that both Alice and Bob sees the same policy after update.
assertPolicyUpdate(
t, nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
)

// Now use the new PPM feerate field and make sure that the feerate is
// correctly set.
feeRatePPM := uint32(32337)
req.FeeRate = 0 // Can't set both at the same time.
req.FeeRatePpm = feeRatePPM
expectedPolicy.FeeRateMilliMsat = int64(feeRatePPM)

ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
if _, err := net.Alice.UpdateChannelPolicy(ctxt, req); err != nil {
t.Fatalf("unable to get alice's balance: %v", err)
}

// Make sure that both Alice and Bob sees the same policy after update.
assertPolicyUpdate(
t, nodes, net.Alice.PubKeyStr, expectedPolicy, chanPoint,
)

}
4 changes: 4 additions & 0 deletions lntest/itest/lnd_test_list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ var allTestCases = []*testCase{
name: "update channel policy",
test: testUpdateChannelPolicy,
},
{
name: "update channel policy fee rate accuracy",
test: testUpdateChannelPolicyFeeRateAccuracy,
},
{
name: "open channel reorg test",
test: testOpenChannelAfterReorg,
Expand Down
Loading

0 comments on commit 09b1ae9

Please sign in to comment.