Skip to content

Commit

Permalink
Tanssi integration (#361)
Browse files Browse the repository at this point in the history
Integrated Tanssi runtimes and updated the abstraction macro invocation
  • Loading branch information
KitHat authored Nov 27, 2024
1 parent 50d854b commit f50de6b
Show file tree
Hide file tree
Showing 31 changed files with 3,156 additions and 1,206 deletions.
795 changes: 661 additions & 134 deletions evm-template/Cargo.lock

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions evm-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ serde_json = "1.0.121"
smallvec = "1.11.0"

# TODO: update to release
openzeppelin-polkadot-wrappers = { git = "https://github.com/openzeppelin/polkadot-runtime-wrappers", default-features = false, tag = "v0.1-rc1" }
openzeppelin-polkadot-wrappers-proc = { git = "https://github.com/openzeppelin/polkadot-runtime-wrappers", default-features = false, tag = "v0.1-rc1" }
openzeppelin-pallet-abstractions = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", default-features = false, tag = "v0.1-rc2" }
openzeppelin-pallet-abstractions-proc = { git = "https://github.com/OpenZeppelin/openzeppelin-pallet-abstractions", default-features = false, tag = "v0.1-rc2" }

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
Expand Down Expand Up @@ -67,6 +67,7 @@ sc-cli = { git = "https://github.com/paritytech/polkadot-sdk", default-features
sc-client-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
sc-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
sc-consensus-slots = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
sc-network = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
sc-network-sync = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
Expand Down Expand Up @@ -120,6 +121,7 @@ cumulus-client-collator = { git = "https://github.com/paritytech/polkadot-sdk",
cumulus-client-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-client-consensus-common = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-client-consensus-proposer = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-client-parachain-inherent = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-client-service = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
Expand All @@ -130,6 +132,7 @@ cumulus-primitives-aura = { git = "https://github.com/paritytech/polkadot-sdk",
cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-primitives-storage-weight-reclaim = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-primitives-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-relay-chain-interface = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, tag = "polkadot-stable2407-1" }
Expand Down Expand Up @@ -181,6 +184,15 @@ xcm-primitives = { git = "https://github.com/OpenZeppelin/moonbeam.git", branch
substrate-runtimes-fuzzers = { git = "https://github.com/srlabs/substrate-runtime-fuzzer.git", default-features = false, tag = "polkadot-v1.12.0" }
ziggy = { version = "0.8", default-features = false }

# Tanssi
ccp-authorities-noting-inherent = { git = "https://github.com/OpenZeppelin/dancekit", default-features = false, tag = "polkadot-stable2407-1" }
dp-consensus = { git = "https://github.com/OpenZeppelin/dancekit", default-features = false, tag = "polkadot-stable2407-1" }
nimbus-consensus = { git = "https://github.com/OpenZeppelin/moonkit", default-features = false, tag = "polkadot-stable2407-1" }
nimbus-primitives = { git = "https://github.com/OpenZeppelin/moonkit", default-features = false, tag = "polkadot-stable2407-1" }
pallet-author-inherent = { git = "https://github.com/OpenZeppelin/moonkit", default-features = false, tag = "polkadot-stable2407-1" }
pallet-cc-authorities-noting = { git = "https://github.com/OpenZeppelin/dancekit", default-features = false, tag = "polkadot-stable2407-1" }
tc-consensus = { git = "https://github.com/KitHat/tanssi", branch = "polkadot-stable2407-1", default-features = false }

[workspace.lints.clippy]
large_enum_variant = "allow"
too_many_arguments = "allow"
Expand Down
19 changes: 10 additions & 9 deletions evm-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ sc-cli = { workspace = true }
sc-client-api = { workspace = true }
sc-consensus = { workspace = true }
sc-consensus-aura = { workspace = true }
sc-consensus-slots = { workspace = true }
sc-executor = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
Expand Down Expand Up @@ -70,10 +71,12 @@ cumulus-client-collator = { workspace = true }
cumulus-client-consensus-aura = { workspace = true }
cumulus-client-consensus-common = { workspace = true }
cumulus-client-consensus-proposer = { workspace = true }
cumulus-client-parachain-inherent = { workspace = true }
cumulus-client-service = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }
cumulus-test-relay-sproof-builder = { workspace = true }

# Frontier
fc-api = { workspace = true }
Expand All @@ -87,21 +90,19 @@ fp-dynamic-fee = { workspace = true, features = [ "std" ] }
fp-evm = { workspace = true }
fp-rpc = { workspace = true }

# Tanssi
ccp-authorities-noting-inherent = { workspace = true }
nimbus-consensus = { workspace = true }
tc-consensus = { workspace = true }

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

[features]
default = []
async-backing = []
runtime-benchmarks = [
"evm-runtime-template/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
runtime-benchmarks = [ "evm-runtime-template/runtime-benchmarks", "frame-benchmarking-cli/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "polkadot-cli/runtime-benchmarks", "polkadot-primitives/runtime-benchmarks", "sc-service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "tc-consensus/runtime-benchmarks" ]
tanssi = []
try-runtime = [
"evm-runtime-template/try-runtime",
"polkadot-cli/try-runtime",
Expand Down
83 changes: 79 additions & 4 deletions evm-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use std::collections::BTreeMap;

use cumulus_primitives_core::ParaId;
use evm_runtime_template::{
AccountId, AuraId, OpenZeppelinPrecompiles as Precompiles, Runtime, Signature,
};
use evm_runtime_template::{AccountId, OpenZeppelinPrecompiles as Precompiles, Runtime};
#[cfg(not(feature = "tanssi"))]
use evm_runtime_template::{AuraId, Signature};
use fp_evm::GenesisAccount;
use hex_literal::hex;
use log::error;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{ecdsa, Pair, Public, H160};
use sp_core::H160;
#[cfg(not(feature = "tanssi"))]
use sp_core::{ecdsa, Pair, Public};
#[cfg(not(feature = "tanssi"))]
use sp_runtime::traits::{IdentifyAccount, Verify};

use crate::contracts::{parse_contracts, ContractsPath};
Expand All @@ -22,6 +25,7 @@ pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION;

/// Helper function to generate a crypto pair from seed
#[cfg(not(feature = "tanssi"))]
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
Expand All @@ -45,17 +49,20 @@ impl Extensions {
}
}

#[cfg(not(feature = "tanssi"))]
type AccountPublic = <Signature as Verify>::Signer;

/// Generate collator keys from seed.
///
/// This function's return type must always match the session keys of the chain
/// in tuple format.
#[cfg(not(feature = "tanssi"))]
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
get_from_seed::<AuraId>(seed)
}

/// Helper function to generate an account ID from seed
#[cfg(not(feature = "tanssi"))]
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
Expand All @@ -67,6 +74,7 @@ where
///
/// The input must be a tuple of individual keys (a single arg for now since we
/// have just one key).
#[cfg(not(feature = "tanssi"))]
pub fn template_session_keys(keys: AuraId) -> evm_runtime_template::SessionKeys {
evm_runtime_template::SessionKeys { aura: keys }
}
Expand Down Expand Up @@ -94,6 +102,7 @@ pub fn development_config(contracts_path: ContractsPath) -> ChainSpec {
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(testnet_genesis(
// initial collators.
#[cfg(not(feature = "tanssi"))]
vec![
(
get_account_id_from_seed::<ecdsa::Public>("Alice"),
Expand Down Expand Up @@ -140,6 +149,7 @@ pub fn local_testnet_config(contracts_path: ContractsPath) -> ChainSpec {
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(testnet_genesis(
// initial collators.
#[cfg(not(feature = "tanssi"))]
vec![
(
get_account_id_from_seed::<ecdsa::Public>("Alice"),
Expand All @@ -165,6 +175,7 @@ pub fn local_testnet_config(contracts_path: ContractsPath) -> ChainSpec {
.build()
}

#[cfg(not(feature = "tanssi"))]
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
#[cfg(not(feature = "runtime-benchmarks"))] endowed_accounts: Vec<AccountId>,
Expand Down Expand Up @@ -245,3 +256,67 @@ fn testnet_genesis(
"sudo": { "key": Some(root) }
})
}

#[cfg(feature = "tanssi")]
fn testnet_genesis(
#[cfg(not(feature = "runtime-benchmarks"))] endowed_accounts: Vec<AccountId>,
#[cfg(feature = "runtime-benchmarks")] mut endowed_accounts: Vec<AccountId>,
root: AccountId,
id: ParaId,
contracts_path: ContractsPath,
) -> serde_json::Value {
let contracts = parse_contracts(contracts_path)
.map_err(|e| error!("Error while parsing contracts: {e:?}"))
.unwrap_or_default();
let precompiles = Precompiles::<Runtime>::used_addresses()
.map(|addr| {
(
addr,
GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
// bytecode to revert without returning data
// (PUSH1 0x00 PUSH1 0x00 REVERT)
code: vec![0x60, 0x00, 0x60, 0x00, 0xFD],
},
)
})
.into_iter();
let accounts: BTreeMap<H160, GenesisAccount> = contracts
.into_iter()
.map(|(address, contract)| {
(
address,
GenesisAccount {
code: contract.bytecode(),
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
},
)
})
.chain(precompiles)
.collect();
#[cfg(feature = "runtime-benchmarks")]
endowed_accounts.push(AccountId::from(hex!("1000000000000000000000000000000000000001")));
serde_json::json!({
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
},
"parachainInfo": {
"parachainId": id,
},
"treasury": {},
"evmChainId": {
"chainId": 9999
},
"evm": {
"accounts": accounts
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"sudo": { "key": Some(root) }
})
}
2 changes: 2 additions & 0 deletions evm-template/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mod cli;
mod command;
mod contracts;
mod eth;

#[cfg_attr(feature = "tanssi", path = "tanssi_rpc/mod.rs")]
mod rpc;

fn main() -> sc_cli::Result<()> {
Expand Down
Loading

0 comments on commit f50de6b

Please sign in to comment.