Skip to content

Commit

Permalink
Modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Aug 28, 2024
1 parent 97458f8 commit 583f7a0
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 43 deletions.
13 changes: 13 additions & 0 deletions runtime/astar/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
use crate::*;
use astar_primitives::{evm::EVM_REVERT_CODE, genesis::GenesisAccount};

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
let genesis = match id.try_into() {
Ok("development") => default_config(2006),
_ => return None,
};
Some(
serde_json::to_string(&genesis)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}

/// Get the default genesis config for the Astar runtime.
pub fn default_config(para_id: u32) -> serde_json::Value {
let alice = GenesisAccount::<sr25519::Public>::from_seed("Alice");
Expand Down
17 changes: 7 additions & 10 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ use cumulus_primitives_core::AggregateMessageOrigin;
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
genesis_builder_helper::build_state,
parameter_types,
genesis_builder_helper, parameter_types,
traits::{
fungible::{Balanced, Credit},
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, FindAuthor, Get, Imbalance,
Expand Down Expand Up @@ -1954,19 +1953,17 @@ impl_runtime_apis! {
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {

fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config)
genesis_builder_helper::build_state::<RuntimeGenesisConfig>(config)
}

fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
Some(
serde_json::to_string(&genesis_config::default_config(2006))
.expect("serialization to json is expected to work. qed.")
.into_bytes()
)
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, &genesis_config::get_preset)
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
vec![
sp_genesis_builder::PresetId::from("development"),
]
}
}

Expand Down
13 changes: 13 additions & 0 deletions runtime/local/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ use astar_primitives::{
genesis::{get_from_seed, GenesisAccount},
};

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
let genesis = match id.try_into() {
Ok("development") => default_config(),
_ => return None,
};
Some(
serde_json::to_string(&genesis)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}

/// Get the default genesis config for the local runtime.
pub fn default_config() -> serde_json::Value {
let alice = GenesisAccount::<sr25519::Public>::from_seed("Alice");
Expand Down
16 changes: 7 additions & 9 deletions runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use frame_support::{
construct_runtime,
genesis_builder_helper::build_state,
parameter_types,
construct_runtime, genesis_builder_helper, parameter_types,
traits::{
fungible::{Balanced, Credit, HoldConsideration},
tokens::{PayFromAccount, UnityAssetBalanceConversion},
Expand Down Expand Up @@ -1802,17 +1800,17 @@ impl_runtime_apis! {
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {

fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config)
genesis_builder_helper::build_state::<RuntimeGenesisConfig>(config)
}

fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
Some(serde_json::to_string(&genesis_config::default_config())
.expect("serialization to json is expected to work. qed.")
.into_bytes())
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, &genesis_config::get_preset)
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
vec![
sp_genesis_builder::PresetId::from("development"),
]
}
}

Expand Down
13 changes: 13 additions & 0 deletions runtime/shibuya/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
use crate::*;
use astar_primitives::{evm::EVM_REVERT_CODE, genesis::GenesisAccount};

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
let genesis = match id.try_into() {
Ok("development") => default_config(2000),
_ => return None,
};
Some(
serde_json::to_string(&genesis)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}

/// Get the default genesis config for the Shibuya runtime.
pub fn default_config(para_id: u32) -> serde_json::Value {
let alice = GenesisAccount::<sr25519::Public>::from_seed("Alice");
Expand Down
17 changes: 7 additions & 10 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ use cumulus_primitives_core::AggregateMessageOrigin;
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
genesis_builder_helper::build_state,
parameter_types,
genesis_builder_helper, parameter_types,
traits::{
fungible::{Balanced, Credit, HoldConsideration},
tokens::{PayFromAccount, UnityAssetBalanceConversion},
Expand Down Expand Up @@ -2300,19 +2299,17 @@ impl_runtime_apis! {
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {

fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config)
genesis_builder_helper::build_state::<RuntimeGenesisConfig>(config)
}

fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
Some(
serde_json::to_string(&genesis_config::default_config(2000))
.expect("serialization to json is expected to work. qed.")
.into_bytes()
)
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, &genesis_config::get_preset)
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
vec![
sp_genesis_builder::PresetId::from("development"),
]
}
}

Expand Down
21 changes: 17 additions & 4 deletions runtime/shiden/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,31 @@
use crate::*;
use astar_primitives::{evm::EVM_REVERT_CODE, genesis::GenesisAccount};

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
let genesis = match id.try_into() {
Ok("development") => default_config(2007),
_ => return None,
};
Some(
serde_json::to_string(&genesis)
.expect("serialization to json is expected to work. qed.")
.into_bytes(),
)
}

/// Get the default genesis config for the Shiden runtime.
pub fn default_config(para_id: u32) -> serde_json::Value {
// TODO: revisit dApp staking benchmarking logic, something causes the total issuance to saturate, probably need to reduce reward amounts
// UPDATE: the issue seems to be with the omni-bencher-tool. For some reason, no issuance is generated for subsequent runs.
// Reducing steps to `repeats` to 0 or 1 helps, but it's unclear why.

let alice = GenesisAccount::<sr25519::Public>::from_seed("Alice");
let bob = GenesisAccount::<sr25519::Public>::from_seed("Bob");

let balances: Vec<(AccountId, Balance)> = vec![
(alice.account_id(), 1_000_000_000_000 * SDN),
(bob.account_id(), 1_000_000_000_000 * SDN),
(
TreasuryPalletId::get().into_account_truncating(),
1_000_000_000 * SDN,
),
];

let authorities = vec![&alice, &bob];
Expand Down
17 changes: 7 additions & 10 deletions runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ use cumulus_primitives_core::AggregateMessageOrigin;
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
genesis_builder_helper::build_state,
parameter_types,
genesis_builder_helper, parameter_types,
traits::{
fungible::{Balanced, Credit},
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, FindAuthor, Get, Imbalance,
Expand Down Expand Up @@ -1954,19 +1953,17 @@ impl_runtime_apis! {
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {

fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config)
genesis_builder_helper::build_state::<RuntimeGenesisConfig>(config)
}

fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
Some(
serde_json::to_string(&genesis_config::default_config(2007))
.expect("serialization to json is expected to work. qed.")
.into_bytes()
)
fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
genesis_builder_helper::get_preset::<RuntimeGenesisConfig>(id, &genesis_config::get_preset)
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
vec![]
vec![
sp_genesis_builder::PresetId::from("development"),
]
}
}

Expand Down

0 comments on commit 583f7a0

Please sign in to comment.