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

Merge light clients config in relayer config and add commands to add/remove light clients #348

Merged
merged 15 commits into from
Nov 3, 2020

Conversation

romac
Copy link
Member

@romac romac commented Oct 29, 2020

Description

This PR merge the light clients config (previously in light_clients.toml) in the main relayer config and add commands to add/remove light clients.

Commands

relayer light

USAGE:
    relayer light <SUBCOMMAND>

DESCRIPTION:
    basic functionality for managing the lite clients

SUBCOMMANDS:
    add        add a light client peer for a given chain
    rm         remove a light client peer for a given chain

relayer light add

USAGE:
    relayer light add <OPTIONS>

DESCRIPTION:
    add a light client peer for a given chain

POSITIONAL ARGUMENTS:
    chain_id                  identifier of the chain

FLAGS:
    -i, --peer-id PEER-ID     peer id for this client
    -p, --primary             whether this is the primary peer
    -x, --hash HASH           trusted header hash
    -a, --address ADDRESS     RPC network address
    -h, --height HEIGHT       trusted header height

relayer light rm

USAGE:
    relayer light rm <OPTIONS>

DESCRIPTION:
    remove a light client peer for a given chain

POSITIONAL ARGUMENTS:
    chain_id                  identifier of the chain

FLAGS:
    -i, --peer-id PEER-ID     peer id for this client
    -f, --force               force removal of primary peer

Caveat

The main downside of this PR is that running either of the commands above will remove any comments or formatting in the config file. This could be improved by using format-preserving TOML parser/serializer (see toml_edit), but it would be a substantial amount of work to manually apply the config changes to the parsed TOML value with toml_edit. Definitely something to revisit in the future.

The main downside of this PR is that running either of the commands above will "scramble" the config file when writing the new configuration to it.

This stems from the fact I have not figured out a way to express our config structs so that they can be serialized to a TOML string directly via serde.

As a workaround, I am serializing the config struct to a TOML Value first and then serializing that to a string. Unfortunately, this does not respect the field order of the Rust structs and thus scrambles the original file (but preserves its semantics, thankfully).

I see a few potential ways out of that:

a) figure out how to express the config so that it can be directly serialized to a TOML string via Serde (no luck so far)
b) use a format-preserving TOML parser/serializer (see toml_edit)
c) move to another config format (Dhall, RON, ?)

Pros

a) quick fix if we can figure it out
b) would preserve formatting and comments
c) no need to massage our config struct to fit into what's accepted by TOML

Cons

a) comments and formatting would still be lost
b) it might take a substantial amount of work to manually apply the config changes to the parsed TOML value with toml_edit.
c) comments and formatting would still be lost


For contributor use:

  • Updated the Unreleased section of CHANGELOG.md with the issue.
  • If applicable: Unit tests written, added test to CI.
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments.
  • Re-reviewed Files changed in the Github PR explorer.

@ancazamfir
Copy link
Collaborator

ancazamfir commented Oct 30, 2020

My concern with these commands is UX, the user has to do some work to retrieve the peer-id, hash, height, etc.
This could be done by the command itself:

USAGE:
    relayer-cli light add <OPTIONS>

DESCRIPTION:
    add a light client peer for a given chain

POSITIONAL ARGUMENTS:
    address                 RPC network address

FLAGS:
    -p, --primary             whether this is the primary peer
    -f, --force               allow overriding an existing peer

And obtain all the info from the status() rpc to the address specified, i.e. from network, id, latest_block_hash, latest_block_height.
Maybe one way is to allow only the address to be specified and in this case retrieve what is needed from status().

#[serde(default = "default::trusting_period", with = "humantime_serde")]
pub trusting_period: Duration,
#[serde(default)]
pub trust_threshold: TrustThreshold,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be in the client config? Same question for the trusting_period? Different apps may use different clients of same chain if they have different security requirements.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Tracked in #356

@romac
Copy link
Member Author

romac commented Nov 2, 2020

Good point! Couple questions:

  1. Is there any value in letting the user specify the height they want to trust?
  2. What do you think of having the command print out the details it fetched from the node and ask for confirmation? Is that overkill?

@ancazamfir
Copy link
Collaborator

ancazamfir commented Nov 2, 2020

Good point! Couple questions:

  1. Is there any value in letting the user specify the height they want to trust?

I think the user should be able to specify any number of params, at the minimum the rpc address. If height is specified then it should be used. If hash is specified then height must also be. But to start with, if we can allow just the address it will go a long way, especially in the development phase, CI integration and initial release with lower focus on security.

  1. What do you think of having the command print out the details it fetched from the node and ask for confirmation? Is that overkill?

That would be nice :)

@romac
Copy link
Member Author

romac commented Nov 2, 2020

But to start with, if we can allow just the address it will go a long way, especially in the development phase, CI integration and initial release with lower focus on security.

Done.


Here's the new usage of the light add command:

USAGE:
    relayer light add <OPTIONS>

DESCRIPTION:
    add a light client peer for a given chain

POSITIONAL ARGUMENTS:
    address                   RPC network address

FLAGS:
    -c, --chain-id CHAIN-ID   identifier of the chain
    -p, --primary             whether this is the primary peer
    -f, --force               allow overriding an existing peer
    -y, --yes                 skip confirmation

I also adapted the options for the light rm command for consistency with the new light add options:

USAGE:
    relayer light rm <OPTIONS>

DESCRIPTION:
    remove a light client peer for a given chain

POSITIONAL ARGUMENTS:
    peer_id                   peer id for this client

FLAGS:
    -c, --chain-id CHAIN-ID   identifier of the chain
    -f, --force               force removal of primary peer

Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks Romain!

@romac romac merged commit 5f314e5 into master Nov 3, 2020
@romac romac deleted the romac/light-config branch November 3, 2020 15:40
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
…remove light clients (informalsystems#348)

* Implement command to add light client peer

* Implement command to remove light client peer

* Refactor config

* Formatting

* Cleanup

* Cleanup deps

* Fix start command

* Cleanup example config

* Add test for serializing config

* Fix TOML serialization issue

* Comments, bugfix, and better names

* Fetch peer id, block hash and height from given node via RPC

* Adapt light rm options for consistency with light add

* Update changelog
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.

2 participants