Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

tendermint-rs: Add TendermintConfig and Error(Kind) types #298

Merged
merged 1 commit into from
Jul 23, 2019

Conversation

tony-iqlusion
Copy link
Contributor

Adds types which describes the structure of config.toml files, and support for parsing them with serde and the toml crate.

This should describe every configuration field generated by the default boilerplate.

Additionally this commit changes the Error type in tendermint-rs from an enum to a struct, renaming the original Error enum to ErrorKind. This allows incorporating additional information into each error: this commit uses it to add a "msg" field to each error which is needed to get reasonable parse errors from config files, however since it's built on the failure crate and using a failure::Context, this will also capture a backtrace at the time the error is generated.

The change from Error to ErrorKind is incomplete: several parts of the API are now returning ErrorKind instead of error. All call sites should probably return Error instead of ErrorKind before a final crate release.

@tarcieri tarcieri force-pushed the tendermint-rs/config branch 3 times, most recently from 3344f23 to 69693e9 Compare July 22, 2019 20:39
@tony-iqlusion tony-iqlusion changed the title [WIP] tendermint-rs: Add TendermintConfig and Error(Kind) types tendermint-rs: Add TendermintConfig and Error(Kind) types Jul 22, 2019
@tony-iqlusion tony-iqlusion marked this pull request as ready for review July 22, 2019 20:39
@tarcieri tarcieri requested a review from ebuchman July 23, 2019 01:20

/// Is this configuration for a validator?
pub fn is_validator(&self) -> bool {
self.priv_validator_key_file.is_some() || self.priv_validator_laddr.is_some()
Copy link
Contributor

Choose a reason for hiding this comment

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

default tendermint config has a validator key file but isn't necessarily for a validator


/// Loglevel configuration
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct LogLevel(BTreeMap<String, String>);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not a HashMap?

Copy link
Contributor

@tarcieri tarcieri Jul 23, 2019

Choose a reason for hiding this comment

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

The main things I like about BTreeMap over HashMap is you always get a deterministic ordering (i.e. the elements are ordered) and by avoiding the use of a hash function they're naturally hashDoS resistant, so I generally use them anywhere the key type impls Ord. That all comes at the cost of slightly more memory usage.

Adds types which describes the structure of `config.toml` files, and
support for parsing them with serde and the `toml` crate.

This should describe every configuration field generated by the default
boilerplate.

Additionally this commit changes the `Error` type in `tendermint-rs`
from an enum to a struct, renaming the original `Error` enum to
`ErrorKind`. This allows incorporating additional information into each
error: this commit uses it to add a "msg" field to each error which is
needed to get reasonable parse errors from config files, however since
it's built on the `failure` crate and using a `failure::Context`, this
will also capture a backtrace at the time the error is generated.

Last but certainly not least, this adds parsers and serializers for the
`node_key.json` and `priv_validator_key.json` configuration files as
well, along with a new `tendermint::private_key::PrivateKey` type for
Ed25519 keypairs.
@tarcieri tarcieri merged commit db62cbe into master Jul 23, 2019
@tarcieri tarcieri deleted the tendermint-rs/config branch July 23, 2019 16:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants