From 5c46edbe98ec669adc454607076f819bf0a2e96e Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 21 Oct 2022 02:06:48 -0400 Subject: [PATCH] Implement tendermint_machine::Block for Substrate Blocks Unfortunately, this immediately makes Tendermint machine capable of deployment as crate since it uses a git reference. In the future, a Cargo.toml patch section for serai/substrate should be investigated. This is being done regardless as it's the quickest way forward and this is for Serai. --- Cargo.lock | 1 + substrate/consensus/Cargo.toml | 2 +- substrate/tendermint/Cargo.toml | 5 +++++ substrate/tendermint/src/ext.rs | 8 ++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index df6df0fb..a929d337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8774,6 +8774,7 @@ version = "0.1.0" dependencies = [ "async-trait", "parity-scale-codec", + "sp-runtime", "tokio", ] diff --git a/substrate/consensus/Cargo.toml b/substrate/consensus/Cargo.toml index 4f58cde5..df8e54d9 100644 --- a/substrate/consensus/Cargo.toml +++ b/substrate/consensus/Cargo.toml @@ -25,7 +25,7 @@ sp-api = { git = "https://github.com/serai-dex/substrate" } sp-consensus = { git = "https://github.com/serai-dex/substrate" } sc-consensus = { git = "https://github.com/serai-dex/substrate" } -tendermint-machine = { path = "../tendermint" } +tendermint-machine = { path = "../tendermint", features = ["substrate"] } # -- diff --git a/substrate/tendermint/Cargo.toml b/substrate/tendermint/Cargo.toml index a6899672..b590e146 100644 --- a/substrate/tendermint/Cargo.toml +++ b/substrate/tendermint/Cargo.toml @@ -12,3 +12,8 @@ parity-scale-codec = { version = "3.2", features = ["derive"] } async-trait = "0.1" tokio = { version = "1", features = ["macros", "sync", "time", "rt"] } + +sp-runtime = { git = "https://github.com/serai-dex/substrate", optional = true } + +[features] +substrate = ["sp-runtime"] diff --git a/substrate/tendermint/src/ext.rs b/substrate/tendermint/src/ext.rs index 383376f1..aadb14e2 100644 --- a/substrate/tendermint/src/ext.rs +++ b/substrate/tendermint/src/ext.rs @@ -112,6 +112,14 @@ pub trait Block: Send + Sync + Clone + PartialEq + Debug + Encode + Decode { fn id(&self) -> Self::Id; } +#[cfg(feature = "substrate")] +impl Block for B { + type Id = B::Hash; + fn id(&self) -> B::Hash { + self.hash() + } +} + /// Trait representing the distributed system Tendermint is providing consensus over. #[async_trait::async_trait] pub trait Network: Send + Sync {