-
Notifications
You must be signed in to change notification settings - Fork 43
tendermint-rs: Add TendermintConfig and Error(Kind) types #298
Conversation
3344f23
to
69693e9
Compare
69693e9
to
6df0471
Compare
6df0471
to
55022b0
Compare
tendermint-rs/src/config.rs
Outdated
|
||
/// 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() |
There was a problem hiding this comment.
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>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not a HashMap?
There was a problem hiding this comment.
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.
55022b0
to
e1fd1bb
Compare
Adds types which describes the structure of
config.toml
files, and support for parsing them with serde and thetoml
crate.This should describe every configuration field generated by the default boilerplate.
Additionally this commit changes the
Error
type intendermint-rs
from an enum to a struct, renaming the originalError
enum toErrorKind
. 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 thefailure
crate and using afailure::Context
, this will also capture a backtrace at the time the error is generated.The change from
Error
toErrorKind
is incomplete: several parts of the API are now returningErrorKind
instead of error. All call sites should probably returnError
instead ofErrorKind
before a final crate release.