Skip to content

Commit

Permalink
feat: use fork backend
Browse files Browse the repository at this point in the history
experiments
  • Loading branch information
RomarQ committed Jul 19, 2024
1 parent bc22939 commit e5d79eb
Show file tree
Hide file tree
Showing 13 changed files with 3,656 additions and 33 deletions.
175 changes: 174 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ sp-consensus = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", br
sp-storage = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
sp-timestamp = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
sp-wasm-interface = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
sp-rpc = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-build-script-utils = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-frame-rpc-system = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-prometheus-endpoint = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-test-client = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-test-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-test-runtime-client = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-wasm-builder = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }
substrate-rpc-client = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" }

# Frontier (wasm)
ethereum = { version = "0.15.0", default-features = false, features = [
Expand Down Expand Up @@ -371,6 +373,7 @@ strum_macros = "0.24"

assert_cmd = "2.0.10"
async-io = "1.3"
async-std = "1.12.0"
bip32 = { version = "0.5.1", default-features = false, features = ["bip39"] }
clap = { version = "4.0.9", features = ["derive"] }
clap-num = "=1.1.1"
Expand Down Expand Up @@ -481,4 +484,174 @@ inherits = "release"
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.11.0" }
sp-crypto-ec-utils = { path = "../polkadot-sdk/substrate/primitives/crypto/ec-utils" }

[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-crypto-ec-utils = { path = "../polkadot-sdk/substrate/primitives/crypto/ec-utils" }
sc-network-light = { path = "../polkadot-sdk/substrate/client/network/light" }
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" }
substrate-build-script-utils = { path = "../polkadot-sdk/substrate/utils/build-script-utils" }
substrate-frame-rpc-system = { path = "../polkadot-sdk/substrate/utils/frame/rpc/system" }
substrate-wasm-builder = { path = "../polkadot-sdk/substrate/utils/wasm-builder" }
substrate-rpc-client = { path = "../polkadot-sdk/substrate/utils/frame/rpc/client" }

frame-metadata-hash-extension = { path = "../polkadot-sdk/substrate/frame/metadata-hash-extension" }
frame-benchmarking = { path = "../polkadot-sdk/substrate/frame/benchmarking" }
frame-benchmarking-cli = { path = "../polkadot-sdk/substrate/utils/frame/benchmarking-cli" }
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" }
pallet-authority-discovery = { path = "../polkadot-sdk/substrate/frame/authority-discovery" }
pallet-beefy = { path = "../polkadot-sdk/substrate/frame/beefy" }

polkadot-cli = { path = "../polkadot-sdk/polkadot/cli" }
polkadot-service = { path = "../polkadot-sdk/polkadot/node/service" }
polkadot-primitives = { path = "../polkadot-sdk/polkadot/primitives" }
staging-xcm = { path = "../polkadot-sdk/polkadot/xcm" }
xcm-simulator = { path = "../polkadot-sdk/polkadot/xcm/xcm-simulator" }
staging-xcm-builder = { path = "../polkadot-sdk/polkadot/xcm/xcm-builder" }
staging-xcm-executor = { path = "../polkadot-sdk/polkadot/xcm/xcm-executor" }
rococo-runtime = { path = "../polkadot-sdk/polkadot/runtime/rococo" }
westend-runtime = { path = "../polkadot-sdk/polkadot/runtime/westend" }

substrate-test-client = { path = "../polkadot-sdk/substrate/test-utils/client" }
substrate-test-runtime = { path = "../polkadot-sdk/substrate/test-utils/runtime" }
substrate-test-runtime-client = { path = "../polkadot-sdk/substrate/test-utils/runtime/client" }

cumulus-pallet-dmp-queue = { path = "../polkadot-sdk/cumulus/pallets/dmp-queue" }
cumulus-pallet-parachain-system = { path = "../polkadot-sdk/cumulus/pallets/parachain-system"}
cumulus-pallet-xcm = { path = "../polkadot-sdk/cumulus/pallets/xcm" }
cumulus-pallet-xcmp-queue = { path = "../polkadot-sdk/cumulus/pallets/xcmp-queue" }
cumulus-primitives-parachain-inherent = { path = "../polkadot-sdk/cumulus/primitives/parachain-inherent" }
cumulus-primitives-timestamp = { path = "../polkadot-sdk/cumulus/primitives/timestamp" }
cumulus-primitives-utility = { path = "../polkadot-sdk/cumulus/primitives/utility" }
staging-parachain-info = { path = "../polkadot-sdk/cumulus/parachains/pallets/parachain-info" }
parachains-common = { path = "../polkadot-sdk/cumulus/parachains/common" }

cumulus-client-cli = { path = "../polkadot-sdk/cumulus/client/cli" }
cumulus-client-service = { path = "../polkadot-sdk/cumulus/client/service" }
cumulus-relay-chain-minimal-node = { path = "../polkadot-sdk/cumulus/client/relay-chain-minimal-node" }
cumulus-client-consensus-common = { path = "../polkadot-sdk/cumulus/client/consensus/common" }
cumulus-primitives-core = { path = "../polkadot-sdk/cumulus/primitives/core" }
cumulus-client-collator = { path = "../polkadot-sdk/cumulus/client/collator" }
cumulus-client-consensus-proposer = { path = "../polkadot-sdk/cumulus/client/consensus/proposer" }
cumulus-client-consensus-relay-chain = { path = "../polkadot-sdk/cumulus/client/consensus/relay-chain" }
cumulus-client-network = { path = "../polkadot-sdk/cumulus/client/network" }
cumulus-client-parachain-inherent = { path = "../polkadot-sdk/cumulus/client/parachain-inherent" }
cumulus-relay-chain-inprocess-interface = { path = "../polkadot-sdk/cumulus/client/relay-chain-inprocess-interface" }
cumulus-relay-chain-interface = { path = "../polkadot-sdk/cumulus/client/relay-chain-interface" }
cumulus-relay-chain-rpc-interface = { path = "../polkadot-sdk/cumulus/client/relay-chain-rpc-interface" }
cumulus-test-relay-sproof-builder = { path = "../polkadot-sdk/cumulus/test/relay-sproof-builder" }

pallet-xcm = { path = "../polkadot-sdk/polkadot/xcm/pallet-xcm" }
pallet-xcm-benchmarks = { path = "../polkadot-sdk/polkadot/xcm/pallet-xcm-benchmarks" }
polkadot-core-primitives = { path = "../polkadot-sdk/polkadot/core-primitives" }
polkadot-parachain-primitives = { path = "../polkadot-sdk/polkadot/parachain" }
polkadot-runtime-common = { path = "../polkadot-sdk/polkadot/runtime/common" }
polkadot-runtime-parachains = { path = "../polkadot-sdk/polkadot/runtime/parachains" }
polkadot-node-subsystem = { path = "../polkadot-sdk/polkadot/node/subsystem" }
polkadot-node-primitives = { path = "../polkadot-sdk/polkadot/node/primitives" }
9 changes: 9 additions & 0 deletions node/cli-opt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use std::path::PathBuf;
// 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 +112,10 @@ pub struct RpcConfig {
pub frontier_backend_config: FrontierBackendConfig,
pub no_prometheus_prefix: bool,
}

#[derive(Clone)]
pub struct LazyLoadingConfig {
pub state_rpc: String,
pub from_block: H256,
pub state_overrides_path: Option<PathBuf>,
}
15 changes: 15 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,15 @@ 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>,

#[clap(long, value_name = "PATH", value_parser)]
pub fork_state_overrides: Option<PathBuf>,

/// When blocks should be sealed in the dev service.
///
/// Options are "instant", "manual", or timer interval in milliseconds
Expand Down
37 changes: 33 additions & 4 deletions 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, moonbase_runtime, moonbeam_runtime, moonriver_runtime,
HostFunctions, IdentifyVariant,
Expand Down Expand Up @@ -704,8 +704,6 @@ pub fn run() -> Result<()> {
};

let extension = chain_spec::Extensions::try_get(&*config.chain_spec);
let para_id = extension.map(|e| e.para_id);
let id = ParaId::from(cli.run.parachain_id.clone().or(para_id).unwrap_or(1000));

let rpc_config = cli.run.new_rpc_config();

Expand All @@ -720,7 +718,35 @@ pub fn run() -> Result<()> {
|| config.chain_spec.is_dev()
|| relay_chain_id == Some("dev-service");

if dev_service {
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"),
state_overrides_path: cli.run.fork_state_overrides,
};

return moonbeam_service::lazy_loading::new_lazy_loading_service::<
moonbeam_runtime::RuntimeApi,
moonbeam_service::MoonbeamCustomizations,
sc_network::NetworkWorker<_, _>,
>(
config,
author_id,
cli.run.sealing,
rpc_config,
lazy_loading_config,
hwbench,
)
.await
.map_err(Into::into);
} else if dev_service {
// 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.
Expand Down Expand Up @@ -765,6 +791,9 @@ pub fn run() -> Result<()> {
.chain(cli.relaychain_args.iter()),
);

let para_id = extension.map(|e| e.para_id);
let id = ParaId::from(cli.run.parachain_id.clone().or(para_id).unwrap_or(1000));

let parachain_account =
AccountIdConversion::<polkadot_primitives::v7::AccountId>::into_account_truncating(&id);

Expand Down
Loading

0 comments on commit e5d79eb

Please sign in to comment.