Skip to content
Open
4 changes: 2 additions & 2 deletions .github/workflows/rust-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Build the project
run: |
cargo build --release --workspace
cargo build --release --features madara-runtime --workspace

- name: Run integration tests
run: cargo test --release
run: cargo test --features madara-runtime --release
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@
madara node
- feat(cache-option): add an option to enable aggressive caching in command-line
parameters
- feat: Added a `madara-hotstuff-runtime` runtime that replaces the Grandpa
pallet with the HotStuff pallet
- feat: Added two features, `madara-hotstuff-runtime` and `madara-runtime`,
which are used to select between HotStuff and Grandpa consensus at
compile-time. Running `cargo build --features madara-hotstuff-runtime` will
use HotStuff consensus to replace Grandpa consensus, while using
`cargo build --features madara-runtime` will use the original runtime with
Grandpa consensus

## v0.4.0

Expand Down
127 changes: 127 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
resolver = "2"
members = [
"crates/node",
"crates/runtime",
"crates/runtime/madara",
"crates/runtime/madara-hotstuff",
"crates/pallets/starknet/runtime_api/",
"crates/pallets/starknet",
"crates/primitives/digest-log",
Expand All @@ -28,7 +29,8 @@ members = [
# We don't want `cargo test` to trigger its tests
default-members = [
"crates/node",
"crates/runtime",
"crates/runtime/madara",
"crates/runtime/madara-hotstuff",
"crates/pallets/starknet/runtime_api/",
"crates/pallets/starknet",
"crates/primitives/digest-log",
Expand Down Expand Up @@ -173,7 +175,8 @@ mc-data-availability = { path = "crates/client/data-availability" }
mc-commitment-state-diff = { path = "crates/client/commitment-state-diff" }

# Madara runtime
madara-runtime = { path = "crates/runtime" }
madara-runtime = { path = "crates/runtime/madara" }
madara-hotstuff-runtime = { path = "crates/runtime/madara-hotstuff" }

# Starknet dependencies
# Cairo Virtual Machine
Expand Down Expand Up @@ -203,6 +206,11 @@ cairo-lang-casm-contract-class = { git = "https://github.com/keep-starknet-stran
cairo-lang-casm = { git = "https://github.com/keep-starknet-strange/cairo.git", branch = "no_std-support-8bbf530", default-features = false }
cairo-lang-utils = { git = "https://github.com/keep-starknet-strange/cairo.git", branch = "no_std-support-8bbf530", default-features = false }

# Hotstuff consensus
hotstuff-consensus = { git = "https://github.com/Generative-Labs/Substrate-HotStuff.git" }
hotstuff-primitives = { git = "https://github.com/Generative-Labs/Substrate-HotStuff.git", default-features = false }
pallet-hotstuff = { git = "https://github.com/Generative-Labs/Substrate-HotStuff.git", default-features = false }

# Other third party dependencies
anyhow = "1.0.75"
flate2 = "1.0.28"
Expand Down
7 changes: 7 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ frame-benchmarking-cli = { workspace = true }
# Starknet
blockifier = { workspace = true }
hex = { workspace = true }
madara-hotstuff-runtime = { workspace = true }
madara-runtime = { workspace = true }
mc-commitment-state-diff = { workspace = true }
mc-data-availability = { workspace = true }
Expand All @@ -102,6 +103,10 @@ reqwest = { workspace = true }
serde_json = { workspace = true }
url = { workspace = true }

# Hotstuff dependencies
hotstuff-consensus = { workspace = true }
hotstuff-primitives = { workspace = true }

[build-dependencies]
substrate-build-script-utils = { workspace = true }

Expand All @@ -120,3 +125,5 @@ disable-transaction-fee = ["madara-runtime/disable-transaction-fee"]
# Load sharingan chain-specs during the compilation
# This is the way to run a sharingan chain
sharingan = []

with-hotstuff-runtime = []
3 changes: 3 additions & 0 deletions crates/node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
use std::sync::Arc;
use std::time::Duration;

#[cfg(feature = "with-hotstuff-runtime")]
use madara_hotstuff_runtime as runtime;
#[cfg(not(feature = "with-hotstuff-runtime"))]
use madara_runtime as runtime;
use runtime::SystemCall;
use sc_cli::Result;
Expand Down
18 changes: 15 additions & 3 deletions crates/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use std::path::PathBuf;

use hotstuff_primitives::AuthorityId as HotStuffId;
#[cfg(feature = "with-hotstuff-runtime")]
use madara_hotstuff_runtime::{
AuraConfig, HotstuffConfig, RuntimeGenesisConfig, SealingMode, SystemConfig, WASM_BINARY,
};
#[cfg(not(feature = "with-hotstuff-runtime"))]
use madara_runtime::{AuraConfig, GrandpaConfig, RuntimeGenesisConfig, SealingMode, SystemConfig, WASM_BINARY};
use mp_felt::Felt252Wrapper;
use pallet_starknet::genesis_loader::{GenesisData, GenesisLoader, HexFelt};
Expand Down Expand Up @@ -39,7 +45,10 @@ pub struct DevGenesisExt {
impl sp_runtime::BuildStorage for DevGenesisExt {
fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> {
BasicExternalities::execute_with_storage(storage, || {
#[cfg(feature = "madara-runtime")]
madara_runtime::Sealing::set(&self.sealing);
#[cfg(feature = "madara-hotstuff-runtime")]
madara_hotstuff_runtime::Sealing::set(&self.sealing);
});
self.genesis_config.assimilate_storage(storage)
}
Expand All @@ -51,8 +60,8 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
}

/// Generate an Aura authority key.
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId, HotStuffId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s), get_from_seed::<HotStuffId>(s))
}

pub fn development_config(sealing: SealingMode, base_path: BasePath) -> Result<DevChainSpec, String> {
Expand Down Expand Up @@ -165,7 +174,7 @@ fn load_genesis(data_path: PathBuf) -> GenesisLoader {
fn testnet_genesis(
genesis_loader: GenesisLoader,
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
initial_authorities: Vec<(AuraId, GrandpaId, HotStuffId)>,
_enable_println: bool,
) -> RuntimeGenesisConfig {
let starknet_genesis_config: madara_runtime::pallet_starknet::GenesisConfig<_> = genesis_loader.into();
Expand All @@ -179,11 +188,14 @@ fn testnet_genesis(
// Authority-based consensus protocol used for block production
aura: AuraConfig { authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect() },
// Deterministic finality mechanism used for block finalization
#[cfg(not(feature = "with-hotstuff-runtime"))]
grandpa: GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
_config: Default::default(),
},
/// Starknet Genesis configuration.
starknet: starknet_genesis_config,
#[cfg(feature = "with-hotstuff-runtime")]
hotstuff: HotstuffConfig { authorities: initial_authorities.iter().map(|x| (x.2.clone())).collect() },
}
}
3 changes: 3 additions & 0 deletions crates/node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
#[cfg(feature = "with-hotstuff-runtime")]
use madara_hotstuff_runtime::Block;
#[cfg(not(feature = "with-hotstuff-runtime"))]
use madara_runtime::Block;
use sc_cli::{ChainSpec, SubstrateCli};

Expand Down
4 changes: 4 additions & 0 deletions crates/node/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::path::PathBuf;

#[cfg(feature = "with-hotstuff-runtime")]
use madara_hotstuff_runtime::SealingMode;
#[cfg(not(feature = "with-hotstuff-runtime"))]
use madara_runtime::SealingMode;
use mc_data_availability::DaLayer;
use sc_cli::{Result, RpcMethods, RunCmd, SubstrateCli};
Expand Down Expand Up @@ -86,6 +89,7 @@ pub fn run_node(mut cli: Cli) -> Result<()> {
None
}
};

runner.run_node_until_exit(|config| async move {
let sealing = cli.run.sealing.map(Into::into).unwrap_or_default();
let cache = cli.run.cache;
Expand Down
Loading