Skip to content

Commit

Permalink
Merge pull request #1451 from subspace/evm/backport
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhavyas authored May 15, 2023
2 parents 2bf5d33 + 65685b6 commit 43777a7
Show file tree
Hide file tree
Showing 44 changed files with 758 additions and 261 deletions.
46 changes: 19 additions & 27 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/sp-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use sp_std::borrow::Cow;
use sp_std::vec::Vec;
use sp_trie::StorageProof;
use subspace_core_primitives::{Blake2b256Hash, BlockNumber, Randomness};
use subspace_runtime_primitives::Moment;

/// Key type for Executor.
const KEY_TYPE: KeyTypeId = KeyTypeId(*b"exec");
Expand Down Expand Up @@ -457,5 +458,8 @@ sp_api::decl_runtime_apis! {

// Returns the state root of the system domain at specific number and hash.
fn system_domain_state_root_at(number: NumberFor<Block>, domain_hash: DomainHash) -> Option<Block::Hash>;

// Returns the current timestamp at given height
fn timestamp() -> Moment;
}
}
1 change: 1 addition & 0 deletions crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ domain-client-executor = { version = "0.1.0", path = "../../domains/client/domai
domain-eth-service = { version = "0.1.0", path = "../../domains/client/eth-service" }
domain-service = { version = "0.1.0", path = "../../domains/service" }
domain-runtime-primitives = { version = "0.1.0", path = "../../domains/primitives/runtime" }
fp-evm = { version = "3.0.0-dev", git = "https://github.com/subspace/frontier/", rev = "e60f3f8617cabd3473bd5e197b7c0c1991fbcd9b" }
frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "fdb68194ab6995447610b3dbdee70559711dbd63", default-features = false }
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "fdb68194ab6995447610b3dbdee70559711dbd63", default-features = false }
frame-support = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "fdb68194ab6995447610b3dbdee70559711dbd63" }
Expand Down
108 changes: 56 additions & 52 deletions crates/subspace-node/src/core_domain/core_evm_chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
use crate::chain_spec_utils::chain_spec_properties;
use crate::AccountId32ToAccountId20Converter;
use core_evm_runtime::{
AccountId, BalancesConfig, EVMChainIdConfig, GenesisConfig, MessengerConfig, Signature,
SudoConfig, SystemConfig, WASM_BINARY,
AccountId, BalancesConfig, EVMChainIdConfig, EVMConfig, GenesisConfig, MessengerConfig,
Precompiles, SudoConfig, SystemConfig, WASM_BINARY,
};
use hex_literal::hex;
use sc_service::ChainType;
use sc_subspace_chain_specs::ExecutionChainSpec;
use sp_core::{ecdsa, sr25519, Pair, Public};
use sp_runtime::traits::{Convert, IdentifyAccount, Verify};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::Convert;
use std::str::FromStr;
use subspace_runtime_primitives::SSC;

Expand All @@ -36,19 +37,24 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
.public()
}

type AccountPublic = <Signature as Verify>::Signer;
pub type ChainSpec = ExecutionChainSpec<GenesisConfig>;

/// Generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
/// Development keys that will be injected automatically on polkadotjs apps
fn get_dev_accounts() -> Vec<AccountId> {
vec![
// Alith key
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
// Baltathar key
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
// Charleth key
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")),
// Dorothy
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")),
]
}

pub type ChainSpec = ExecutionChainSpec<GenesisConfig>;

pub fn development_config() -> ExecutionChainSpec<GenesisConfig> {
let accounts = get_dev_accounts();
ExecutionChainSpec::from_genesis(
// Name
"Development",
Expand All @@ -57,20 +63,16 @@ pub fn development_config() -> ExecutionChainSpec<GenesisConfig> {
ChainType::Development,
move || {
testnet_genesis(
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
],
Some(get_account_id_from_seed::<ecdsa::Public>("Alice")),
accounts.clone(),
// Alith is Sudo
Some(accounts[0]),
vec![(
get_account_id_from_seed::<ecdsa::Public>("Alice"),
accounts[0],
AccountId32ToAccountId20Converter::convert(
get_from_seed::<sr25519::Public>("Alice").into(),
),
)],
42,
1000,
)
},
vec![],
Expand All @@ -83,6 +85,7 @@ pub fn development_config() -> ExecutionChainSpec<GenesisConfig> {
}

pub fn local_testnet_config() -> ExecutionChainSpec<GenesisConfig> {
let accounts = get_dev_accounts();
ExecutionChainSpec::from_genesis(
// Name
"Local Testnet",
Expand All @@ -91,32 +94,11 @@ pub fn local_testnet_config() -> ExecutionChainSpec<GenesisConfig> {
ChainType::Local,
move || {
testnet_genesis(
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Charlie"),
get_account_id_from_seed::<ecdsa::Public>("Dave"),
get_account_id_from_seed::<ecdsa::Public>("Eve"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
get_account_id_from_seed::<ecdsa::Public>("Charlie//stash"),
get_account_id_from_seed::<ecdsa::Public>("Dave//stash"),
get_account_id_from_seed::<ecdsa::Public>("Eve//stash"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie//stash"),
],
Some(get_account_id_from_seed::<ecdsa::Public>("Alice")),
vec![
(
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Alice"),
),
(
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
),
],
43,
accounts.clone(),
// Alith is sudo
Some(accounts[0]),
vec![(accounts[0], accounts[0]), (accounts[1], accounts[1])],
1001,
)
},
// Bootnodes
Expand Down Expand Up @@ -153,7 +135,7 @@ pub fn gemini_3d_config() -> ExecutionChainSpec<GenesisConfig> {
],
Some(sudo_account),
Default::default(),
44,
1002,
)
},
// Bootnodes
Expand Down Expand Up @@ -194,7 +176,7 @@ pub fn devnet_config() -> ExecutionChainSpec<GenesisConfig> {
AccountId::from_str("5b267fd1ba3ace6e3c3234f9576c49c877b5beb9")
.expect("Wrong relayer account address"),
)],
45,
1003,
)
},
// Bootnodes
Expand Down Expand Up @@ -228,6 +210,12 @@ fn testnet_genesis(
relayers: Vec<(AccountId, AccountId)>,
chain_id: u64,
) -> GenesisConfig {
// This is the simplest bytecode to revert without returning any data.
// We will pre-deploy it under all of our precompiles to ensure they can be called from
// within contracts.
// (PUSH1 0x00 PUSH1 0x00 REVERT)
let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD];

GenesisConfig {
system: SystemConfig {
code: WASM_BINARY
Expand All @@ -247,9 +235,25 @@ fn testnet_genesis(
},
messenger: MessengerConfig { relayers },
evm_chain_id: EVMChainIdConfig { chain_id },
evm: Default::default(),
evm: EVMConfig {
// We need _some_ code inserted at the precompile address so that
// the evm will actually call the address.
accounts: Precompiles::used_addresses()
.into_iter()
.map(|addr| {
(
addr,
fp_evm::GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
code: revert_bytecode.clone(),
},
)
})
.collect(),
},
ethereum: Default::default(),
dynamic_fee: Default::default(),
base_fee: Default::default(),
}
}
6 changes: 5 additions & 1 deletion crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("subspace"),
impl_name: create_runtime_str!("subspace"),
authoring_version: 0,
spec_version: 1,
spec_version: 2,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 0,
Expand Down Expand Up @@ -804,6 +804,10 @@ impl_runtime_apis! {
) -> Option<domain_runtime_primitives::Hash>{
Receipts::domain_state_root_at(DomainId::SYSTEM, number, domain_hash)
}

fn timestamp() -> Moment{
Timestamp::now()
}
}

impl sp_session::SessionKeys<Block> for Runtime {
Expand Down
1 change: 1 addition & 0 deletions domains/client/block-preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sp-messenger = { version = "0.1.0", path = "../../primitives/messenger" }
sp-runtime = { version = "7.0.0", git = "https://github.com/subspace/substrate", rev = "fdb68194ab6995447610b3dbdee70559711dbd63" }
sp-state-machine = { version = "0.13.0", git = "https://github.com/subspace/substrate", rev = "fdb68194ab6995447610b3dbdee70559711dbd63" }
subspace-core-primitives = { version = "0.1.0", path = "../../../crates/subspace-core-primitives" }
subspace-runtime-primitives = { version = "0.1.0", path = "../../../crates/subspace-runtime-primitives" }
subspace-wasm-tools = { version = "0.1.0", path = "../../../crates/subspace-wasm-tools" }
system-runtime-primitives = { version = "0.1.0", path = "../../primitives/system-runtime" }
tracing = "0.1.37"
Expand Down
Loading

0 comments on commit 43777a7

Please sign in to comment.