Skip to content

Commit

Permalink
feat: use fork backend
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed Jun 27, 2024
1 parent 6945830 commit 800ac3e
Show file tree
Hide file tree
Showing 6 changed files with 1,004 additions and 28 deletions.
112 changes: 112 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,115 @@ overflow-checks = true

[patch."https://github.com/paritytech/polkadot-sdk"]
sp-crypto-ec-utils = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" }

[patch."https://github.com/moonbeam-foundation/polkadot-sdk"]
sc-service = { path = "../polkadot-sdk/substrate/client/service" }
pallet-transaction-payment-rpc = { path = "../polkadot-sdk/substrate/frame/transaction-payment/rpc" }
sc-basic-authorship = { path = "../polkadot-sdk/substrate/client/basic-authorship" }
sc-block-builder = { path = "../polkadot-sdk/substrate/client/block-builder" }
sc-chain-spec = { path = "../polkadot-sdk/substrate/client/chain-spec" }
sc-cli = { path = "../polkadot-sdk/substrate/client/cli" }
sc-client-api = { path = "../polkadot-sdk/substrate/client/api" }
sc-client-db = { path = "../polkadot-sdk/substrate/client/db" }
sc-consensus = { path = "../polkadot-sdk/substrate/client/consensus/common" }
sc-consensus-grandpa = { path = "../polkadot-sdk/substrate/client/consensus/grandpa" }
sc-consensus-babe = { path = "../polkadot-sdk/substrate/client/consensus/babe" }
sc-consensus-babe-rpc = { path = "../polkadot-sdk/substrate/client/consensus/babe/rpc" }
sc-consensus-aura = { path = "../polkadot-sdk/substrate/client/consensus/aura" }
sc-consensus-manual-seal = { path = "../polkadot-sdk/substrate/client/consensus/manual-seal" }
sc-consensus-slots = { path = "../polkadot-sdk/substrate/client/consensus/slots" }
sc-consensus-epochs = { path = "../polkadot-sdk/substrate/client/consensus/epochs" }
sc-executor = { path = "../polkadot-sdk/substrate/client/executor" }
sc-executor-common = { path = "../polkadot-sdk/substrate/client/executor/common" }
sc-executor-wasmtime = { path = "../polkadot-sdk/substrate/client/executor/wasmtime" }
sc-informant = { path = "../polkadot-sdk/substrate/client/informant" }
sc-network = { path = "../polkadot-sdk/substrate/client/network" }
sc-network-common = { path = "../polkadot-sdk/substrate/client/network/common" }
sc-network-sync = { path = "../polkadot-sdk/substrate/client/network/sync" }
sc-offchain = { path = "../polkadot-sdk/substrate/client/offchain" }
sc-rpc = { path = "../polkadot-sdk/substrate/client/rpc" }
sc-rpc-api = { path = "../polkadot-sdk/substrate/client/rpc-api" }
sc-sysinfo = { path = "../polkadot-sdk/substrate/client/sysinfo" }
sc-telemetry = { path = "../polkadot-sdk/substrate/client/telemetry" }
sc-tracing = { path = "../polkadot-sdk/substrate/client/tracing" }
sc-transaction-pool = { path = "../polkadot-sdk/substrate/client/transaction-pool" }
sc-transaction-pool-api = { path = "../polkadot-sdk/substrate/client/transaction-pool/api" }
sc-utils = { path = "../polkadot-sdk/substrate/client/utils" }
sc-network-gossip = { path = "../polkadot-sdk/substrate/client/network-gossip" }
sc-keystore = { path = "../polkadot-sdk/substrate/client/keystore" }
sc-network-transactions = { path = "../polkadot-sdk/substrate/client/network/transactions" }
sp-consensus = { path = "../polkadot-sdk/substrate/primitives/consensus/common" }
sp-consensus-slots = { path = "../polkadot-sdk/substrate/primitives/consensus/slots" }
sp-consensus-babe = { path = "../polkadot-sdk/substrate/primitives/consensus/babe" }
sp-consensus-aura = { path = "../polkadot-sdk/substrate/primitives/consensus/aura" }
sp-consensus-grandpa = { path = "../polkadot-sdk/substrate/primitives/consensus/grandpa" }
sp-storage = { path = "../polkadot-sdk/substrate/primitives/storage" }
sp-timestamp = { path = "../polkadot-sdk/substrate/primitives/timestamp" }
sp-wasm-interface = { path = "../polkadot-sdk/substrate/primitives/wasm-interface" }
sp-api = { path = "../polkadot-sdk/substrate/primitives/api" }
sp-blockchain = { path = "../polkadot-sdk/substrate/primitives/blockchain" }
sp-session = { path = "../polkadot-sdk/substrate/primitives/session" }
sp-runtime = { path = "../polkadot-sdk/substrate/primitives/runtime" }
sp-core = { path = "../polkadot-sdk/substrate/primitives/core" }
sp-version = { path = "../polkadot-sdk/substrate/primitives/version" }
sp-externalities = { path = "../polkadot-sdk/substrate/primitives/externalities" }
sp-inherents = { path = "../polkadot-sdk/substrate/primitives/inherents" }
sp-runtime-interface = { path = "../polkadot-sdk/substrate/primitives/runtime-interface" }
sp-arithmetic = { path = "../polkadot-sdk/substrate/primitives/arithmetic" }
sp-maybe-compressed-blob = { path = "../polkadot-sdk/substrate/primitives/maybe-compressed-blob" }
sp-crypto-hashing = { path = "../polkadot-sdk/substrate/primitives/crypto/hashing" }
sp-io = { path = "../polkadot-sdk/substrate/primitives/io" }
sp-tracing = { path = "../polkadot-sdk/substrate/primitives/tracing" }
sp-application-crypto = { path = "../polkadot-sdk/substrate/primitives/application-crypto" }
sp-std = { path = "../polkadot-sdk/substrate/primitives/std" }
sp-weights = { path = "../polkadot-sdk/substrate/primitives/weights" }
sp-block-builder = { path = "../polkadot-sdk/substrate/primitives/block-builder" }
sp-debug-derive = { path = "../polkadot-sdk/substrate/primitives/debug-derive" }
sp-keystore = { path = "../polkadot-sdk/substrate/primitives/keystore" }
sp-offchain = { path = "../polkadot-sdk/substrate/primitives/offchain" }
sp-state-machine = { path = "../polkadot-sdk/substrate/primitives/state-machine" }
sp-transaction-pool = { path = "../polkadot-sdk/substrate/primitives/transaction-pool" }
sp-trie = { path = "../polkadot-sdk/substrate/primitives/trie" }
sp-genesis-builder = { path = "../polkadot-sdk/substrate/primitives/genesis-builder" }
sp-staking = { path = "../polkadot-sdk/substrate/primitives/staking" }
sp-npos-elections = { path = "../polkadot-sdk/substrate/primitives/npos-elections" }
sp-keyring = { path = "../polkadot-sdk/substrate/primitives/keyring" }
sp-rpc = { path = "../polkadot-sdk/substrate/primitives/rpc" }
sp-transaction-storage-proof = { path = "../polkadot-sdk/substrate/primitives/transaction-storage-proof" }
sp-database = { path = "../polkadot-sdk/substrate/primitives/database" }

substrate-state-trie-migration-rpc = { path = "../polkadot-sdk/substrate/utils/frame/rpc/state-trie-migration-rpc" }
substrate-prometheus-endpoint = { path = "../polkadot-sdk/substrate/utils/prometheus" }

frame-benchmarking = { path = "../polkadot-sdk/substrate/frame/benchmarking" }
frame-executive = { path = "../polkadot-sdk/substrate/frame/executive" }
frame-support = { path = "../polkadot-sdk/substrate/frame/support" }
frame-system = { path = "../polkadot-sdk/substrate/frame/system" }
frame-system-benchmarking = { path = "../polkadot-sdk/substrate/frame/system/benchmarking" }
frame-system-rpc-runtime-api = { path = "../polkadot-sdk/substrate/frame/system/rpc/runtime-api" }
frame-try-runtime = { path = "../polkadot-sdk/substrate/frame/try-runtime" }
frame-election-provider-support = { path = "../polkadot-sdk/substrate/frame/election-provider-support" }
frame-election-provider-solution-type = { path = "../polkadot-sdk/substrate/frame/election-provider-support/solution-type" }
pallet-assets = { path = "../polkadot-sdk/substrate/frame/assets" }
pallet-balances = { path = "../polkadot-sdk/substrate/frame/balances" }
pallet-collective = { path = "../polkadot-sdk/substrate/frame/collective" }
pallet-conviction-voting = { path = "../polkadot-sdk/substrate/frame/conviction-voting" }
pallet-identity = { path = "../polkadot-sdk/substrate/frame/identity" }
pallet-message-queue = { path = "../polkadot-sdk/substrate/frame/message-queue" }
pallet-multisig = { path = "../polkadot-sdk/substrate/frame/multisig" }
pallet-preimage = { path = "../polkadot-sdk/substrate/frame/preimage" }
pallet-proxy = { path = "../polkadot-sdk/substrate/frame/proxy" }
pallet-referenda = { path = "../polkadot-sdk/substrate/frame/referenda" }
pallet-root-testing = { path = "../polkadot-sdk/substrate/frame/root-testing" }
pallet-scheduler = { path = "../polkadot-sdk/substrate/frame/scheduler" }
pallet-society = { path = "../polkadot-sdk/substrate/frame/society" }
pallet-staking = { path = "../polkadot-sdk/substrate/frame/staking" }
pallet-sudo = { path = "../polkadot-sdk/substrate/frame/sudo" }
pallet-timestamp = { path = "../polkadot-sdk/substrate/frame/timestamp" }
pallet-transaction-payment = { path = "../polkadot-sdk/substrate/frame/transaction-payment" }
pallet-transaction-payment-rpc-runtime-api = { path = "../polkadot-sdk/substrate/frame/transaction-payment/rpc/runtime-api" }
pallet-treasury = { path = "../polkadot-sdk/substrate/frame/treasury" }
pallet-utility = { path = "../polkadot-sdk/substrate/frame/utility" }
pallet-whitelist = { path = "../polkadot-sdk/substrate/frame/whitelist" }
pallet-authorship = { path = "../polkadot-sdk/substrate/frame/authorship" }
pallet-session = { path = "../polkadot-sdk/substrate/frame/session" }
6 changes: 6 additions & 0 deletions node/cli-opt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.
use primitive_types::H256;
use std::str::FromStr;

pub mod account_key;
Expand Down Expand Up @@ -110,3 +111,8 @@ pub struct RpcConfig {
pub frontier_backend_config: FrontierBackendConfig,
pub no_prometheus_prefix: bool,
}

pub struct LazyLoadingConfig {
pub state_rpc: String,
pub from_block: H256,
}
12 changes: 12 additions & 0 deletions node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ use clap::Parser;
use moonbeam_cli_opt::{account_key::GenerateAccountKey, EthApi, FrontierBackendType, Sealing};
use moonbeam_service::chain_spec;
use sc_cli::{Error as CliError, SubstrateCli};
use sp_core::H256;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Duration;

fn parse_block_hash(s: &str) -> Result<H256, String> {
H256::from_str(s).map_err(|err| err.to_string())
}

/// Sub-commands supported by the collator.
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
Expand Down Expand Up @@ -136,6 +142,12 @@ pub struct RunCmd {
#[clap(long)]
pub dev_service: bool,

#[clap(long)]
pub fork_chain_from_rpc: Option<String>,

#[arg(long, value_name = "BLOCK", value_parser = parse_block_hash)]
pub block: Option<H256>,

/// When blocks should be sealed in the dev service.
///
/// Options are "instant", "manual", or timer interval in milliseconds
Expand Down
63 changes: 62 additions & 1 deletion node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use cumulus_client_cli::extract_genesis_wasm;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::BenchmarkCmd;
use log::{info, warn};
use moonbeam_cli_opt::EthApi;
use moonbeam_cli_opt::{EthApi, LazyLoadingConfig};
use moonbeam_service::{chain_spec, frontier_database_dir, IdentifyVariant};
use parity_scale_codec::Encode;
#[cfg(feature = "westend-native")]
Expand Down Expand Up @@ -750,6 +750,67 @@ pub fn run() -> Result<()> {
};
}

if cli.run.fork_chain_from_rpc.is_some() {
// When running the dev service, just use Alice's author inherent
//TODO maybe make the --alice etc flags work here, and consider bringing back
// the author-id flag. For now, this will work.
let author_id = Some(chain_spec::get_from_seed::<nimbus_primitives::NimbusId>(
"Alice",
));

let lazy_loading_config = LazyLoadingConfig {
state_rpc: cli.run.fork_chain_from_rpc.expect("Expected a valid RPC"),
from_block: cli.run.block.expect("Expected a valid block hash"),
};

return match &config.chain_spec {
#[cfg(feature = "moonriver-native")]
spec if spec.is_moonriver() => moonbeam_service::new_forked_network::<
moonbeam_service::moonriver_runtime::RuntimeApi,
moonbeam_service::MoonriverCustomizations,
>(
config,
author_id,
cli.run.sealing,
rpc_config,
lazy_loading_config,
hwbench,
)
.await
.map_err(Into::into),
#[cfg(feature = "moonbeam-native")]
spec if spec.is_moonbeam() => moonbeam_service::new_forked_network::<
moonbeam_service::moonbeam_runtime::RuntimeApi,
moonbeam_service::MoonbeamCustomizations,
>(
config,
author_id,
cli.run.sealing,
rpc_config,
lazy_loading_config,
hwbench,
)
.await
.map_err(Into::into),
#[cfg(feature = "moonbase-native")]
_ => moonbeam_service::new_forked_network::<
moonbeam_service::moonbase_runtime::RuntimeApi,
moonbeam_service::MoonbaseCustomizations,
>(
config,
author_id,
cli.run.sealing,
rpc_config,
lazy_loading_config,
hwbench,
)
.await
.map_err(Into::into),
#[cfg(not(feature = "moonbase-native"))]
_ => panic!("invalid chain spec"),
};
}

let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name().to_string()]
Expand Down
Loading

0 comments on commit 800ac3e

Please sign in to comment.