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

update tendermint config #897

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/unreleased/bug-fixes/897-outdated-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `[tendermint]` Update TendermintConfig for Tendermint v.0.34.x ([#897](https://github.com/informalsystems/tendermint-rs/issues/897))
175 changes: 139 additions & 36 deletions tendermint/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod priv_validator_key;
pub use self::{node_key::NodeKey, priv_validator_key::PrivValidatorKey};

use crate::{
abci::tag,
error::{Error, Kind},
genesis::Genesis,
net, node, Moniker, Timeout,
Expand Down Expand Up @@ -41,7 +40,7 @@ pub struct TendermintConfig {
/// and verifying their commits
pub fast_sync: bool,

/// Database backend: `leveldb | memdb | cleveldb`
/// Database backend: `goleveldb | cleveldb | boltdb | rocksdb | badgerdb`
pub db_backend: DbBackend,

/// Database directory
Expand Down Expand Up @@ -75,10 +74,6 @@ pub struct TendermintConfig {
/// Mechanism to connect to the ABCI application: socket | grpc
pub abci: AbciMode,

/// TCP or UNIX socket address for the profiling server to listen on
#[serde(deserialize_with = "deserialize_optional_value")]
pub prof_laddr: Option<net::Address>,

/// If `true`, query the ABCI app on connecting to a new peer
/// so the app can decide if we should keep the connection or not
pub filter_peers: bool,
Expand All @@ -100,6 +95,12 @@ pub struct TendermintConfig {

/// instrumentation configuration options
pub instrumentation: InstrumentationConfig,

/// statesync configuration options
pub statesync: StatesyncConfig,

/// fastsync configuration options
pub fastsync: FastsyncConfig,
}

impl TendermintConfig {
Expand Down Expand Up @@ -144,35 +145,50 @@ impl TendermintConfig {
/// Database backend
#[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum DbBackend {
/// LevelDB backend
#[serde(rename = "leveldb")]
LevelDb,

/// MemDB backend
#[serde(rename = "memdb")]
MemDb,
/// GoLevelDB backend
#[serde(rename = "goleveldb")]
GoLevelDb,

/// CLevelDB backend
#[serde(rename = "cleveldb")]
CLevelDb,

/// BoltDB backend
#[serde(rename = "boltdb")]
BoltDb,

/// RocksDB backend
#[serde(rename = "rocksdb")]
RocksDb,

/// BadgerDB backend
#[serde(rename = "badgerdb")]
BadgerDb,
}

/// Loglevel configuration
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct LogLevel(BTreeMap<String, String>);
pub struct LogLevel {
/// A global log level
pub global: Option<String>,
components: BTreeMap<String, String>,
}

impl LogLevel {
/// Get the setting for the given key
/// Get the setting for the given key. If not found, returns the global setting, if any.
pub fn get<S>(&self, key: S) -> Option<&str>
where
S: AsRef<str>,
{
self.0.get(key.as_ref()).map(AsRef::as_ref)
self.components
.get(key.as_ref())
.or_else(|| self.global.as_ref())
.map(AsRef::as_ref)
}

/// Iterate over the levels
/// Iterate over the levels. This doesn't include the global setting, if any.
pub fn iter(&self) -> LogLevelIter<'_> {
self.0.iter()
self.components.iter()
}
}

Expand All @@ -183,33 +199,43 @@ impl FromStr for LogLevel {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut levels = BTreeMap::new();
let mut global = None;
let mut components = BTreeMap::new();

for level in s.split(',') {
let parts = level.split(':').collect::<Vec<_>>();

if parts.len() != 2 {
if parts.len() == 1 {
global = Some(parts[0].to_owned());
continue;
} else if parts.len() != 2 {
fail!(Kind::Parse, "error parsing log level: {}", level);
}

let key = parts[0].to_owned();
let value = parts[1].to_owned();

if levels.insert(key, value).is_some() {
if components.insert(key, value).is_some() {
fail!(Kind::Parse, "duplicate log level setting for: {}", level);
}
}

Ok(LogLevel(levels))
Ok(LogLevel { global, components })
}
}

impl fmt::Display for LogLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for (i, (k, v)) in self.0.iter().enumerate() {
if let Some(global) = &self.global {
write!(f, "{}", global)?;
if !self.components.is_empty() {
write!(f, ",")?;
}
}
for (i, (k, v)) in self.components.iter().enumerate() {
write!(f, "{}:{}", k, v)?;

if i < self.0.len() - 1 {
if i < self.components.len() - 1 {
write!(f, ",")?;
}
}
Expand Down Expand Up @@ -298,13 +324,23 @@ pub struct RpcConfig {
/// How long to wait for a tx to be committed during `/broadcast_tx_commit`.
pub timeout_broadcast_tx_commit: Timeout,

/// Maximum size of request body, in bytes
pub max_body_bytes: u64,

/// Maximum size of request header, in bytes
pub max_header_bytes: u64,

/// The name of a file containing certificate that is used to create the HTTPS server.
#[serde(deserialize_with = "deserialize_optional_value")]
pub tls_cert_file: Option<PathBuf>,

/// The name of a file containing matching private key that is used to create the HTTPS server.
#[serde(deserialize_with = "deserialize_optional_value")]
pub tls_key_file: Option<PathBuf>,

/// pprof listen address <https://golang.org/pkg/net/http/pprof>
#[serde(deserialize_with = "deserialize_optional_value")]
pub pprof_laddr: Option<net::Address>,
}

/// Origin hosts allowed with CORS requests to the RPC API
Expand Down Expand Up @@ -401,6 +437,16 @@ pub struct P2PConfig {
/// Maximum number of outbound peers to connect to, excluding persistent peers
pub max_num_outbound_peers: u64,

/// List of node IDs, to which a connection will be (re)established ignoring any existing limits
#[serde(
serialize_with = "serialize_comma_separated_list",
deserialize_with = "deserialize_comma_separated_list"
)]
pub unconditional_peer_ids: Vec<node::Id>,

/// Maximum pause when redialing a persistent peer (if zero, exponential backoff is used)
pub persistent_peers_max_dial_period: Timeout,

/// Time to wait before flushing messages out on the connection
pub flush_throttle_timeout: Timeout,

Expand Down Expand Up @@ -462,6 +508,21 @@ pub struct MempoolConfig {

/// Size of the cache (used to filter transactions we saw earlier) in transactions
pub cache_size: u64,

/// Do not remove invalid transactions from the cache (default: false)
/// Set to true if it's not possible for any invalid transaction to become valid
/// again in the future.
#[serde(rename = "keep-invalid-txs-in-cache")]
pub keep_invalid_txs_in_cache: bool,

/// Maximum size of a single transaction.
/// NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
pub max_tx_bytes: u64,

/// Maximum size of a batch of transactions to send to a peer
/// Including space needed by encoding (one varint per transaction).
/// XXX: Unused due to <https://github.com/tendermint/tendermint/issues/5796>
pub max_batch_bytes: u64,
}

/// consensus configuration options
Expand Down Expand Up @@ -491,6 +552,12 @@ pub struct ConsensusConfig {
/// Commit timeout
pub timeout_commit: Timeout,

/// How many blocks to look back to check existence of the node's consensus votes before joining consensus
/// When non-zero, the node will panic upon restart
/// if the same consensus key was used to sign {double-sign-check-height} last blocks.
/// So, validators should stop the state machine, wait for some blocks, and then restart the state machine to avoid panic.
pub double_sign_check_height: u64,

/// Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
pub skip_timeout_commit: bool,

Expand All @@ -513,18 +580,6 @@ pub struct TxIndexConfig {
/// What indexer to use for transactions
#[serde(default)]
pub indexer: TxIndexer,

/// Comma-separated list of tags to index (by default the only tag is `tx.hash`)
// TODO(tarcieri): switch to `tendermint::abci::Tag`
#[serde(
serialize_with = "serialize_comma_separated_list",
deserialize_with = "deserialize_comma_separated_list"
)]
pub index_tags: Vec<tag::Key>,

/// When set to true, tells indexer to index all tags (predefined tags:
/// `tx.hash`, `tx.height` and all tags from DeliverTx responses).
pub index_all_tags: bool,
}

/// What indexer to use for transactions
Expand Down Expand Up @@ -565,6 +620,54 @@ pub struct InstrumentationConfig {
pub namespace: String,
}

/// statesync configuration options
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct StatesyncConfig {
/// State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine
/// snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in
/// the network to take and serve state machine snapshots. State sync is not attempted if the node
/// has any local state (LastBlockHeight > 0). The node will have a truncated block history,
/// starting from the height of the snapshot.
pub enable: bool,

/// RPC servers (comma-separated) for light client verification of the synced state machine and
/// retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding
/// header hash obtained from a trusted source, and a period during which validators can be trusted.
///
/// For Cosmos SDK-based chains, trust-period should usually be about 2/3 of the unbonding time (~2
/// weeks) during which they can be financially punished (slashed) for misbehavior.
#[serde(
serialize_with = "serialize_comma_separated_list",
deserialize_with = "deserialize_comma_separated_list"
)]
pub rpc_servers: Vec<String>,

/// Trust height. See `rpc_servers` above.
pub trust_height: u64,

/// Trust hash. See `rpc_servers` above.
pub trust_hash: String,

/// Trust period. See `rpc_servers` above.
pub trust_period: String,

/// Time to spend discovering snapshots before initiating a restore.
pub discovery_time: Timeout,

/// Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp).
/// Will create a new, randomly named directory within, and remove it when done.
pub temp_dir: String,
}

/// fastsync configuration options
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FastsyncConfig {
/// Fast Sync version to use:
/// 1) "v0" (default) - the legacy fast sync implementation
/// 2) "v2" - complete redesign of v0, optimized for testability & readability
pub version: String,
}

/// Rate at which bytes can be sent/received
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
pub struct TransferRate(u64);
Expand Down
12 changes: 3 additions & 9 deletions tendermint/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ mod files {
);
assert_eq!(config.moniker.as_ref(), "technodrome");
assert!(config.fast_sync);
assert_eq!(config.db_backend, DbBackend::LevelDb);
assert_eq!(config.db_backend, DbBackend::GoLevelDb);
assert_eq!(config.db_dir, PathBuf::from("data"));
assert_eq!(config.log_level.global, Some("info".to_string()));
assert_eq!(config.log_level.get("main"), Some("info"));
assert_eq!(config.log_level.get("state"), Some("info"));
assert_eq!(config.log_level.get("*"), Some("error"));
assert_eq!(config.log_level.get("*"), Some("info"));
assert_eq!(config.log_format, LogFormat::Plain);
assert_eq!(config.genesis_file, PathBuf::from("config/genesis.json"));
assert_eq!(
Expand All @@ -44,10 +45,6 @@ mod files {
assert_eq!(config.priv_validator_laddr, None);
assert_eq!(config.node_key_file, PathBuf::from("config/node_key.json"));
assert_eq!(config.abci, AbciMode::Socket);
assert_eq!(
config.prof_laddr,
Some("tcp://localhost:6060".parse::<net::Address>().unwrap())
);
assert!(!config.filter_peers);

// rpc server configuration options
Expand Down Expand Up @@ -188,9 +185,6 @@ mod files {

let tx_index = &config.tx_index;
assert_eq!(tx_index.indexer, TxIndexer::Kv);
assert_eq!(tx_index.index_tags.len(), 1);
assert_eq!(tx_index.index_tags[0].as_ref(), "tx.height");
assert!(tx_index.index_all_tags);

// instrumentation configuration options

Expand Down
Loading