Skip to content

Commit

Permalink
Merge branch 'moonbeam-polkadot-stable2407' into agustin-xcm-dry-run-api
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ authored Oct 1, 2024
2 parents 88e14af + 09eddbd commit a0fb852
Show file tree
Hide file tree
Showing 37 changed files with 915 additions and 204 deletions.
3 changes: 0 additions & 3 deletions .github/workflow-templates/cargo-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ runs:
params="$params --features ${{ inputs.features }}"
fi
echo "cargo build $params"
cargo build $params --features lazy-loading
cp target/release/moonbeam target/release/lazy-loading
cargo build $params
- name: Display binary comments
shell: bash
Expand All @@ -76,4 +74,3 @@ runs:
run: |
mkdir -p build
cp target/release/moonbeam build/moonbeam;
cp target/release/lazy-loading build/lazy-loading;
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,9 @@ jobs:
path: target/release
- name: "Run lazy loading tests"
run: |
chmod uog+x target/release/moonbeam
cd test
pnpm install
chmod uog+x ../target/release/lazy-loading
pnpm moonwall test lazy_loading_${{ matrix.chain }}
- name: Zip and Upload Node Logs on Failure
if: failure()
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/subxt-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: "runtime-${{ github.event.inputs.spec_version }}"
- name: Local build new Node
uses: ./.github/workflow-templates/cargo-build
- name: Upload Node
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Docker images are published for every tagged release. Learn more with `moonbeam

```bash
# Join the public testnet
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.0 --chain alphanet
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.1 --chain alphanet
```

You can find more detailed instructions to [run a full node in our TestNet](https://docs.moonbeam.network/node-operators/networks/run-a-node/overview/)
Expand All @@ -28,7 +28,7 @@ locally. You can quickly set up a single node without a relay chain backing it u

```bash
# Run a dev service node
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.0 --dev
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.1 --dev
```

For more information, see our detailed instructions to [run a development node](https://docs.moonbeam.network/builders/get-started/networks/moonbeam-dev/)
Expand All @@ -39,10 +39,10 @@ The above command will start the node in instant seal mode. It creates a block w

```bash
# Author a block every 6 seconds.
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.0 --dev --sealing 6000
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.1 --dev --sealing 6000

# Manually control the block authorship and finality
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.0 --dev --sealing manual
docker run --network="host" moonbeamfoundation/moonbeam:v0.40.1 --dev --sealing manual
```

### Prefunded Development Addresses
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pallet-xcm = { workspace = true, features = [ "std" ] }
xcm-builder = { workspace = true, features = [ "std" ] }

[features]
default = [ "moonbase-native", "moonbeam-native", "moonriver-native" ]
default = [ "moonbase-native", "moonbeam-native", "moonriver-native", "lazy-loading" ]

rococo-native = [ "moonbeam-service/rococo-native" ]
westend-native = [ "moonbeam-cli/westend-native", "moonbeam-service/westend-native" ]
Expand Down
158 changes: 70 additions & 88 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,8 @@ fn validate_trace_environment(cli: &Cli) -> Result<()> {

/// Parse command line arguments into service configuration.
pub fn run() -> Result<()> {
let mut cli = Cli::from_args();
let cli = Cli::from_args();
let _ = validate_trace_environment(&cli)?;
// Set --execution wasm as default
let execution_strategies = cli.run.base.base.import_params.execution_strategies.clone();
if execution_strategies.execution.is_none() {
cli.run
.base
.base
.import_params
.execution_strategies
.execution = Some(sc_cli::ExecutionStrategy::Wasm);
}

match &cli.subcommand {
Some(Subcommand::BuildSpec(params)) => {
Expand Down Expand Up @@ -694,8 +684,6 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(&(*cli.run).normalize())?;
let collator_options = cli.run.collator_options();

// It is used when feature "lazy-loading" is enabled
#[allow(unused_mut)]
runner.run_node_until_exit(|mut config| async move {
let hwbench = if !cli.run.no_hardware_benchmarks {
config.database.path().map(|database_path| {
Expand All @@ -710,15 +698,82 @@ pub fn run() -> Result<()> {

let rpc_config = cli.run.new_rpc_config();

#[cfg(feature = "lazy-loading")]
if let Some(fork_chain_from_rpc) = cli.run.fork_chain_from_rpc {
// If dev service was requested, start up manual or instant seal.
// Otherwise continue with the normal parachain node.
// Dev service can be requested in two ways.
// 1. by providing the --dev-service flag to the CLI
// 2. by specifying "dev-service" in the chain spec's "relay-chain" field.
// NOTE: the --dev flag triggers the dev service by way of number 2
let relay_chain_id = extension.map(|e| e.relay_chain.as_str());
let para_id = extension.map(|e| e.para_id);

let dev_service = cli.run.dev_service
|| config.chain_spec.is_dev()
|| relay_chain_id == Some("dev-service");
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.
let author_id = Some(chain_spec::get_from_seed::<nimbus_primitives::NimbusId>(
"Alice",
));

return match &config.chain_spec {
#[cfg(feature = "moonriver-native")]
spec if spec.is_moonriver() => moonbeam_service::new_dev::<
moonbeam_service::moonriver_runtime::RuntimeApi,
moonbeam_service::MoonriverCustomizations,
sc_network::NetworkWorker<_, _>,
>(
config,
para_id,
author_id,
cli.run.sealing,
rpc_config,
hwbench,
)
.await
.map_err(Into::into),
#[cfg(feature = "moonbeam-native")]
spec if spec.is_moonbeam() => moonbeam_service::new_dev::<
moonbeam_service::moonbeam_runtime::RuntimeApi,
moonbeam_service::MoonbeamCustomizations,
sc_network::NetworkWorker<_, _>,
>(
config,
para_id,
author_id,
cli.run.sealing,
rpc_config,
hwbench,
)
.await
.map_err(Into::into),
#[cfg(feature = "moonbase-native")]
_ => moonbeam_service::new_dev::<
moonbeam_service::moonbase_runtime::RuntimeApi,
moonbeam_service::MoonbaseCustomizations,
sc_network::NetworkWorker<_, _>,
>(
config,
para_id,
author_id,
cli.run.sealing,
rpc_config,
hwbench,
)
.await
.map_err(Into::into),
#[cfg(not(feature = "moonbase-native"))]
_ => panic!("invalid chain spec"),
};
}
#[cfg(feature = "lazy-loading")]
if let Some(fork_chain_from_rpc) = cli.run.fork_chain_from_rpc {
let author_id = Some(chain_spec::get_from_seed::<nimbus_primitives::NimbusId>(
"Alice",
));

let lazy_loading_config = moonbeam_cli_opt::LazyLoadingConfig {
state_rpc: fork_chain_from_rpc,
from_block: cli.run.block,
Expand Down Expand Up @@ -749,79 +804,6 @@ pub fn run() -> Result<()> {
.await
.map_err(Into::into);
}
#[cfg(not(feature = "lazy-loading"))]
{
// If dev service was requested, start up manual or instant seal.
// Otherwise continue with the normal parachain node.
// Dev service can be requested in two ways.
// 1. by providing the --dev-service flag to the CLI
// 2. by specifying "dev-service" in the chain spec's "relay-chain" field.
// NOTE: the --dev flag triggers the dev service by way of number 2
let relay_chain_id = extension.map(|e| e.relay_chain.as_str());
let para_id = extension.map(|e| e.para_id);

let dev_service = cli.run.dev_service
|| config.chain_spec.is_dev()
|| relay_chain_id == Some("dev-service");
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.
let author_id = Some(chain_spec::get_from_seed::<
nimbus_primitives::NimbusId,
>("Alice"));

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

let polkadot_cli = RelayChainCli::new(
&config,
Expand Down
19 changes: 1 addition & 18 deletions node/service/src/lazy_loading/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,8 +1673,6 @@ where
Block: BlockT + DeserializeOwned,
Block::Hash: From<H256>,
{
use sc_client_api::Backend as _;
use sc_client_api::BlockImportOperation as _;
let uri: String = lazy_loading_config.state_rpc.clone().into();

let http_client = jsonrpsee::http_client::HttpClientBuilder::default()
Expand Down Expand Up @@ -1742,23 +1740,8 @@ where

let _ = helpers::produce_genesis_block(backend.clone());

let mut op = backend.begin_operation().unwrap();
op.before_fork = true;

let extrinsics: Vec<Block::Extrinsic> = checkpoint.extrinsics().to_vec();

op.set_block_data(
checkpoint.header().clone(),
Some(extrinsics.clone()),
None,
None,
NewBlockState::Final,
)?;

backend.commit_operation(op)?;

// Produce first block after the fork
let _ = helpers::produce_first_block(backend.clone(), state_overrides)?;
let _ = helpers::produce_first_block(backend.clone(), checkpoint, state_overrides)?;

Ok(backend)
}
43 changes: 28 additions & 15 deletions node/service/src/lazy_loading/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
use crate::lazy_loading;
use crate::lazy_loading::backend::RPC;
use cumulus_primitives_core::BlockT;
use parity_scale_codec::Encode;
use sc_client_api::{Backend, BlockImportOperation, NewBlockState};
use sp_core::{twox_128, H256};
use sp_core::{twox_128, twox_64, H256};
use sp_runtime::traits::{Header, One};
use sp_runtime::Saturating;
use sp_storage::{StateVersion, Storage, StorageKey};
Expand Down Expand Up @@ -56,30 +57,42 @@ pub fn produce_genesis_block<TBl: BlockT + sp_runtime::DeserializeOwned>(

pub fn produce_first_block<Block: BlockT + sp_runtime::DeserializeOwned>(
backend: Arc<lazy_loading::backend::Backend<Block>>,
state_overrides: Vec<(Vec<u8>, Vec<u8>)>,
fork_checkpoint: Block,
mut state_overrides: Vec<(Vec<u8>, Vec<u8>)>,
) -> sp_blockchain::Result<()> {
use sc_client_api::HeaderBackend;
let mut op = backend.begin_operation()?;

let state_root = op.reset_storage(
Storage {
top: state_overrides.into_iter().collect(),
children_default: Default::default(),
},
StateVersion::V0,
)?;

let head_info = backend.blockchain.info();
let next_block_number = head_info.finalized_number.saturating_add(One::one());
let header = fork_checkpoint.header().clone();
let next_block_number = header.number().saturating_add(One::one());

let header: Block::Header = Block::Header::new(
next_block_number,
Default::default(),
state_root,
head_info.finalized_hash,
Default::default(),
header.hash(),
Default::default(),
);

// IMPORTANT: Add first block after the fork to frame_system::BlockHash
// This is required by CheckMortality/CheckEra in SignedExtension
let key = [
&twox_128(b"System"),
&twox_128(b"BlockHash"),
twox_64(&next_block_number.encode()).as_slice(),
&next_block_number.encode(),
]
.concat();
state_overrides.push((key, header.hash().encode()));

let _ = op.reset_storage(
Storage {
top: state_overrides.into_iter().collect(),
children_default: Default::default(),
},
StateVersion::V0,
)?;

// Create empty first block
let _ = op.set_block_data(
header.clone(),
Some(Default::default()),
Expand Down
Loading

0 comments on commit a0fb852

Please sign in to comment.