Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autopilot: generic rules per feature #634

Merged

Conversation

bitromortac
Copy link
Contributor

@bitromortac bitromortac commented Aug 29, 2023

We would like to be able to set different rules for different features. This is solved by introducing JSON-serialized (per-feature) rule flags where all the rules from litcli autopilot features can be set.

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First code review looks good 🚀fire:! Awaiting rebase before testing.

how do we signal empty restrictions for more than a single feature? currently we have to repeat the restrictions as often as the number of features, which requires to set several flags (a flag --feature-peer-restrict-list="" does not count)

Given that we opted for this version with feature configurations, I think it makes sense to do it like you've implemented it in this PR.

could we transition to json-style lists like "[item1,item1]" to signal empty restrictions with "[]", similarly to the feature configuration?

No strong opinion here, as long as we keep it consistent.

We change the flags to have a feature prefix, which is a breaking change.

Just a thought, would it make sense to keep the old flags as well for now, i.e. "channel-restrict-list" & "peer-restrict-list" but mark them as deprecated and remove them later to not make this a breaking change with this PR? And if the old flags are set, we keep the old behaviour, but also make sure that only one version of the flags are set and error if both versions are set. Do you think that would make sense?

Usage: `List of channel IDs that the ` +
`Autopilot server should not ` +
`perform actions on. In the ` +
`form of: [chanID1,chanID2,...]. ` +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
Should be as below, correct?

Suggested change
`form of: [chanID1,chanID2,...]. ` +
`form of: ["chanID1","chanID2",...]. ` +

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that was intentional, we would error to parse into []int64 otherwise

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we are here, let's clear up this confusion by specifying that this should be a list of numbers. Since even in LND, there is a ChannelID which is a uint64 and another which is a string ([32]byte)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a disadvantage of the generic flags is that it's not as well documented

@bitromortac
Copy link
Contributor Author

Rebased the PR.

Just a thought, would it make sense to keep the old flags as well for now, i.e. "channel-restrict-list" & "peer-restrict-list" but mark them as deprecated and remove them later to not make this a breaking change with this PR? And if the old flags are set, we keep the old behaviour, but also make sure that only one version of the flags are set and error if both versions are set. Do you think that would make sense?

Am with you there, will check if it's worth to keep them backwards compatible.

I also found a small issue which is preexisting: ListChannels error: rpc error: code = Unknown desc = error parsing rules: invalid channel ID, which is related to the channel restrictions. It happens when an unknown channel id restriction, say channel id of 123456 is passed. Will also try to provide a fix.

@ellemouton
Copy link
Member

Will also try to provide a fix.

@bitromortac - is this ready for review?

Copy link
Member

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! will test on next round 👍

cmd/litcli/autopilot.go Outdated Show resolved Hide resolved
Usage: `List of channel IDs that the ` +
`Autopilot server should not ` +
`perform actions on. In the ` +
`form of: [chanID1,chanID2,...]. ` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we are here, let's clear up this confusion by specifying that this should be a list of numbers. Since even in LND, there is a ChannelID which is a uint64 and another which is a string ([32]byte)

"perform actions on. In the " +
"form of: chanID1,chanID2,...",
cli.StringSliceFlag{
Name: "feature-channel-restrict-list",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically this rename is a backwards incompatible change... imo it is fine since I dont think anyone is using this at the command line level yet. But perhaps something we should at least include in the release notes? (btw, I think we should have a running issue per release where we keep track of notes we want to make in the release so that we dont forget cc @ViktorTigerstrom )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move these to be next to feature-config just so that all the per-feature flags are together?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah - I saw @ViktorTigerstrom's suggestion now re keeping the old flags for now.

We could do that and then add a waring and a todo that they will be removed in the release after the next one. That's definitely the more friendly way of doing things :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, I changed it to remain backwards compatible

cmd/litcli/autopilot.go Outdated Show resolved Hide resolved
cmd/litcli/autopilot.go Outdated Show resolved Hide resolved
@bitromortac
Copy link
Contributor Author

I changed this PR to include generic feature rule setting via JSON flags. Legacy flags are preserved and marked for deprecation.

@bitromortac bitromortac changed the title autopilot: per feature peer and channel restrictions autopilot: generic rules per feature Jan 26, 2024
@lightninglabs-deploy
Copy link

@ViktorTigerstrom: review reminder
@ellemouton: review reminder

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK LGTM 🔥🚀!!

Great work!! Thanks for addressing the feedback about adding deprecating support 🚀!

Just adding some minor feedback in my comments below that's not blocking.

Also, I'd just like to show two examples of adding an autopilot session that intuitively probably shouldn't be accepted by the parsing, but that is. We probably don't really need to address these examples though, but feel free to address them if you want:

  1. When using the legacy version of setting the peer-restrict-list arg with multiple features, if you add multiple peer-restrict-list args where the last arg is set to "", that is accepted:
    litcli autopilot a --label="test" --feature=AutoFees --peer-restrict-list="peerID1" --feature=SampleFeature --peer-restrict-list=""
  2. If the same feature is specified more than once when adding a autpilot session, that's accepted and only the last version is used:
    litcli autopilot a --label="test" --feature=AutoFees --feature-rules="{\"rules\":{}}" --feature=AutoFees --feature-rules="{\"rules\":{\"channel-restriction\":{\"channel_restrict\":{\"channel_ids\":[chanID1]}}}}"

cmd/litcli/autopilot.go Outdated Show resolved Hide resolved
Comment on lines 58 to 81
"rate-limit": {
"rate_limit": {
"read_limit": {
"iterations": 10,
"num_hours": 1
},
"write_limit": {
"iterations": 1,
"num_hours": 1
}
}
},
"channel-restriction": {
"channel_restrict": {
"channel_ids": [
18283782789,
22891928322,
31878293727
]
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
Since this enables users to set any of the rules now, I do think that:

  1. It makes sense to give an example for all types rules the user can set, i.e. also include examples of the channel-policy-bounds, history-limit & peer-restriction rule types here.
  2. Clarify in the docs that if a specific rule type is not set, the default values will be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good calls, concerning 1, I have added the most interesting rules for AutoFees, but left others away since I think it would add too much help output and it should be clear how to apply the pattern. I updated the help text a bit more to give more hints on how to correctly set rules. I've added that comment for 2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but left others away since I think it would add too much help output and it should be clear how to apply the pattern

Ok thanks for the edits :)! Sure, I see your point, let's avoid adding too much output. In case we end up getting lot's of user questions of how to apply a specific rule in the future, we can always revisit this and add more info :)!

This commit adds generic feature rule flags. Legacy flags
`channel-restrict-list` and `peer-restrict-list` are deprecated.
@bitromortac
Copy link
Contributor Author

Also, I'd just like to show two examples of adding an autopilot session that intuitively probably shouldn't be accepted by the parsing, but that is. We probably don't really need to address these examples though, but feel free to address them if you want:

1. When using the legacy version of setting the `peer-restrict-list` arg with multiple features, if you add multiple `peer-restrict-list` args where the last arg is set to "", that is accepted:
   `litcli autopilot a --label="test" --feature=AutoFees --peer-restrict-list="peerID1" --feature=SampleFeature --peer-restrict-list=""`

2. If the same feature is specified more than once when adding a autpilot session, that's accepted and only the last version is used:
   `litcli autopilot a --label="test" --feature=AutoFees --feature-rules="{\"rules\":{}}" --feature=AutoFees --feature-rules="{\"rules\":{\"channel-restriction\":{\"channel_restrict\":{\"channel_ids\":[chanID1]}}}}"`

Thanks for the review and testing 🙏 @ViktorTigerstrom, those issues should be fixed in the latest version, great calls!

Copy link
Member

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks for this 🔥

@ViktorTigerstrom - will leave it to you to merge just incase you had anything to add re the latest updates to your feedback :)

@ViktorTigerstrom
Copy link
Contributor

Also, I'd just like to show two examples of adding an autopilot session that intuitively probably shouldn't be accepted by the parsing, but that is. We probably don't really need to address these examples though, but feel free to address them if you want:

1. When using the legacy version of setting the `peer-restrict-list` arg with multiple features, if you add multiple `peer-restrict-list` args where the last arg is set to "", that is accepted:
   `litcli autopilot a --label="test" --feature=AutoFees --peer-restrict-list="peerID1" --feature=SampleFeature --peer-restrict-list=""`

2. If the same feature is specified more than once when adding a autpilot session, that's accepted and only the last version is used:
   `litcli autopilot a --label="test" --feature=AutoFees --feature-rules="{\"rules\":{}}" --feature=AutoFees --feature-rules="{\"rules\":{\"channel-restriction\":{\"channel_restrict\":{\"channel_ids\":[chanID1]}}}}"`

Thanks for the review and testing 🙏 @ViktorTigerstrom, those issues should be fixed in the latest version, great calls!

Thanks for the fixes, they look great 🙏!

@ViktorTigerstrom ViktorTigerstrom merged commit 6bc86e5 into lightninglabs:master Feb 12, 2024
12 checks passed
@bitromortac bitromortac deleted the per-feature-restrictions branch April 17, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants