Skip to content

Commit

Permalink
Runtime 1103 (#1216)
Browse files Browse the repository at this point in the history
* Implement `ConvertTransactionRuntimeApi`

* Update frontier pin

* Help type checker

* remove TransactionConverter

* editorconfig

* Bump spec version to 1103

Co-authored-by: tgmichel <telmo@purestake.com>
  • Loading branch information
librelois and tgmichel authored Jan 24, 2022
1 parent e6d5f1b commit 6ce3f54
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 227 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

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

25 changes: 11 additions & 14 deletions node/perf-test/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use cumulus_primitives_parachain_inherent::{
MockValidationDataInherentDataProvider, MockXcmConfig,
};
use ethereum::TransactionAction;
use fp_rpc::{ConvertTransaction, EthereumRuntimeRPCApi};
use fp_rpc::EthereumRuntimeRPCApi;
use nimbus_primitives::NimbusId;
use sc_cli::{CliConfiguration, Result as CliResult, SharedParams};
use sc_client_api::HeaderBackend;
Expand All @@ -44,9 +44,7 @@ use futures::{

use cli_table::{print_stdout, WithTitle};
use serde::Serialize;
use service::{
chain_spec, rpc, Block, RuntimeApiCollection, RuntimeVariant, TransactionConverters,
};
use service::{chain_spec, rpc, Block, RuntimeApiCollection};
use sha3::{Digest, Keccak256};

pub type FullClient<RuntimeApi, Executor> =
Expand All @@ -65,7 +63,6 @@ where
client: Arc<FullClient<RuntimeApi, Executor>>,
manual_seal_command_sink: mpsc::Sender<EngineCommand<H256>>,
pool: Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, Executor>>>,
transaction_converter: TransactionConverters, // TODO: could be generic

_marker1: PhantomData<RuntimeApi>,
_marker2: PhantomData<Executor>,
Expand Down Expand Up @@ -193,18 +190,15 @@ where
});

let command_sink_for_deps = command_sink.clone();
let runtime_variant = RuntimeVariant::from_chain_spec(&config.chain_spec);

let rpc_extensions_builder = {
let client = client.clone();
let pool = transaction_pool.clone();
let backend = backend.clone();
let network = network.clone();
let max_past_logs = 1000;
let runtime_variant = runtime_variant.clone();

Box::new(move |deny_unsafe, _| {
let runtime_variant = runtime_variant.clone();
let deps = rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
Expand All @@ -219,9 +213,6 @@ where
frontier_backend: frontier_backend.clone(),
backend: backend.clone(),
max_past_logs,
transaction_converter: TransactionConverters::for_runtime_variant(
runtime_variant,
),
xcm_senders: None,
};
#[allow(unused_mut)]
Expand Down Expand Up @@ -252,7 +243,6 @@ where
client: client.clone(),
manual_seal_command_sink: command_sink.unwrap(),
pool: transaction_pool,
transaction_converter: TransactionConverters::for_runtime_variant(runtime_variant),
_marker1: Default::default(),
_marker2: Default::default(),
})
Expand Down Expand Up @@ -369,10 +359,17 @@ where
let transaction_hash =
H256::from_slice(Keccak256::digest(&rlp::encode(&signed)).as_slice());

let unchecked_extrinsic = self.transaction_converter.convert_transaction(signed);

let hash = self.client.info().best_hash;
log::debug!("eth_sign_and_send_transaction best_hash: {:?}", hash);
let id = BlockId::hash(hash);

use fp_rpc::ConvertTransactionRuntimeApi;
let unchecked_extrinsic = match self.client.runtime_api().convert_transaction(&id, signed) {
Ok(xt) => xt,
_ => return Err("cannot access runtime api".into()),
};
//let unchecked_extrinsic = self.transaction_converter.convert_transaction(signed);

let future = self.pool.submit_one(
&BlockId::hash(hash),
TransactionSource::Local,
Expand Down
2 changes: 2 additions & 0 deletions node/service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub trait RuntimeApiCollection:
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_session::SessionKeys<Block>
+ fp_rpc::EthereumRuntimeRPCApi<Block>
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
+ moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi<Block>
+ nimbus_primitives::NimbusApi<Block>
Expand All @@ -61,6 +62,7 @@ where
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_session::SessionKeys<Block>
+ fp_rpc::EthereumRuntimeRPCApi<Block>
+ fp_rpc::ConvertTransactionRuntimeApi<Block>
+ moonbeam_rpc_primitives_debug::DebugRuntimeApi<Block>
+ moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi<Block>
+ nimbus_primitives::NimbusApi<Block>
Expand Down
96 changes: 0 additions & 96 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,78 +395,6 @@ where
})
}

/// `fp_rpc::ConvertTransaction` is implemented for an arbitrary struct that lives in each runtime.
/// It receives a ethereum::Transaction and returns a pallet-ethereum transact Call wrapped in an
/// UncheckedExtrinsic.
///
/// Although the implementation should be the same in each runtime, this might change at some point.
/// `TransactionConverters` is just a `fp_rpc::ConvertTransaction` implementor that proxies calls to
/// each runtime implementation.
pub enum TransactionConverters {
#[cfg(feature = "moonbeam-native")]
Moonbeam(moonbeam_runtime::TransactionConverter),
#[cfg(feature = "moonbase-native")]
Moonbase(moonbase_runtime::TransactionConverter),
#[cfg(feature = "moonriver-native")]
Moonriver(moonriver_runtime::TransactionConverter),
}

impl TransactionConverters {
#[cfg(feature = "moonbeam-native")]
fn moonbeam() -> Self {
TransactionConverters::Moonbeam(moonbeam_runtime::TransactionConverter)
}
#[cfg(not(feature = "moonbeam-native"))]
fn moonbeam() -> Self {
unimplemented!()
}
#[cfg(feature = "moonriver-native")]
fn moonriver() -> Self {
TransactionConverters::Moonriver(moonriver_runtime::TransactionConverter)
}
#[cfg(not(feature = "moonriver-native"))]
fn moonriver() -> Self {
unimplemented!()
}
#[cfg(feature = "moonbase-native")]
fn moonbase() -> Self {
TransactionConverters::Moonbase(moonbase_runtime::TransactionConverter)
}
#[cfg(not(feature = "moonbase-native"))]
fn moonbase() -> Self {
unimplemented!()
}
pub fn for_runtime_variant(runtime: RuntimeVariant) -> Self {
match runtime {
#[cfg(feature = "moonbeam-native")]
RuntimeVariant::Moonbeam => Self::moonbeam(),
#[cfg(feature = "moonriver-native")]
RuntimeVariant::Moonriver => Self::moonriver(),
#[cfg(feature = "moonbase-native")]
RuntimeVariant::Moonbase => Self::moonbase(),
_ => panic!("invalid chain spec"),
}
}
}

impl fp_rpc::ConvertTransaction<moonbeam_core_primitives::OpaqueExtrinsic>
for TransactionConverters
{
fn convert_transaction(
&self,
transaction: ethereum_primitives::TransactionV0,
) -> moonbeam_core_primitives::OpaqueExtrinsic {
match &self {
#[cfg(feature = "moonbeam-native")]
Self::Moonbeam(inner) => inner.convert_transaction(transaction),
#[cfg(feature = "moonriver-native")]
Self::Moonriver(inner) => inner.convert_transaction(transaction),
#[cfg(feature = "moonbase-native")]
Self::Moonbase(inner) => inner.convert_transaction(transaction),
}
}
}

/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
///
/// This is the actual implementation that is abstract over the executor and the runtime api.
Expand Down Expand Up @@ -568,18 +496,7 @@ where
let ethapi_cmd = ethapi_cmd.clone();
let max_past_logs = rpc_config.max_past_logs;

let is_moonbeam = parachain_config.chain_spec.is_moonbeam();
let is_moonriver = parachain_config.chain_spec.is_moonriver();

Box::new(move |deny_unsafe, _| {
let transaction_converter: TransactionConverters = if is_moonbeam {
TransactionConverters::moonbeam()
} else if is_moonriver {
TransactionConverters::moonriver()
} else {
TransactionConverters::moonbase()
};

let deps = rpc::FullDeps {
backend: backend.clone(),
client: client.clone(),
Expand All @@ -594,7 +511,6 @@ where
is_authority: collator,
max_past_logs,
network: network.clone(),
transaction_converter,
xcm_senders: None,
};
#[allow(unused_mut)]
Expand Down Expand Up @@ -922,18 +838,7 @@ where
let ethapi_cmd = ethapi_cmd.clone();
let max_past_logs = rpc_config.max_past_logs;

let is_moonbeam = config.chain_spec.is_moonbeam();
let is_moonriver = config.chain_spec.is_moonriver();

Box::new(move |deny_unsafe, _| {
let transaction_converter: TransactionConverters = if is_moonbeam {
TransactionConverters::moonbeam()
} else if is_moonriver {
TransactionConverters::moonriver()
} else {
TransactionConverters::moonbase()
};

let deps = rpc::FullDeps {
backend: backend.clone(),
client: client.clone(),
Expand All @@ -948,7 +853,6 @@ where
is_authority: collator,
max_past_logs,
network: network.clone(),
transaction_converter,
xcm_senders: xcm_senders.clone(),
};
#[allow(unused_mut)]
Expand Down
Loading

0 comments on commit 6ce3f54

Please sign in to comment.