Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Integrate Frontier (#334)
Browse files Browse the repository at this point in the history
* Squashed 'frontier/' content from commit 51bd10f

git-subtree-dir: frontier
git-subtree-split: 51bd10ff209f1f19cd33715d2d75e6768eca5352

* Add frontier to root workspace

* Impl ethereum and evm pallets for Runtime

* Replace all frontier parity deps to common-library

* Change ethereum pallet trait bond

* Change evm deps path,mark runtime compile success

* Impl EthereumRuntimeRPCApi for Runtime

* Implement node logic, mark node compile success

* Remove useless variables

* Add ConcatAddressMapping

* Add Precompile: TransferBack

* Add ConcatAddressMapping test

* Add frame_evm precompiles

* TransferBack precompile fix #329

* Format and del useless variable

* FIX frontier test

* Clear frontier-cloned files

* Move test case to test mod

* Change precompile name to Withdraw

* Move into frames

* Update crate info

* Delete useless deps

* Update dvm address mapping algo

* Fix failed test

* Delete unused import

* Simplified address mapping code

* [WIP] Put precompile into ethereum pallet

* Fix precompiles.rs

* Fix no std problem

* Update chores

* Add explaination docs about ConcatAddressMapping

* Handle conflict

* Move address mapping test out to ethereum

* Add signature verification to NativeTransfer precompile

* Update precompiles format

* Unit test about signature

* update: workspace

* remove: unused features & bump dependencies

* rename: to `pallet_evm`

* update: chain spec

* ignore: if test

* rename: to `dvm_ethereum`

* Handle conflicting file

* fix: typo

* optimize: rpc code

* optimize: service code

* remove: unnecessary denpendency

* optimize: runtime code

* update: toml

* bump: to 1.2.2

Co-authored-by: Aki <[email protected]>
Co-authored-by: Xavier Lau <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2020
1 parent 915faee commit dd77422
Show file tree
Hide file tree
Showing 76 changed files with 6,026 additions and 185 deletions.
525 changes: 411 additions & 114 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
[workspace]
members = [
# node
"bin/node-template/node",
"bin/node-template/runtime",
# client
"client/cli",
# frame
"frame/balances",
"frame/balances/rpc",
"frame/balances/rpc/runtime-api",
"frame/claims",
"frame/bridge/crab/backing",
"frame/bridge/crab/issuing",
"frame/bridge/ethereum/backing",
"frame/bridge/ethereum/linear-relay",
"frame/bridge/ethereum/relay",
"frame/bridge/relayer-game",
"frame/bridge/tron/backing",
"frame/claims",
"frame/democracy",
"frame/dvm/ethereum",
"frame/dvm/rpc",
"frame/dvm/rpc/core",
"frame/dvm/rpc/primitives",
"frame/dvm/consensus",
"frame/dvm/consensus/primitives",
"frame/elections-phragmen",
"frame/header-mmr",
"frame/header-mmr/rpc",
Expand All @@ -25,6 +34,7 @@ members = [
"frame/support",
"frame/treasury",
"frame/vesting",
# primitives
"primitives/array-bytes",
"primitives/ethereum-primitives",
"primitives/merkle-patricia-trie",
Expand Down
19 changes: 12 additions & 7 deletions bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Unlicense"
name = "node-template"
readme = "README.md"
repository = "https://github.com/darwinia-network/darwinia-common/"
version = "1.0.0"
version = "1.2.2"

[[bin]]
name = "node-template"
Expand All @@ -17,12 +17,13 @@ name = "node-template"
# anonymous
node-template-runtime = { path = "../runtime" }
# crates
codec = { package = "parity-scale-codec", version = "1.3.5" }
futures = { version = "0.3.6" }
jsonrpc-core = { version = "15.1.0" }
log = { version = "0.4.11" }
structopt = { version = "0.3.20" }
tokio = { version = "0.3.1", optional = true, features = ["rt-multi-thread"] }
codec = { package = "parity-scale-codec", version = "1.3.5" }
futures = { version = "0.3.7" }
jsonrpc-core = { version = "15.1.0" }
jsonrpc-pubsub = { version = "15.1.0" }
log = { version = "0.4.11" }
structopt = { version = "0.3.20" }
tokio = { version = "0.3.1", optional = true, features = ["rt-multi-thread"] }
# darwinia
array-bytes = { path = "../../../primitives/array-bytes" }
darwinia-balances-rpc = { path = "../../../frame/balances/rpc" }
Expand All @@ -35,8 +36,12 @@ darwinia-header-mmr-rpc-runtime-api = { path = "../../../frame/header-mmr/rpc/ru
darwinia-staking = { path = "../../../frame/staking" }
darwinia-staking-rpc = { path = "../../../frame/staking/rpc" }
darwinia-staking-rpc-runtime-api = { path = "../../../frame/staking/rpc/runtime-api" }
dvm-consensus = { path = "../../../frame/dvm/consensus" }
dvm-rpc = { path = "../../../frame/dvm/rpc" }
dvm-rpc-primitives = { path = "../../../frame/dvm/rpc/primitives" }
# substrate
frame-system-rpc-runtime-api = { git = "https://github.com/darwinia-network/substrate.git", branch = "common-library" }
pallet-evm = { git = "https://github.com/darwinia-network/substrate.git", branch = "common-library" }
pallet-im-online = { git = "https://github.com/darwinia-network/substrate.git", branch = "common-library" }
pallet-transaction-payment-rpc = { git = "https://github.com/darwinia-network/substrate.git", branch = "common-library" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/darwinia-network/substrate.git", branch = "common-library" }
Expand Down
22 changes: 21 additions & 1 deletion bin/node-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// --- std ---
use std::collections::BTreeMap;
// --- substrate ---
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_service::{ChainType, Properties};
Expand Down Expand Up @@ -159,6 +161,20 @@ fn testnet_genesis(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
) -> GenesisConfig {
let gerald_evm_account_id =
fixed_hex_bytes_unchecked!("0x6be02d1d3665660d22ff9624b7be0551ee1ac91b", 20).into();
let mut evm_accounts = BTreeMap::new();

evm_accounts.insert(
gerald_evm_account_id,
pallet_evm::GenesisAccount {
nonce: 0.into(),
balance: 123_456_123_000_000_000_000_000u128.into(),
storage: BTreeMap::new(),
code: vec![],
},
);

GenesisConfig {
frame_system: Some(SystemConfig {
code: wasm_binary_unwrap().to_vec(),
Expand Down Expand Up @@ -258,6 +274,10 @@ fn testnet_genesis(
darwinia_tron_backing: Some(TronBackingConfig {
backed_ring: 1 << 56,
backed_kton: 1 << 56,
})
}),
pallet_evm: Some(EVMConfig {
accounts: evm_accounts,
}),
dvm_ethereum: Some(Default::default()),
}
}
57 changes: 45 additions & 12 deletions bin/node-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};

// --- std ---
use std::sync::Arc;
// --- substrate ---
use sp_api::ProvideRuntimeApi;
// --- darwinia ---
use node_template_runtime::{
opaque::Block,
Expand Down Expand Up @@ -64,6 +62,10 @@ pub struct FullDeps<C, P, SC, B> {
pub select_chain: SC,
/// Whether to deny unsafe calls
pub deny_unsafe: sc_rpc::DenyUnsafe,
/// The Node authority flag
pub is_authority: bool,
/// Network service
pub network: Arc<sc_network::NetworkService<Block, Hash>>,
/// BABE specific dependencies.
pub babe: BabeDeps,
/// GRANDPA specific dependencies.
Expand All @@ -83,11 +85,19 @@ pub struct LightDeps<C, F, P> {
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension
pub fn create_full<C, P, SC, B>(
deps: FullDeps<C, P, SC, B>,
subscription_task_executor: sc_rpc::SubscriptionTaskExecutor,
) -> RpcExtension
where
C: 'static + Send + Sync,
C: ProvideRuntimeApi<Block>,
C: sp_blockchain::HeaderBackend<Block>
C: 'static
+ Send
+ Sync
+ sp_api::ProvideRuntimeApi<Block>
+ sc_client_api::AuxStore
+ sc_client_api::BlockchainEvents<Block>
+ sc_client_api::StorageProvider<Block, B>
+ sp_blockchain::HeaderBackend<Block>
+ sp_blockchain::HeaderMetadata<Block, Error = sp_blockchain::Error>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
Expand All @@ -96,11 +106,15 @@ where
C::Api: darwinia_balances_rpc::BalancesRuntimeApi<Block, AccountId, Balance>,
C::Api: darwinia_header_mmr_rpc::HeaderMMRRuntimeApi<Block, Hash>,
C::Api: darwinia_staking_rpc::StakingRuntimeApi<Block, AccountId, Power>,
P: 'static + sp_transaction_pool::TransactionPool,
C::Api: dvm_rpc_primitives::EthereumRuntimeRPCApi<Block>,
<C::Api as sp_api::ApiErrorExt>::Error: std::fmt::Debug,
P: 'static + Sync + Send + sp_transaction_pool::TransactionPool<Block = Block>,
SC: 'static + sp_consensus::SelectChain<Block>,
B: 'static + Send + Sync + sc_client_api::Backend<Block>,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
// --- crates ---
use jsonrpc_pubsub::manager::SubscriptionManager;
// --- substrate ---
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use sc_consensus_babe_rpc::{BabeApi, BabeRpcHandler};
Expand All @@ -110,20 +124,24 @@ where
use darwinia_balances_rpc::{Balances, BalancesApi};
use darwinia_header_mmr_rpc::{HeaderMMR, HeaderMMRApi};
use darwinia_staking_rpc::{Staking, StakingApi};
use dvm_rpc::{EthApi, EthApiServer, EthPubSubApi, EthPubSubApiServer, NetApi, NetApiServer};
use node_template_runtime::TransactionConverter;

let FullDeps {
client,
pool,
select_chain,
deny_unsafe,
is_authority,
network,
babe,
grandpa,
} = deps;
let mut io = jsonrpc_core::IoHandler::default();

io.extend_with(SystemApi::to_delegate(FullSystem::new(
client.clone(),
pool,
pool.clone(),
deny_unsafe,
)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(
Expand Down Expand Up @@ -164,17 +182,32 @@ where
}
io.extend_with(BalancesApi::to_delegate(Balances::new(client.clone())));
io.extend_with(HeaderMMRApi::to_delegate(HeaderMMR::new(client.clone())));
io.extend_with(StakingApi::to_delegate(Staking::new(client)));
io.extend_with(StakingApi::to_delegate(Staking::new(client.clone())));
io.extend_with(EthApiServer::to_delegate(EthApi::new(
client.clone(),
pool.clone(),
TransactionConverter,
is_authority,
)));
io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new(
pool.clone(),
client.clone(),
network.clone(),
SubscriptionManager::new(Arc::new(subscription_task_executor)),
)));
io.extend_with(NetApiServer::to_delegate(NetApi::new(client)));

io
}

/// Instantiate all RPC extensions for light node.
pub fn create_light<C, P, F>(deps: LightDeps<C, F, P>) -> RpcExtension
where
C: 'static + Send + Sync,
C: ProvideRuntimeApi<Block>,
C: sp_blockchain::HeaderBackend<Block>,
C: 'static
+ Send
+ Sync
+ sp_api::ProvideRuntimeApi<Block>
+ sp_blockchain::HeaderBackend<Block>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
P: 'static + sp_transaction_pool::TransactionPool,
Expand Down
50 changes: 42 additions & 8 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use sc_finality_grandpa::{
LinkHalf, SharedVoterState as GrandpaSharedVoterState,
VotingRulesBuilder as GrandpaVotingRulesBuilder,
};
use sc_network::NetworkService;
use sc_service::{
config::{KeystoreConfig, PrometheusConfig},
BuildNetworkParams, Configuration, Error as ServiceError, NoopRpcExtensionBuilder,
Expand All @@ -38,6 +39,8 @@ use crate::rpc::{
self, BabeDeps, DenyUnsafe, FullDeps, GrandpaDeps, LightDeps, RpcExtension,
SubscriptionTaskExecutor,
};
use dvm_consensus::FrontierBlockImport;

use node_template_runtime::{
opaque::Block,
primitives::{AccountId, Balance, Hash, Nonce, Power},
Expand Down Expand Up @@ -78,6 +81,7 @@ pub trait RuntimeApiCollection:
+ darwinia_balances_rpc_runtime_api::BalancesApi<Block, AccountId, Balance>
+ darwinia_header_mmr_rpc_runtime_api::HeaderMMRApi<Block, Hash>
+ darwinia_staking_rpc_runtime_api::StakingApi<Block, AccountId, Power>
+ dvm_rpc_primitives::EthereumRuntimeRPCApi<Block>
where
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
Expand All @@ -97,7 +101,8 @@ where
+ pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ darwinia_balances_rpc_runtime_api::BalancesApi<Block, AccountId, Balance>
+ darwinia_header_mmr_rpc_runtime_api::HeaderMMRApi<Block, Hash>
+ darwinia_staking_rpc_runtime_api::StakingApi<Block, AccountId, Power>,
+ darwinia_staking_rpc_runtime_api::StakingApi<Block, AccountId, Power>
+ dvm_rpc_primitives::EthereumRuntimeRPCApi<Block>,
<Self as sp_api::ApiExt<Block>>::StateBackend: sp_api::StateBackend<BlakeTwo256>,
{
}
Expand Down Expand Up @@ -152,12 +157,21 @@ fn new_partial<RuntimeApi, Executor>(
DefaultImportQueue<Block, FullClient<RuntimeApi, Executor>>,
FullPool<Block, FullClient<RuntimeApi, Executor>>,
(
impl Fn(DenyUnsafe, SubscriptionTaskExecutor) -> RpcExtension,
impl Fn(
DenyUnsafe,
bool,
Arc<NetworkService<Block, Hash>>,
SubscriptionTaskExecutor,
) -> RpcExtension,
(
BabeBlockImport<
Block,
FullClient<RuntimeApi, Executor>,
FullGrandpaBlockImport<RuntimeApi, Executor>,
FrontierBlockImport<
Block,
FullGrandpaBlockImport<RuntimeApi, Executor>,
FullClient<RuntimeApi, Executor>,
>,
>,
LinkHalf<Block, FullClient<RuntimeApi, Executor>, FullSelectChain>,
BabeLink<Block>,
Expand Down Expand Up @@ -199,9 +213,11 @@ where
grandpa_hard_forks,
)?;
let justification_import = grandpa_block_import.clone();
let frontier_block_import =
FrontierBlockImport::new(grandpa_block_import.clone(), client.clone(), true);
let (babe_import, babe_link) = sc_consensus_babe::block_import(
BabeConfig::get_or_compute(&*client)?,
grandpa_block_import,
frontier_block_import,
client.clone(),
)?;
let import_queue = sc_consensus_babe::import_queue(
Expand All @@ -225,18 +241,22 @@ where
let rpc_setup = (shared_voter_state.clone(), finality_proof_provider.clone());
let babe_config = babe_link.config().clone();
let shared_epoch_changes = babe_link.epoch_changes().clone();
let subscription_task_executor =
sc_rpc::SubscriptionTaskExecutor::new(task_manager.spawn_handle());
let rpc_extensions_builder = {
let client = client.clone();
let keystore = keystore.clone();
let transaction_pool = transaction_pool.clone();
let select_chain = select_chain.clone();

move |deny_unsafe, subscription_executor| -> RpcExtension {
move |deny_unsafe, is_authority, network, subscription_executor| -> RpcExtension {
let deps = FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
select_chain: select_chain.clone(),
deny_unsafe,
is_authority,
network,
babe: BabeDeps {
babe_config: babe_config.clone(),
shared_epoch_changes: shared_epoch_changes.clone(),
Expand All @@ -251,7 +271,7 @@ where
},
};

rpc::create_full(deps)
rpc::create_full(deps, subscription_task_executor.clone())
}
};

Expand Down Expand Up @@ -321,14 +341,28 @@ where
}

let telemetry_connection_sinks = TelemetryConnectionSinks::default();

sc_service::spawn_tasks(SpawnTasksParams {
config,
backend: backend.clone(),
client: client.clone(),
keystore: keystore.clone(),
network: network.clone(),
rpc_extensions_builder: Box::new(rpc_extensions_builder),
rpc_extensions_builder: {
let wrap_rpc_extensions_builder = {
let network = network.clone();

move |deny_unsafe, subscription_executor| -> RpcExtension {
rpc_extensions_builder(
deny_unsafe,
is_authority,
network.clone(),
subscription_executor,
)
}
};

Box::new(wrap_rpc_extensions_builder)
},
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
on_demand: None,
Expand Down
Loading

0 comments on commit dd77422

Please sign in to comment.