Skip to content

Commit

Permalink
Import state from running eden chain at 4541250
Browse files Browse the repository at this point in the history
create some chainspe magic to generate a new
genesis for chain at release 2.5.2
  • Loading branch information
simonsso committed Apr 15, 2024
1 parent 89f228c commit 48048af
Show file tree
Hide file tree
Showing 12 changed files with 3,707 additions and 687 deletions.
1,197 changes: 643 additions & 554 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ resolver = "1"
# Substrate runtime requires unwind apparently, and anyways it gives more useful
# panic messages which can be useful for troubleshooting purposes
panic = "unwind"
[workspace.dependencies]
hex-literal = { version = "0.4.1" }
serde = { version = "1.0.152", default-features = false }
serde_json = { version = "1.0.104", default-features = false }
3 changes: 3 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ runtime-benchmarks = [
]

[dependencies]
bzip2-rs = "0.1.2"
clap = { version = "4.1.8", features = ["derive"] }
derive_more = "0.99.2"
log = "0.4.17"
codec = { package = "parity-scale-codec", version = "3.0.0" }
serde = { version = "1.0.152", features = ["derive"] }
serde_json.workspace = true
hex-literal = "0.4.1"

# RPC related Dependencies
jsonrpsee = { version = "0.16.2", features = ["server"] }
Expand Down
Binary file added node/res/eden-export.json.bz2
Binary file not shown.
2,663 changes: 2,534 additions & 129 deletions node/res/eden-testing.spec.json

Large diffs are not rendered by default.

424 changes: 424 additions & 0 deletions node/res/paseo.raw.json

Large diffs are not rendered by default.

Binary file added node/res/runtime_eden.compact.wasm
Binary file not shown.
91 changes: 91 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
// clippy complains about ChainSpecGroup which we cannot modify
#![allow(clippy::derive_partial_eq_without_eq)]

use std::borrow::Cow;
use std::{fs::File, str::FromStr};
use std::io::Read;

use bzip2_rs::DecoderReader;
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use primitives::{AccountId, Balance, Signature};
use runtime_eden::{
constants::{EXISTENTIAL_DEPOSIT, NODL},
Expand All @@ -29,6 +35,8 @@ use runtime_eden::{
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sp_core::crypto::Ss58Codec;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::{
bounded_vec,
Expand Down Expand Up @@ -192,6 +200,89 @@ fn development_config_genesis(id: ParaId) -> RuntimeGenesisConfig {
)
}

pub fn paradis_config(id: ParaId) -> Result<ChainSpec, Box<dyn std::error::Error>> {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "notNodl".into());
properties.insert("tokenDecimals".into(), 11.into());
properties.insert("ss58Format".into(), 37.into());

let patch_chain_spec = ChainSpec::from_genesis(
// Name
"Parachain Hades testnet",
// ID
"hades",
ChainType::Live,
move || eden_testnet_genesis(
sp_core::sr25519::Public::from_ss58check("4jmcpevRTaN4sd4KGwAQ48w1UkC1Ky38HKCBdNpEC8jbv2N9").expect("Internal Error").into(),
vec![
(
sp_core::sr25519::Public::from_ss58check("4jaftaRRK57EAGw2ooaLU7wQDQ4FpVaj2yTqxxkPpX49uRrW").expect("Internal Error").into(),
sp_core::sr25519::Public::from_ss58check("4jaftaRRK57EAGw2ooaLU7wQDQ4FpVaj2yTqxxkPpX49uRrW").expect("Internal Error").into(),
),
(
sp_core::sr25519::Public::from_ss58check("4j5pvMg65HBK4KvUcgSGMPEqrRjXkWJmjuqhb7AktmrB9auf").expect("Internal Error").into(),
sp_core::sr25519::Public::from_ss58check("4j5pvMg65HBK4KvUcgSGMPEqrRjXkWJmjuqhb7AktmrB9auf").expect("Internal Error").into(),
),
(
sp_core::sr25519::Public::from_ss58check("4mXXuWGQNgUW8QzWH8bg2Ao654d99CSYJXfELCCyd7qx2ACs").expect("Internal Error").into(),
sp_core::sr25519::Public::from_ss58check("4mXXuWGQNgUW8QzWH8bg2Ao654d99CSYJXfELCCyd7qx2ACs").expect("Internal Error").into(),
)
],
None,
id,
),
Vec::new(),
None,
None,
None,
Some(properties),
Extensions {
// TODO change to paseo
relay_chain: "paseo".into(), // You MUST set this to the correct network!
para_id: id.into(),
},
);

let mut target_spec = Value::from_str(&patch_chain_spec.clone().as_json(true)?)?;
// black list all data with values in current spec
let mut blacklist = Value::from_str(&patch_chain_spec.clone().as_json(true)?)?;

// black list block number of relay chain we are a parachain under.
blacklist["genesis"]["raw"]["top"]["0x45323df7cc47150b3930e2666b0aa313a2bca190d36bd834cc73a38fc213ecbd"] = true.into();

let compressed_file = File::open("/home/simson/nodle/chain/node/res/eden-export.json.bz2")?;

let mut reader = DecoderReader::new(compressed_file);

let mut exported_bytes = Vec::<u8>::with_capacity(500_000_000);
let _ = reader.read_to_end(&mut exported_bytes)?;

let exported_state: Value = serde_json::from_slice(&exported_bytes[..])?;

if let Some(top) = exported_state["genesis"]["raw"]["top"].as_object() {
for key in top.keys() {
if blacklist["genesis"]["raw"]["top"][key].is_null() {
target_spec["genesis"]["raw"]["top"][key] = top[key].clone();
}
}
}

// working_cs_state["id"] = "hades".into();
// working_cs_state["bootNodes"] = Value::Array(vec![]);
// working_cs_state["telemetryEndpoints"] = Value::Array(vec![]);
// working_cs_state["relayChain"] = "paseo".into();

let cs_string = target_spec.to_string();

// Maybe this debug is nneded soon again
// println!("{cs_string}");

let cs_bytes = Cow::from_iter(cs_string.bytes());
let cs = ChainSpec::from_json_bytes(cs_bytes)?;
Ok(cs)
}

pub fn development_config(id: ParaId) -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
Expand Down
4 changes: 2 additions & 2 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const DEFAULT_PARA_ID: u32 = 2026;

fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"eden-dev" | "dev" => Box::new(chain_spec::development_config(DEFAULT_PARA_ID.into())),
"eden-local" | "local" => Box::new(chain_spec::local_testnet_config(DEFAULT_PARA_ID.into())),
"eden-local" | "local" | "eden-dev" | "dev" => Box::new(chain_spec::development_config(DEFAULT_PARA_ID.into())),
"eden-testing" | "testing" | "test" | "paradis" => Box::new(chain_spec::testing_config()),
"hades" => Box::new(chain_spec::paradis_config(DEFAULT_PARA_ID.into()).map_err(|e| format!("{e:?}"))?),
"eden" | "production" | "main" | "" => Box::new(chain_spec::production_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
Expand Down
2 changes: 1 addition & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::sync::Arc;
use primitives::{AccountId, Balance, Block, Nonce};

use sc_client_api::AuxStore;
pub use sc_rpc::DenyUnsafe;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{sync::Arc, time::Duration};
// rpc
use jsonrpsee::RpcModule;

pub use primitives::{AccountId, Balance, Block, Nonce};
pub use primitives::{AccountId, Balance, Block, BlockNumber, Hash, Header, Nonce};

// Cumulus Imports
use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
Expand Down
4 changes: 4 additions & 0 deletions runtimes/eden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ std = [
"sp-io/std",
"sp-offchain/std",
"sp-runtime/std",
"sp-genesis-builder/std",
"sp-storage/std",
"sp-session/std",
"sp-staking/std",
"sp-std/std",
Expand Down Expand Up @@ -224,10 +226,12 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", default-features
sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-staking = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-npos-elections = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-genesis-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0", optional = true }
primitives = { default-features = false, path = "../../primitives" }
pallet-allocations = { default-features = false, path = "../../pallets/allocations" }
Expand Down

0 comments on commit 48048af

Please sign in to comment.