forked from informalsystems/tendermint-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes informalsystems#1134
- Loading branch information
Showing
10 changed files
with
808 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Added validator crate as per ADR-011 | ||
([#1134](https://github.com/informalsystems/tendermint-rs/issues/1134)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ members = [ | |
"std-ext", | ||
"tendermint", | ||
"test", | ||
"testgen" | ||
"testgen", | ||
"validator" | ||
] | ||
|
||
exclude = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
name = "tendermint-validator" | ||
version = "0.24.0-pre.2" | ||
authors = ["Informal Systems <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
readme = "README.md" | ||
categories = ["cryptography::cryptocurrencies", "network-programming"] | ||
keywords = ["privval", "validator", "blockchain", "bft", "consensus", "tendermint"] | ||
repository = "https://github.com/informalsystems/tendermint-rs" | ||
description = """ | ||
tendermint-validator provides a simple framework with which to build key management | ||
for Tendermint validators. | ||
""" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[features] | ||
default = ["flex-error/std", "flex-error/eyre_tracer"] | ||
|
||
[dependencies] | ||
ed25519-consensus = { version = "1.2", default-features = false } | ||
flex-error = { version = "0.4.4", default-features = false } | ||
rand_core = { version = "0.6", default-features = false, features = ["std"] } | ||
serde_json = "1" | ||
tempfile = { version = "3.2.0" } | ||
tendermint = { version = "0.24.0-pre.2", default-features = false, path = "../tendermint" } | ||
tendermint-proto = { version = "0.24.0-pre.2", default-features = false, path = "../proto", features = ["grpc"] } | ||
tokio = { version = "1", features = ["full"] } | ||
tokio-stream = { version = "0.1", features = ["net"] } | ||
tonic = { version = "0.7", features = ["tls", "transport"] } | ||
tracing = { version = "0.1", default-features = false } | ||
|
||
[dev-dependencies] | ||
tracing-subscriber = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// use std::collections::HashMap; | ||
|
||
// use ed25519_consensus::SigningKey; | ||
// use tendermint::account::Id; | ||
// use tendermint_validator::{ | ||
// BasicServerConfig, FileStateProvider, GrpcSocket, SoftwareSigner, SoftwareSignerServer, | ||
// }; | ||
|
||
use std::collections::HashMap; | ||
|
||
use tendermint::chain; | ||
use tendermint_validator::{ | ||
BasicServerConfig, FileStateProvider, GrpcSocket, KMSServer, SoftwareSigner, | ||
}; | ||
use tracing::Level; | ||
use tracing_subscriber::FmtSubscriber; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let subscriber = FmtSubscriber::builder() | ||
.with_max_level(Level::INFO) | ||
.finish(); | ||
let _ = tracing::subscriber::set_global_default(subscriber); | ||
let mut providers = HashMap::new(); | ||
let signer = SoftwareSigner::generate_ed25519(rand_core::OsRng); | ||
let state_provider = FileStateProvider::new("/tmp/validator.json".into()) | ||
.await | ||
.unwrap(); | ||
providers.insert( | ||
chain::Id::try_from("test-chain-4bmabt").unwrap(), | ||
(signer, state_provider), | ||
); | ||
let config = BasicServerConfig::new(None, GrpcSocket::Unix("/tmp/validator.test".into())); | ||
let server = KMSServer::new(providers, config).await.unwrap(); | ||
server.serve().await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! Validator configuration. | ||
use std::{net::SocketAddr, path::PathBuf}; | ||
|
||
use tonic::transport::ServerTlsConfig; | ||
|
||
/// The common options for listening for gRPC connections. | ||
#[derive(Debug, Clone)] | ||
pub enum GrpcSocket { | ||
/// the syntax in Tendermint config is "grpc://HOST:PORT" | ||
Tcp(SocketAddr), | ||
/// the syntax in Tendermint config is "grpc://unix:PATH" | ||
Unix(PathBuf), | ||
} | ||
|
||
/// The basic configuration for the gRPC server. | ||
#[derive(Debug, Clone)] | ||
pub struct BasicServerConfig { | ||
/// The optional TLS configuration. | ||
pub tls_config: Option<ServerTlsConfig>, | ||
/// The choice of a socket type to listen on. | ||
pub socket: GrpcSocket, | ||
} | ||
|
||
impl BasicServerConfig { | ||
/// creates a basic config for the gRPC server | ||
pub fn new(tls_config: Option<ServerTlsConfig>, socket: GrpcSocket) -> Self { | ||
Self { tls_config, socket } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! Validator errors (returned in a status via gRPC) | ||
use flex_error::{define_error, DetailOnly}; | ||
|
||
define_error! { | ||
Error { | ||
IoError{ | ||
path: String, | ||
} [DetailOnly<std::io::Error>] |e| { | ||
format_args!("Error persisting {}", e.path) | ||
}, | ||
JsonError{ | ||
path_or_msg: String, | ||
} [DetailOnly<serde_json::Error>] |e| { | ||
format_args!("Error parsing or serializing validator state {}", e.path_or_msg) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! A framework for building key management solutions for [Tendermint] validators in Rust. | ||
//! | ||
//! [Tendermint]: https://tendermint.com | ||
pub mod config; | ||
pub mod error; | ||
pub mod server; | ||
pub mod signer; | ||
pub mod state; | ||
|
||
pub use config::{BasicServerConfig, GrpcSocket}; | ||
pub use server::KMSServer; | ||
pub use signer::{SignerProvider, SoftwareSigner}; | ||
pub use state::{FileStateProvider, ValidatorStateProvider}; |
Oops, something went wrong.