mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 01:38:32 +00:00
## Polkadot upgrade 2503 In this PR, we upgrade form Polkadot SDK 2412 to Polkadot SDK 2503. In order to upgrade the SDK we need to upgrade some dependencies : StorageHub and frontier simultaneously. ## What changes ### Trivial changes * https://github.com/paritytech/polkadot-sdk/pull/7634 -> The new trait is required in all the pallets using scale encoding. * https://github.com/paritytech/polkadot-sdk/pull/7043 -> Remove deprecated `sp-std` and replace with `alloc` or `core`. * https://github.com/paritytech/polkadot-sdk/pull/6140 -> Accurate weight reclaim with frame_system::WeightReclaim ### Breaking changes * https://github.com/paritytech/polkadot-sdk/pull/2072 -> There is a change in `pallet-referenda`. Now, the tracks are retrieved as a list of `Track`s. Also, the names of the tracks might have some trailing null values (`\0`). This means display representation of the tracks' names must be sanitized. * https://github.com/paritytech/polkadot-sdk/pull/5723 -> adds the ability for these pallets to specify their source of the block number. This is useful when these pallets are migrated from the relay chain to a parachain and vice versa. (Not entirely sure it is breaking as it is being marked as backward compatible). * https://github.com/paritytech/polkadot-sdk/pull/6338 -> Update Referenda to Support Block Number Provider ### Notable changes * https://github.com/paritytech/polkadot-sdk/pull/5703 -> Not changes required in the codebase but impact fastSync mode. Should improve testing. * https://github.com/paritytech/polkadot-sdk/pull/5842 -> Removes `libp2p` types in authority-discovery, and replace them with network backend agnostic types from `sc-network-types`. The `sc-network` interface is therefore updated accordingly. ## What changes in Frontier * https://github.com/polkadot-evm/frontier/pull/1693 -> Add support for EIP 7702 which has been enable with Pectra. This EIP add a new field `AuthorizationList` in Ethereum transaction. Changes example : ```rust #[test] fn validate_transaction_fails_on_filtered_call() { ... pallet_evm::Call::<Runtime>::call { source: H160::default(), target: H160::default(), input: Vec::new(), value: sp_core::U256::zero(), gas_limit: 21000, max_fee_per_gas: sp_core::U256::zero(), max_priority_fee_per_gas: Some(sp_core::U256::zero()), nonce: None, access_list: Vec::new(), authorization_list: Vec::new(), } .into(), ``` ## ⚠️ Breaking Changes ⚠️ * Upgrade to Stirage hub v0.5.1 * Support for Ethereum latest upgrade (txs now have the `authoriation_list` for support EIP 7702) --------- Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
299 lines
10 KiB
Rust
299 lines
10 KiB
Rust
// Copyright 2025 DataHaven
|
|
// This file is part of DataHaven.
|
|
|
|
// DataHaven is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// DataHaven is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with DataHaven. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use crate::{
|
|
configs::BABE_GENESIS_EPOCH_CONFIG, AccountId, BalancesConfig, EVMConfig, Precompiles,
|
|
RuntimeGenesisConfig, SessionKeys, Signature, SudoConfig, TechnicalCommitteeConfig,
|
|
TreasuryCouncilConfig,
|
|
};
|
|
use alloc::{format, vec, vec::Vec};
|
|
use fp_evm::GenesisAccount;
|
|
use hex_literal::hex;
|
|
use pallet_external_validator_slashes::SlashingModeOption;
|
|
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
|
|
use serde_json::Value;
|
|
use sp_consensus_babe::AuthorityId as BabeId;
|
|
use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId;
|
|
use sp_consensus_grandpa::AuthorityId as GrandpaId;
|
|
use sp_core::{ecdsa, Pair, Public};
|
|
use sp_genesis_builder::{self, PresetId};
|
|
use sp_runtime::traits::{IdentifyAccount, Verify};
|
|
|
|
const TESTNET_EVM_CHAIN_ID: u64 = 55931;
|
|
|
|
// Returns the genesis config presets populated with given parameters.
|
|
fn testnet_genesis(
|
|
initial_authorities: Vec<(AccountId, BabeId, GrandpaId, ImOnlineId, BeefyId)>,
|
|
root_key: AccountId,
|
|
endowed_accounts: Vec<AccountId>,
|
|
treasury_council_members: Vec<AccountId>,
|
|
technical_committee_members: Vec<AccountId>,
|
|
evm_chain_id: u64,
|
|
) -> Value {
|
|
// This is the simplest bytecode to revert without returning any data.
|
|
// We will pre-deploy it under all of our precompiles to ensure they can be called from
|
|
// within contracts.
|
|
// (PUSH1 0x00 PUSH1 0x00 REVERT)
|
|
let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD];
|
|
|
|
let config = RuntimeGenesisConfig {
|
|
balances: BalancesConfig {
|
|
balances: endowed_accounts
|
|
.iter()
|
|
.cloned()
|
|
.map(|k| (k, 1u128 << 80))
|
|
.collect::<Vec<_>>(),
|
|
dev_accounts: Default::default(),
|
|
},
|
|
babe: pallet_babe::GenesisConfig {
|
|
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
|
|
..Default::default()
|
|
},
|
|
evm: EVMConfig {
|
|
// We need _some_ code inserted at the precompile address so that
|
|
// the evm will actually call the address.
|
|
accounts: Precompiles::used_addresses()
|
|
.map(|addr| {
|
|
(
|
|
addr.into(),
|
|
GenesisAccount {
|
|
nonce: Default::default(),
|
|
balance: Default::default(),
|
|
storage: Default::default(),
|
|
code: revert_bytecode.clone(),
|
|
},
|
|
)
|
|
})
|
|
.collect(),
|
|
..Default::default()
|
|
},
|
|
evm_chain_id: pallet_evm_chain_id::GenesisConfig {
|
|
chain_id: evm_chain_id,
|
|
..Default::default()
|
|
},
|
|
session: pallet_session::GenesisConfig {
|
|
keys: initial_authorities
|
|
.iter()
|
|
.map(|(account, babe, grandpa, im_online, beefy)| {
|
|
(
|
|
*account,
|
|
*account,
|
|
session_keys(
|
|
babe.clone(),
|
|
grandpa.clone(),
|
|
im_online.clone(),
|
|
beefy.clone(),
|
|
),
|
|
)
|
|
})
|
|
.collect::<Vec<_>>(),
|
|
..Default::default()
|
|
},
|
|
sudo: SudoConfig {
|
|
key: Some(root_key),
|
|
},
|
|
external_validators: pallet_external_validators::GenesisConfig {
|
|
skip_external_validators: false,
|
|
whitelisted_validators: vec![],
|
|
external_validators: initial_authorities
|
|
.iter()
|
|
.map(|(account, ..)| *account)
|
|
.collect::<Vec<_>>()
|
|
.try_into()
|
|
.expect("Too many initial authorities"),
|
|
},
|
|
// Governance pallets configuration
|
|
technical_committee: TechnicalCommitteeConfig {
|
|
phantom: Default::default(),
|
|
members: technical_committee_members,
|
|
},
|
|
treasury_council: TreasuryCouncilConfig {
|
|
phantom: Default::default(),
|
|
members: treasury_council_members,
|
|
},
|
|
external_validators_slashes: pallet_external_validator_slashes::GenesisConfig {
|
|
slashing_mode: SlashingModeOption::Disabled,
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
};
|
|
|
|
serde_json::to_value(config).expect("Could not build genesis config.")
|
|
}
|
|
|
|
/// Return the development genesis config.
|
|
pub fn development_config_genesis() -> Value {
|
|
let mut endowed_accounts = pre_funded_accounts();
|
|
endowed_accounts.sort();
|
|
|
|
testnet_genesis(
|
|
// Alice is the only authority in Dev mode
|
|
vec![authority_keys_from_seed("Alice")],
|
|
// Alith is Sudo
|
|
alith(),
|
|
// Endowed: Alice, Bob, Charlie, Dave, Eve, Ferdie,
|
|
// Alith, Baltathar, Charleth, Dorothy, Ethan, Frank,
|
|
// Beacon relayer account
|
|
endowed_accounts,
|
|
// Treasury Council members: Baltathar, Charleth and Dorothy
|
|
vec![baltathar(), charleth(), dorothy()],
|
|
// Technical committee members: Alith and Baltathar
|
|
vec![alith(), baltathar()],
|
|
TESTNET_EVM_CHAIN_ID,
|
|
)
|
|
}
|
|
|
|
/// Return the local genesis config preset.
|
|
pub fn local_config_genesis() -> Value {
|
|
let mut endowed_accounts = pre_funded_accounts();
|
|
endowed_accounts.sort();
|
|
|
|
testnet_genesis(
|
|
// Alice, Bob, Charlie, Dave, Eve and Ferdie are authorities in Local mode
|
|
vec![
|
|
authority_keys_from_seed("Alice"),
|
|
authority_keys_from_seed("Bob"),
|
|
authority_keys_from_seed("Charlie"),
|
|
authority_keys_from_seed("Dave"),
|
|
authority_keys_from_seed("Eve"),
|
|
authority_keys_from_seed("Ferdie"),
|
|
],
|
|
// Alith is Sudo
|
|
alith(),
|
|
// Endowed: Alice, Bob, Charlie, Dave, Eve, Ferdie,
|
|
// Alith, Baltathar, Charleth, Dorothy, Ethan, Frank,
|
|
// Beacon relayer account
|
|
endowed_accounts,
|
|
// Treasury Council members: Baltathar, Charleth and Dorothy
|
|
vec![baltathar(), charleth(), dorothy()],
|
|
// Technical committee members: Alith and Baltathar
|
|
vec![alith(), baltathar()],
|
|
TESTNET_EVM_CHAIN_ID,
|
|
)
|
|
}
|
|
|
|
/// Provides the JSON representation of predefined genesis config for given `id`.
|
|
pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> {
|
|
let patch = match id.as_str() {
|
|
sp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(),
|
|
sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_config_genesis(),
|
|
_ => return None,
|
|
};
|
|
Some(
|
|
serde_json::to_string(&patch)
|
|
.expect("serialization to json is expected to work. qed.")
|
|
.into_bytes(),
|
|
)
|
|
}
|
|
|
|
/// List of supported presets.
|
|
pub fn preset_names() -> Vec<PresetId> {
|
|
vec![
|
|
PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET),
|
|
PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET),
|
|
]
|
|
}
|
|
|
|
/// Generate a crypto pair from seed.
|
|
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
|
|
TPublic::Pair::from_string(&format!("//{}", seed), None)
|
|
.expect("static values are valid; qed")
|
|
.public()
|
|
}
|
|
|
|
fn session_keys(
|
|
babe: BabeId,
|
|
grandpa: GrandpaId,
|
|
im_online: ImOnlineId,
|
|
beefy: BeefyId,
|
|
) -> SessionKeys {
|
|
SessionKeys {
|
|
babe,
|
|
grandpa,
|
|
im_online,
|
|
beefy,
|
|
}
|
|
}
|
|
|
|
type AccountPublic = <Signature as Verify>::Signer;
|
|
|
|
/// Generate an account ID from seed.
|
|
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
|
|
where
|
|
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
|
|
{
|
|
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
|
|
}
|
|
|
|
/// Generate a Babe authority key.
|
|
pub fn authority_keys_from_seed(s: &str) -> (AccountId, BabeId, GrandpaId, ImOnlineId, BeefyId) {
|
|
(
|
|
get_account_id_from_seed::<ecdsa::Public>(s),
|
|
get_from_seed::<BabeId>(s),
|
|
get_from_seed::<GrandpaId>(s),
|
|
get_from_seed::<ImOnlineId>(s),
|
|
get_from_seed::<BeefyId>(s),
|
|
)
|
|
}
|
|
|
|
pub fn alith() -> AccountId {
|
|
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"))
|
|
}
|
|
|
|
pub fn baltathar() -> AccountId {
|
|
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0"))
|
|
}
|
|
|
|
pub fn charleth() -> AccountId {
|
|
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc"))
|
|
}
|
|
|
|
pub fn dorothy() -> AccountId {
|
|
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9"))
|
|
}
|
|
|
|
pub fn ethan() -> AccountId {
|
|
AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB"))
|
|
}
|
|
|
|
pub fn frank() -> AccountId {
|
|
AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d"))
|
|
}
|
|
|
|
pub fn beacon_relayer() -> AccountId {
|
|
AccountId::from(hex!("c46e141b5083721ad5f5056ba1cded69dce4a65f"))
|
|
}
|
|
|
|
/// Get pre-funded accounts
|
|
pub fn pre_funded_accounts() -> Vec<AccountId> {
|
|
// These addresses are derived from Substrate's canonical mnemonic:
|
|
// bottom drive obey lake curtain smoke basket hold race lonely fit walk
|
|
vec![
|
|
get_account_id_from_seed::<ecdsa::Public>("Alice"),
|
|
get_account_id_from_seed::<ecdsa::Public>("Bob"),
|
|
get_account_id_from_seed::<ecdsa::Public>("Charlie"),
|
|
get_account_id_from_seed::<ecdsa::Public>("Dave"),
|
|
get_account_id_from_seed::<ecdsa::Public>("Eve"),
|
|
get_account_id_from_seed::<ecdsa::Public>("Ferdie"),
|
|
alith(),
|
|
baltathar(),
|
|
charleth(),
|
|
dorothy(),
|
|
ethan(),
|
|
frank(),
|
|
beacon_relayer(),
|
|
]
|
|
}
|