Skip to content

Commit

Permalink
Add EVM to unorthodox collator setup. (#115)
Browse files Browse the repository at this point in the history
* Add EVM to unorthodox collator setup.

* Fix Ethereum block import on new sync.

* Make tests run daily.

* Cargo fmt run.

* Update runtime versions on opportunity/standard.
  • Loading branch information
firke authored Dec 28, 2021
1 parent 8338177 commit 720e234
Show file tree
Hide file tree
Showing 20 changed files with 741 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fmt-checks-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
- "primitives/**"
- "runtime/**"
schedule:
- cron: "0 10 * * FRI"
- cron: "0 10 * * *"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/opportunity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ description = 'Opportunity Node Client.'

[[bin]]
name = 'opportunity-standalone'
path = "src/main.rs"

[package.metadata.docs.rs]
targets = [ 'x86_64-unknown-linux-gnu' ]
Expand Down
3 changes: 0 additions & 3 deletions node/opportunity/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//! Substrate Node Template CLI library.
#![warn(missing_docs)]

mod chain_spec;
#[macro_use]
mod service;
Expand Down
8 changes: 4 additions & 4 deletions node/opportunity/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub struct FullDeps<C, P, SC, B, T, A: ChainApi> {
/// EthFilterApi pool.
pub filter_pool: FilterPool,
/// Backend.
pub backend: Arc<fc_db::Backend<Block>>,
pub frontier_backend: Arc<fc_db::Backend<Block>>,
/// The Node authority flag
pub is_authority: bool,
/// Network service
Expand Down Expand Up @@ -167,7 +167,7 @@ where
grandpa,
network,
filter_pool,
backend,
frontier_backend,
transaction_converter,
is_authority,
} = deps;
Expand Down Expand Up @@ -237,15 +237,15 @@ where
network.clone(),
Default::default(),
overrides.clone(),
backend.clone(),
frontier_backend.clone(),
is_authority,
max_past_logs,
block_data_cache.clone(),
)));

io.extend_with(EthFilterApiServer::to_delegate(EthFilterApi::new(
client.clone(),
backend,
frontier_backend,
filter_pool,
max_stored_filters,
overrides.clone(),
Expand Down
35 changes: 13 additions & 22 deletions node/opportunity/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ pub fn new_partial(
sc_rpc::SubscriptionTaskExecutor,
) -> RpcResult,
(
sc_consensus_babe::BabeBlockImport<
Block,
FullClient,
FrontierBlockImport<Block, FullGrandpaBlockImport, FullClient>,
>,
sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
sc_consensus_babe::BabeLink<Block>,
),
Expand Down Expand Up @@ -137,8 +133,6 @@ pub fn new_partial(
client.clone(),
);

let frontier_backend = open_frontier_backend(config)?;

let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import(
client.clone(),
&(client.clone() as Arc<_>),
Expand All @@ -148,6 +142,8 @@ pub fn new_partial(

let justification_import = grandpa_block_import.clone();

let frontier_backend = open_frontier_backend(config)?;

let frontier_block_import = FrontierBlockImport::new(
grandpa_block_import.clone(),
client.clone(),
Expand All @@ -156,16 +152,10 @@ pub fn new_partial(

let (babe_import, babe_link) = sc_consensus_babe::block_import(
sc_consensus_babe::Config::get_or_compute(&*client)?,
frontier_block_import,
grandpa_block_import,
client.clone(),
)?;

// let (babe_import, babe_link) = sc_consensus_babe::block_import(
// sc_consensus_babe::Config::get_or_compute(&*client)?,
// grandpa_block_import,
// client.clone(),
// )?;

let slot_duration = babe_link.config().slot_duration();

let import_queue = sc_consensus_babe::import_queue(
Expand Down Expand Up @@ -215,8 +205,6 @@ pub fn new_partial(
let chain_spec = config.chain_spec.cloned_box();
let backend = frontier_backend.clone();
let filter_pool: FilterPool = Arc::new(std::sync::Mutex::new(BTreeMap::new()));
// let filter_pool = filter_pool.clone();
// let pending_transactions = pending_transactions.clone();
move |deny_unsafe, is_authority, network, subscription_executor| -> RpcResult {
let deps = FullDeps {
client: client.clone(),
Expand All @@ -227,7 +215,7 @@ pub fn new_partial(
deny_unsafe,
transaction_converter: opportunity_runtime::TransactionConverter,
filter_pool: filter_pool.clone(),
backend: backend.clone(),
frontier_backend: backend.clone(),
is_authority,
network,
babe: BabeDeps {
Expand Down Expand Up @@ -264,11 +252,7 @@ pub fn new_partial(
pub fn new_full_base(
mut config: Configuration,
with_startup_data: impl FnOnce(
&sc_consensus_babe::BabeBlockImport<
Block,
FullClient,
FrontierBlockImport<Block, FullGrandpaBlockImport, FullClient>,
>,
&sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
&sc_consensus_babe::BabeLink<Block>,
),
) -> Result<
Expand Down Expand Up @@ -334,6 +318,8 @@ pub fn new_full_base(
let prometheus_registry = config.prometheus_registry().cloned();
let chain_spec = config.chain_spec.cloned_box();

// Frontier offchain DB task. Essential.
// Maps emulated ethereum data to substrate native data.
task_manager.spawn_essential_handle().spawn(
"frontier-mapping-sync-worker",
MappingSyncWorker::new(
Expand All @@ -357,6 +343,11 @@ pub fn new_full_base(
EthTask::filter_pool_task(client.clone(), filter_pool.clone(), FILTER_RETAIN_THRESHOLD),
);

task_manager.spawn_essential_handle().spawn(
"frontier-schema-cache-task",
EthTask::ethereum_schema_cache_task(client.clone(), frontier_backend.clone()),
);

let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
config,
backend: backend.clone(),
Expand Down
18 changes: 14 additions & 4 deletions node/standard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ path = "src/main.rs"
[package.metadata.docs.rs]
targets = [ 'x86_64-unknown-linux-gnu' ]

[lib]
crate-type = [ "cdylib", "rlib" ]

[build-dependencies]
substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.12" }

Expand All @@ -39,9 +36,11 @@ hex-literal = "0.3.3"
hex = "0.4.3"
lazy_static = "1.4"
log = "0.4.14"
futures = { version = "0.3.4", features = ["compat"] }

# RPC related Dependencies
jsonrpc-core = "18.0.0"
jsonrpc-pubsub = "18.0.0"

# Local Dependencies
standard-runtime = { path = "../../runtime/standard" }
Expand Down Expand Up @@ -105,4 +104,15 @@ cumulus-primitives-parachain-inherent = { git = 'https://github.com/paritytech/c
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }

# Frontier Dependencies
pallet-dynamic-fee = { version = "4.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
pallet-ethereum = { version = "4.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
pallet-evm = { version = "6.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
fc-db = { version = "2.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
fc-rpc = { version = "2.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
fc-rpc-core = { version = "1.1.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
fc-mapping-sync = { version = "2.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
fc-consensus = { version = "2.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
fp-rpc = { version = "3.0.0-dev", default-features = false, git = "https://github.com/digitalnativeinc/frontier", branch = "feature/opportunity-integration" }
40 changes: 32 additions & 8 deletions node/standard/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use standard_runtime::{
AccountId, AssetRegistryConfig, AuraConfig, AuraId, BalancesConfig, CollatorSelectionConfig,
GenesisConfig, ImOnlineConfig, ImOnlineId, OracleConfig, ParachainInfoConfig, SessionConfig,
SessionKeys, Signature, StakerStatus, StakingConfig, SudoConfig, SystemConfig, VestingConfig,
EXISTENTIAL_DEPOSIT, WASM_BINARY,
};

use sp_runtime::{
traits::{IdentifyAccount, Verify},
Perbill,
};
use standard_runtime::{
AssetRegistryConfig, AuraConfig, AuraId, BalancesConfig, CollatorSelectionConfig, EVMConfig,
EthereumConfig, GenesisConfig, ImOnlineConfig, ImOnlineId, OracleConfig, ParachainInfoConfig,
Precompiles, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
VestingConfig, EXISTENTIAL_DEPOSIT, WASM_BINARY,
};

use primitives::AssetId;
use primitives::{AccountId, AssetId, Signature};

pub const CORE_ASSET_ID: AssetId = 1;

Expand Down Expand Up @@ -251,6 +250,11 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
// This is supposed the be 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.expect("WASM binary was not build, please build it!").to_vec(),
Expand Down Expand Up @@ -310,5 +314,25 @@ fn testnet_genesis(
oracles: [get_account_id_from_seed::<sr25519::Public>("Alice")].to_vec(),
provider_count: 5,
},
evm: EVMConfig {
// We need _some_ code inserted at the precompile address so that
// the evm will actually call the address.
accounts: Precompiles::used_addresses()
.iter()
.map(|addr| {
(
addr.clone(),
pallet_evm::GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
code: revert_bytecode.clone(),
},
)
})
.collect(),
},
ethereum: EthereumConfig {},
dynamic_fee: Default::default(),
}
}
2 changes: 1 addition & 1 deletion node/standard/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ macro_rules! construct_async_run {
_
>(
&$config,
crate::service::parachain_build_import_queue,
crate::service::build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
Expand Down
3 changes: 0 additions & 3 deletions node/standard/src/lib.rs

This file was deleted.

Loading

0 comments on commit 720e234

Please sign in to comment.