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

Commit

Permalink
Update dvm from 399 (#703)
Browse files Browse the repository at this point in the history
* companion for 399, precompile output refactor

* companion for 397, remove TargetMinGasPrice event

* companion for 404, Remove frontier offchain db on purge-chain subcommand

* companion for 406, Use skip_initialize_block for call and create

* companion for 415, Fix remaining release issues

* companion for 409, Add pallet_evm::Config::BlockHashMapping

* companion for 411, Update stack runner block_coinbase

* companion for 412, Use TransactionPool notification stream in pusbub

* companion for 419, Prioritize by gas price

* companion for 410, Update stack runner block_gas_limit

* summary: Have finished all update prs until now, still have some tasks to be done

* update: use dvm_backend instead of frontier_backend

* refactor: make BlockHashMapping clean

* fix broken evm unit test

* update: use `EthereumBlockHashMapping`, the same with upstream

* format: code clean

* fix: fix confilct with merge

* fix: fix broken test in s2s bridge issuing

* update format

Co-authored-by: Xavier Lau <[email protected]>
  • Loading branch information
bear and Xavier Lau authored Jul 19, 2021
1 parent 604080a commit 2619efc
Show file tree
Hide file tree
Showing 44 changed files with 525 additions and 279 deletions.
186 changes: 149 additions & 37 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,16 @@ pub fn run() -> sc_cli::Result<()> {
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd)?;

runner.sync_run(|config| cmd.run(config.database))
runner.sync_run(|config| {
// Remove dvm offchain db
let dvm_database_config = sc_service::DatabaseConfig::RocksDb {
path: service::dvm_database_dir(&config),
cache_size: 0,
};
cmd.run(dvm_database_config)?;

cmd.run(config.database)
})
}
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?;
Expand Down
22 changes: 13 additions & 9 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use pangolin_runtime;
// --- std ---
use std::{
collections::{BTreeMap, HashMap},
path::PathBuf,
sync::{Arc, Mutex},
time::Duration,
};
Expand Down Expand Up @@ -176,7 +177,7 @@ fn set_prometheus_registry(config: &mut Configuration) -> Result<(), ServiceErro
Ok(())
}

fn open_frontier_backend(config: &Configuration) -> Result<Arc<Backend<Block>>, String> {
pub fn dvm_database_dir(config: &Configuration) -> PathBuf {
let config_dir = config
.base_path
.as_ref()
Expand All @@ -185,11 +186,14 @@ fn open_frontier_backend(config: &Configuration) -> Result<Arc<Backend<Block>>,
BasePath::from_project("", "", &crate::cli::Cli::executable_name())
.config_dir(config.chain_spec.id())
});
let database_dir = config_dir.join("dvm").join("db");

config_dir.join("dvm").join("db")
}

pub fn open_dvm_backend(config: &Configuration) -> Result<Arc<Backend<Block>>, String> {
Ok(Arc::new(Backend::<Block>::new(&DatabaseSettings {
source: DatabaseSettingsSrc::RocksDb {
path: database_dir,
path: dvm_database_dir(&config),
cache_size: 0,
},
})?))
Expand Down Expand Up @@ -274,7 +278,7 @@ where
task_manager.spawn_handle(),
client.clone(),
);
let frontier_backend = open_frontier_backend(config)?;
let dvm_backend = open_dvm_backend(config)?;
let grandpa_hard_forks = vec![];
let (grandpa_block_import, grandpa_link) =
sc_finality_grandpa::block_import_with_authority_set_hard_forks(
Expand Down Expand Up @@ -340,7 +344,7 @@ where
let select_chain = select_chain.clone();
let chain_spec = config.chain_spec.cloned_box();
let pending_transactions = pending_transactions.clone();
let frontier_backend = frontier_backend.clone();
let dvm_backend = dvm_backend.clone();
let filter_pool = filter_pool.clone();
let max_past_logs = cli.run.max_past_logs;

Expand All @@ -366,7 +370,7 @@ where
finality_provider: finality_proof_provider.clone(),
},
pending_transactions: pending_transactions.clone(),
backend: frontier_backend.clone(),
backend: dvm_backend.clone(),
filter_pool: filter_pool.clone(),
max_past_logs,
};
Expand All @@ -389,7 +393,7 @@ where
rpc_setup,
telemetry,
pending_transactions,
frontier_backend,
dvm_backend,
filter_pool,
),
})
Expand Down Expand Up @@ -444,7 +448,7 @@ where
rpc_setup,
mut telemetry,
pending_transactions,
frontier_backend,
dvm_backend,
filter_pool,
),
} = new_partial::<RuntimeApi, Executor>(&mut config, cli)?;
Expand Down Expand Up @@ -673,7 +677,7 @@ where
Duration::new(6, 0),
client.clone(),
backend.clone(),
frontier_backend.clone(),
dvm_backend.clone(),
)
.for_each(|()| futures::future::ready(())),
);
Expand Down
2 changes: 1 addition & 1 deletion bin/node/runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version = "2.5.0"
# crates.io
array-bytes = { version = "1.3.3" }
codec = { package = "parity-scale-codec", version = "2.1.1", default-features = false }
evm = { version = "0.25.0", default-features = false, features = ["with-codec"] }
evm = { version = "0.27.0", default-features = false, features = ["with-codec"] }
log = { version = "0.4.14" }
serde = { version = "1.0.126", optional = true }
smallvec = { version = "1.6.1" }
Expand Down
12 changes: 11 additions & 1 deletion bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ use darwinia_evm::{Account as EVMAccount, Runner};
use darwinia_header_mmr_rpc_runtime_api::RuntimeDispatchInfo as HeaderMMRRuntimeDispatchInfo;
use darwinia_staking_rpc_runtime_api::RuntimeDispatchInfo as StakingRuntimeDispatchInfo;
use drml_primitives::*;
use dvm_ethereum::{Call::transact, Transaction as EthereumTransaction};
use dvm_rpc_runtime_api::TransactionStatus;
use impls::*;
use pangolin_bridge_primitives::PANGOLIN_CHAIN_ID;
Expand Down Expand Up @@ -682,7 +683,7 @@ impl_runtime_apis! {
}

fn author() -> H160 {
<dvm_ethereum::Pallet<Runtime>>::find_author()
<darwinia_evm::Pallet<Runtime>>::find_author()
}

fn storage_at(address: H160, index: U256) -> H256 {
Expand Down Expand Up @@ -773,6 +774,15 @@ impl_runtime_apis! {
Ethereum::current_transaction_statuses()
)
}

fn extrinsic_filter(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> Vec<EthereumTransaction> {
xts.into_iter().filter_map(|xt| match xt.function {
Call::Ethereum(transact(t)) => Some(t),
_ => None
}).collect::<Vec<EthereumTransaction>>()
}
}

impl millau_primitives::MillauFinalityApi<Block> for Runtime {
Expand Down
18 changes: 0 additions & 18 deletions bin/node/runtime/pangolin/src/pallets/dvm.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
// --- substrate ---
use frame_support::{traits::FindAuthor, ConsensusEngineId};
use sp_core::{crypto::Public, H160};
// --- darwinia ---
use crate::*;
use dvm_ethereum::{Config, IntermediateStateRoot};

pub struct EthereumFindAuthor<F>(sp_std::marker::PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
if let Some(author_index) = F::find_author(digests) {
let authority_id = Babe::authorities()[author_index as usize].clone();
return Some(H160::from_slice(&authority_id.0.to_raw_vec()[4..24]));
}
None
}
}

impl Config for Runtime {
type Event = Event;
type FindAuthor = EthereumFindAuthor<Babe>;
type StateRoot = IntermediateStateRoot;
type RingCurrency = Ring;
type KtonCurrency = Kton;
Expand Down
35 changes: 29 additions & 6 deletions bin/node/runtime/pangolin/src/pallets/evm_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,40 @@ pub use darwinia_evm_precompile_simple::{ECRecover, Identity, Ripemd160, Sha256}
pub use darwinia_evm_precompile_transfer::Transfer;

// --- crates.io ---
use evm::{Context, ExitError, ExitSucceed};
use evm::{executor::PrecompileOutput, Context, ExitError};
// --- substrate ---
use codec::{Decode, Encode};
use frame_support::dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo};
use sp_core::{H160, U256};
use sp_std::{marker::PhantomData, vec::Vec};
use frame_support::{
dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},
traits::FindAuthor,
ConsensusEngineId,
};
use sp_core::{crypto::Public, H160, U256};
use sp_std::marker::PhantomData;
// --- darwinia ---
use crate::*;
use darwinia_evm::{
runner::stack::Runner, ConcatAddressMapping, Config, EnsureAddressTruncated, GasWeightMapping,
};
use dp_evm::{Precompile, PrecompileSet};
use dvm_ethereum::account_basic::{DvmAccountBasic, KtonRemainBalance, RingRemainBalance};
use dvm_ethereum::{
account_basic::{DvmAccountBasic, KtonRemainBalance, RingRemainBalance},
EthereumBlockHashMapping,
};

pub struct EthereumFindAuthor<F>(sp_std::marker::PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
if let Some(author_index) = F::find_author(digests) {
let authority_id = Babe::authorities()[author_index as usize].clone();
return Some(H160::from_slice(&authority_id.0.to_raw_vec()[4..24]));
}
None
}
}

pub struct PangolinPrecompiles<R>(PhantomData<R>);
impl<R> PrecompileSet for PangolinPrecompiles<R>
Expand All @@ -32,7 +53,7 @@ where
input: &[u8],
target_gas: Option<u64>,
context: &Context,
) -> Option<Result<(ExitSucceed, Vec<u8>, u64), ExitError>> {
) -> Option<Result<PrecompileOutput, ExitError>> {
let addr = |n: u64| -> H160 { H160::from_low_u64_be(n) };

match address {
Expand Down Expand Up @@ -71,6 +92,8 @@ impl Config for Runtime {
type GasWeightMapping = DarwiniaGasWeightMapping;
type CallOrigin = EnsureAddressTruncated<Self::AccountId>;
type AddressMapping = ConcatAddressMapping<Self::AccountId>;
type FindAuthor = EthereumFindAuthor<Babe>;
type BlockHashMapping = EthereumBlockHashMapping<Self>;
type RingCurrency = Ring;
type KtonCurrency = Kton;
type Event = Event;
Expand Down
2 changes: 1 addition & 1 deletion bin/node/runtime/pangolin/src/pallets/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sp_version::RuntimeVersion;
use crate::*;

frame_support::parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
pub const BlockHashCount: BlockNumber = 256;
pub const Version: RuntimeVersion = VERSION;
pub const SS58Prefix: u8 = 18;
}
Expand Down
2 changes: 1 addition & 1 deletion client/dvm/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ array-bytes = { version = "1.3.3" }
codec = { package = "parity-scale-codec", version = "2.1.1" }
ethereum = { version = "0.7.1", features = ["with-codec"] }
ethereum-types = { version = "0.11.0" }
evm = { version = "0.25.0" }
evm = { version = "0.27.0" }
futures = { version = "0.3.13", features = ["compat"] }
jsonrpc-core = { version = "15.1.0" }
jsonrpc-core-client = { version = "15.1.0" }
Expand Down
Loading

0 comments on commit 2619efc

Please sign in to comment.