Skip to content

Commit

Permalink
merge master to feat/support-eth-address-in-xcm
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoka committed Dec 11, 2023
2 parents a4943bc + 31a793a commit cfd2f24
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 20 deletions.
3 changes: 2 additions & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ fc-mapping-sync = { git = "https://github.com/PureStake/frontier", branch = "moo
fc-rpc = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false }
fc-rpc-core = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false }

fp-consensus = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false }
fp-evm = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false }
fp-rpc = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false }
fp-self-contained = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ build-benchmarks:

.PHONY: test
test:
cargo test --locked

.PHONY: test-release
test-release:
cargo test --release --locked

.PHONY: test-benchmarks
Expand Down
3 changes: 2 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx"
version = "11.0.0"
version = "11.1.0"
description = "HydraDX node"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down Expand Up @@ -106,6 +106,7 @@ fc-rpc = { workspace = true }
fc-rpc-core = { workspace = true }
fp-rpc = { workspace = true }
fp-storage = { workspace = true }
fp-consensus = { workspace = true }

[features]
default = [
Expand Down
3 changes: 2 additions & 1 deletion node/res/hydradx.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"relay_chain": "polkadot",
"para_id": 2034,
"evm_since": 4006384,
"consensusEngine": null,
"codeSubstitutes": {},
"genesis": {
Expand Down Expand Up @@ -83,4 +84,4 @@
"childrenDefault": {}
}
}
}
}
121 changes: 121 additions & 0 deletions node/res/moonbase.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node/src/chain_spec/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub fn parachain_config() -> Result<ChainSpec, String> {
Extensions {
relay_chain: "rococo-local".into(),
para_id: PARA_ID,
evm_since: 1,
},
))
}
4 changes: 3 additions & 1 deletion node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

pub mod hydradx;
pub mod local;
pub mod moonbase;
pub mod rococo;
pub mod staging;

Expand Down Expand Up @@ -57,6 +58,7 @@ pub struct Extensions {
pub relay_chain: String,
/// The id of the Parachain.
pub para_id: u32,
pub evm_since: BlockNumber,
}

impl Extensions {
Expand Down Expand Up @@ -183,7 +185,7 @@ pub fn parachain_genesis(
omnipool_warehouse_lm: Default::default(),
omnipool_liquidity_mining: Default::default(),
evm_chain_id: hydradx_runtime::EVMChainIdConfig {
chain_id: 222_222u32.into(),
chain_id: 2_222_222u32.into(),
},
ethereum: Default::default(),
evm: Default::default(),
Expand Down
8 changes: 8 additions & 0 deletions node/src/chain_spec/moonbase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use super::*;

// The URL for the telemetry server.
const _TELEMETRY_URLS: [&str; 1] = ["wss://telemetry.hydradx.io:9000/submit/"];

pub fn parachain_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../../res/moonbase.json")[..])
}
1 change: 1 addition & 0 deletions node/src/chain_spec/rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub fn _parachain_config_rococo() -> Result<ChainSpec, String> {
Extensions {
relay_chain: "rococo".into(),
para_id: PARA_ID,
evm_since: 1,
},
))
}
1 change: 1 addition & 0 deletions node/src/chain_spec/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub fn parachain_config() -> Result<ChainSpec, String> {
Extensions {
relay_chain: "polkadot".into(),
para_id: PARA_ID,
evm_since: 1,
},
))
}
2 changes: 2 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, St
"local" | "dev" => Box::new(chain_spec::local::parachain_config()?),
"staging" => Box::new(chain_spec::staging::parachain_config()?),
"rococo" => Box::new(chain_spec::rococo::parachain_config()?),
"moonbase" => Box::new(chain_spec::moonbase::parachain_config()?),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
}
Expand Down Expand Up @@ -78,6 +79,7 @@ impl SubstrateCli for Cli {
"local" | "dev" => Box::new(chain_spec::local::parachain_config()?),
"staging" => Box::new(chain_spec::staging::parachain_config()?),
"rococo" => Box::new(chain_spec::rococo::parachain_config()?),
"moonbase" => Box::new(chain_spec::moonbase::parachain_config()?),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
}
Expand Down
7 changes: 5 additions & 2 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use std::{
use substrate_prometheus_endpoint::Registry;

pub(crate) mod evm;
use crate::rpc;
use crate::{chain_spec, rpc};

// native executor instance.
pub struct HydraDXExecutorDispatch;
Expand Down Expand Up @@ -99,12 +99,15 @@ where
+ EthereumRuntimeRPCApi<Block>,
{
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
let evm_since = chain_spec::Extensions::try_get(&config.chain_spec)
.map(|e| e.evm_since)
.unwrap_or(1);
let block_import = evm::BlockImport::new(
ParachainBlockImport::new(client.clone(), backend.clone()),
client.clone(),
frontier_backend,
evm_since,
);

cumulus_client_consensus_aura::import_queue::<sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _>(
cumulus_client_consensus_aura::ImportQueueParams {
block_import,
Expand Down
34 changes: 27 additions & 7 deletions node/src/service/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// you may not use this file except in compliance with the License.
// http://www.apache.org/licenses/LICENSE-2.0

use std::marker::PhantomData;
use std::{
collections::{BTreeMap, HashMap},
path::PathBuf,
Expand All @@ -31,11 +32,12 @@ use crate::service::{
FullClient,
};
use cumulus_client_consensus_common::ParachainBlockImportMarker;
use fc_consensus::FrontierBlockImport;
use fc_consensus::Error;
use fc_db::Backend as FrontierBackend;
use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};
use fc_rpc::{EthTask, OverrideHandle};
use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool};
use fp_consensus::ensure_log;
use fp_rpc::EthereumRuntimeRPCApi;
use fp_storage::EthereumStorageSchema;
use futures::{future, StreamExt};
Expand All @@ -50,7 +52,7 @@ use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::{well_known_cache_keys::Id as CacheKeyId, Error as BlockchainError, HeaderBackend, HeaderMetadata};
use sp_consensus::Error as ConsensusError;
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, Header as HeaderT};

/// The ethereum-compatibility configuration used to run a node.
/// evmTODO: revise settings, these are by Centrifuge
Expand Down Expand Up @@ -82,9 +84,17 @@ pub struct EthereumConfig {
}

pub type Hash = sp_core::H256;
type BlockNumberOf<B> = <<B as BlockT>::Header as HeaderT>::Number;

#[allow(dead_code)]
#[derive(Clone)]
pub struct BlockImport<B: BlockT, I: BlockImportT<B>, C>(FrontierBlockImport<B, I, C>);
pub struct BlockImport<B: BlockT, I: BlockImportT<B>, C> {
inner: I,
client: Arc<C>,
backend: Arc<fc_db::Backend<B>>,
evm_since: BlockNumberOf<B>,
_marker: PhantomData<B>,
}

impl<B, I, C> BlockImport<B, I, C>
where
Expand All @@ -95,15 +105,22 @@ where
C::Api: EthereumRuntimeRPCApi<B>,
C::Api: BlockBuilderApi<B>,
{
pub fn new(inner: I, client: Arc<C>, backend: Arc<fc_db::Backend<B>>) -> Self {
Self(FrontierBlockImport::new(inner, client, backend))
pub fn new(inner: I, client: Arc<C>, backend: Arc<fc_db::Backend<B>>, evm_since: BlockNumberOf<B>) -> Self {
Self {
inner,
client,
backend,
evm_since,
_marker: PhantomData,
}
}
}

#[async_trait::async_trait]
impl<B, I, C> BlockImportT<B> for BlockImport<B, I, C>
where
B: BlockT,
<B::Header as HeaderT>::Number: PartialOrd,
I: BlockImportT<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync,
I::Error: Into<ConsensusError>,
C: ProvideRuntimeApi<B> + Send + Sync + HeaderBackend<B> + AuxStore + BlockOf,
Expand All @@ -114,15 +131,18 @@ where
type Transaction = sp_api::TransactionFor<C, B>;

async fn check_block(&mut self, block: BlockCheckParams<B>) -> Result<ImportResult, Self::Error> {
self.0.check_block(block).await
self.inner.check_block(block).await.map_err(Into::into)
}

async fn import_block(
&mut self,
block: BlockImportParams<B, Self::Transaction>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, Self::Error> {
self.0.import_block(block, new_cache).await
if *block.header.number() >= self.evm_since {
ensure_log(block.header.digest()).map_err(Error::from)?;
}
self.inner.import_block(block, new_cache).await.map_err(Into::into)
}
}

Expand Down
3 changes: 3 additions & 0 deletions rococo-local/config-zombienet.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"nodes": [
{
"name": "alice",
"command": "../../polkadot/target/release/polkadot",
"args": ["--pruning=archive"],
"ws_port": 9944,
"invulnerable": true
},
Expand Down Expand Up @@ -39,6 +41,7 @@
{
"name": "alice",
"command": "../target/release/hydradx",
"args": ["--pruning=archive"],
"ws_port": 9988,
"rpc_port": 9999
},
Expand Down
8 changes: 1 addition & 7 deletions runtime/hydradx/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
#![allow(unused_imports)]
use crate::Vec;
use frame_support::{codec::alloc::vec, traits::OnRuntimeUpgrade, weights::Weight};

pub struct OnRuntimeUpgradeMigration;

use crate::Runtime;
use pallet_evm_chain_id::ChainId;

impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(vec![])
}

fn on_runtime_upgrade() -> Weight {
let evm_id: u64 = 222_222u64;
ChainId::<Runtime>::put(evm_id);
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 1)
Weight::zero()
}

#[cfg(feature = "try-runtime")]
Expand Down

0 comments on commit cfd2f24

Please sign in to comment.