loop: add peer rules to set rule command

pull/333/head
carla 3 years ago
parent 949e76bb2a
commit b9aae4f8f9
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -1,6 +1,7 @@
package main
import (
"bytes"
"context"
"errors"
"fmt"
@ -8,6 +9,7 @@ import (
"github.com/lightninglabs/loop/liquidity"
"github.com/lightninglabs/loop/looprpc"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/urfave/cli"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@ -42,9 +44,9 @@ func getParams(ctx *cli.Context) error {
var setLiquidityRuleCommand = cli.Command{
Name: "setrule",
Usage: "set liquidity manager rule for a channel",
Description: "Update or remove the liquidity rule for a channel.",
ArgsUsage: "shortchanid",
Usage: "set liquidity manager rule for a channel/peer",
Description: "Update or remove the liquidity rule for a channel/peer.",
ArgsUsage: "{shortchanid | peerpubkey}",
Flags: []cli.Flag{
cli.IntFlag{
Name: "incoming_threshold",
@ -58,8 +60,9 @@ var setLiquidityRuleCommand = cli.Command{
"that we do not want to drop below.",
},
cli.BoolFlag{
Name: "clear",
Usage: "remove the rule currently set for the channel.",
Name: "clear",
Usage: "remove the rule currently set for the " +
"channel/peer.",
},
},
Action: setRule,
@ -68,13 +71,22 @@ var setLiquidityRuleCommand = cli.Command{
func setRule(ctx *cli.Context) error {
// We require that a channel ID is set for this rule update.
if ctx.NArg() != 1 {
return fmt.Errorf("please set a channel id for the rule " +
"update")
return fmt.Errorf("please set a channel id or peer pubkey " +
"for the rule update")
}
var (
pubkey route.Vertex
pubkeyRule bool
)
chanID, err := strconv.ParseUint(ctx.Args().First(), 10, 64)
if err != nil {
return fmt.Errorf("could not parse channel ID: %v", err)
pubkey, err = route.NewVertexFromStr(ctx.Args().First())
if err != nil {
return fmt.Errorf("please provide a valid pubkey: "+
"%v, or short channel ID", err)
}
pubkeyRule = true
}
client, cleanup, err := getClient(ctx)
@ -101,11 +113,20 @@ func setRule(ctx *cli.Context) error {
)
// Run through our current set of rules and check whether we have a rule
// currently set for this channel. We also track a slice containing all
// of the rules we currently have set for other channels, because we
// want to leave these rules untouched.
// currently set for this channel or peer. We also track a slice
// containing all of the rules we currently have set for other channels,
// and peers because we want to leave these rules untouched.
for _, rule := range params.Rules {
if rule.ChannelId == chanID {
var (
channelRuleSet = rule.ChannelId != 0 &&
rule.ChannelId == chanID
peerRuleSet = rule.Pubkey != nil && bytes.Equal(
rule.Pubkey, pubkey[:],
)
)
if channelRuleSet || peerRuleSet {
ruleSet = true
} else {
otherRules = append(otherRules, rule)
@ -149,6 +170,10 @@ func setRule(ctx *cli.Context) error {
Type: looprpc.LiquidityRuleType_THRESHOLD,
}
if pubkeyRule {
newRule.Pubkey = pubkey[:]
}
if inboundSet {
newRule.IncomingThreshold = uint32(
ctx.Int("incoming_threshold"),

@ -609,6 +609,7 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
}
for peer, rule := range cfg.PeerRules {
peer := peer
rpcRule := newRPCRule(0, peer[:], rule)
rpcCfg.Rules = append(rpcCfg.Rules, rpcRule)
}

Loading…
Cancel
Save