Update develop to patch-polkadot-sdk

Allows us to finally remove the old `serai-dex/substrate` repository _and_
should have CI pass without issue on `develop` again.

The changes made here should be trivial and maintain all prior
behavior/functionality. The most notable are to `chain_spec.rs`, in order to
still use a SCALE-encoded `GenesisConfig` (avoiding `serde_json`).
This commit is contained in:
Luke Parker
2025-09-21 18:21:18 -04:00
parent 52d15b789c
commit 41bb2c7b2a
102 changed files with 4185 additions and 3472 deletions

View File

@@ -10,7 +10,7 @@ use serai_runtime::{
CoinsConfig, ValidatorSetsConfig, SignalsConfig, BabeConfig, GrandpaConfig, EmissionsConfig,
};
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;
pub type ChainSpec = sc_service::GenericChainSpec;
fn account_from_name(name: &'static str) -> PublicKey {
insecure_pair_from_name(name).public()
@@ -28,7 +28,6 @@ fn wasm_binary() -> Vec<u8> {
}
fn devnet_genesis(
wasm_binary: &[u8],
validators: &[&'static str],
endowed_accounts: Vec<PublicKey>,
) -> RuntimeGenesisConfig {
@@ -50,7 +49,7 @@ fn devnet_genesis(
.collect::<Vec<_>>();
RuntimeGenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
system: SystemConfig { _config: PhantomData },
transaction_payment: Default::default(),
@@ -70,7 +69,7 @@ fn devnet_genesis(
signals: SignalsConfig::default(),
babe: BabeConfig {
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
_config: PhantomData,
},
grandpa: GrandpaConfig {
@@ -80,7 +79,7 @@ fn devnet_genesis(
}
}
fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> RuntimeGenesisConfig {
fn testnet_genesis(validators: Vec<&'static str>) -> RuntimeGenesisConfig {
let validators = validators
.into_iter()
.map(|validator| Public::decode(&mut hex::decode(validator).unwrap().as_slice()).unwrap())
@@ -104,7 +103,7 @@ fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> Runtime
assert_eq!(validators.iter().collect::<HashSet<_>>().len(), validators.len());
RuntimeGenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
system: SystemConfig { _config: PhantomData },
transaction_payment: Default::default(),
@@ -124,7 +123,7 @@ fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> Runtime
signals: SignalsConfig::default(),
babe: BabeConfig {
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
_config: PhantomData,
},
grandpa: GrandpaConfig {
@@ -134,114 +133,106 @@ fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> Runtime
}
}
pub fn development_config() -> ChainSpec {
let wasm_binary = wasm_binary();
fn genesis(
name: &'static str,
id: &'static str,
chain_type: ChainType,
protocol_id: &'static str,
config: &RuntimeGenesisConfig,
) -> ChainSpec {
use sp_core::{
Encode,
traits::{RuntimeCode, WrappedRuntimeCode, CodeExecutor},
};
use sp_runtime::BuildStorage;
ChainSpec::from_genesis(
// Name
let bin = wasm_binary();
let hash = sp_core::blake2_256(&bin).to_vec();
let chain_spec = sc_chain_spec::ChainSpecBuilder::new(&bin, None)
.with_name(name)
.with_id(id)
.with_chain_type(chain_type)
.with_protocol_id(protocol_id)
.build();
let mut ext = sp_state_machine::BasicExternalities::new_empty();
let code_fetcher = WrappedRuntimeCode(bin.into());
sc_executor::WasmExecutor::<sp_io::SubstrateHostFunctions>::builder()
.with_allow_missing_host_functions(true)
.build()
.call(
&mut ext,
&RuntimeCode { heap_pages: None, code_fetcher: &code_fetcher, hash },
"GenesisApi_build",
&config.encode(),
sp_core::traits::CallContext::Onchain,
)
.0
.unwrap();
chain_spec.assimilate_storage(&mut ext.into_storages()).unwrap();
chain_spec
}
pub fn development_config() -> ChainSpec {
genesis(
"Development Network",
// ID
"devnet",
ChainType::Development,
move || {
devnet_genesis(
&wasm_binary,
&["Alice"],
vec![
account_from_name("Alice"),
account_from_name("Bob"),
account_from_name("Charlie"),
account_from_name("Dave"),
account_from_name("Eve"),
account_from_name("Ferdie"),
],
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("serai-devnet"),
// Fork ID
None,
// Properties
None,
// Extensions
None,
"serai-devnet",
&devnet_genesis(
&["Alice"],
vec![
account_from_name("Alice"),
account_from_name("Bob"),
account_from_name("Charlie"),
account_from_name("Dave"),
account_from_name("Eve"),
account_from_name("Ferdie"),
],
),
)
}
pub fn local_config() -> ChainSpec {
let wasm_binary = wasm_binary();
ChainSpec::from_genesis(
// Name
genesis(
"Local Test Network",
// ID
"local",
ChainType::Local,
move || {
devnet_genesis(
&wasm_binary,
&["Alice", "Bob", "Charlie", "Dave"],
vec![
account_from_name("Alice"),
account_from_name("Bob"),
account_from_name("Charlie"),
account_from_name("Dave"),
account_from_name("Eve"),
account_from_name("Ferdie"),
],
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("serai-local"),
// Fork ID
None,
// Properties
None,
// Extensions
None,
"serai-local",
&devnet_genesis(
&["Alice", "Bob", "Charlie", "Dave"],
vec![
account_from_name("Alice"),
account_from_name("Bob"),
account_from_name("Charlie"),
account_from_name("Dave"),
account_from_name("Eve"),
account_from_name("Ferdie"),
],
),
)
}
#[allow(clippy::redundant_closure_call)]
pub fn testnet_config() -> ChainSpec {
let wasm_binary = wasm_binary();
ChainSpec::from_genesis(
// Name
"Test Network 2",
// ID
"testnet-2",
genesis(
"Test Network 0",
"testnet-0",
ChainType::Live,
move || {
let _ = testnet_genesis(&wasm_binary, vec![]);
todo!()
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("serai-testnet-2"),
// Fork ID
None,
// Properties
None,
// Extensions
None,
"serai-testnet-0",
&(move || {
let _ = testnet_genesis(vec![]);
todo!("TODO")
})(),
)
}
pub fn bootnode_multiaddrs(id: &str) -> Vec<libp2p::Multiaddr> {
match id {
"devnet" | "local" => vec![],
"testnet-2" => todo!(),
"testnet-0" => todo!("TODO"),
_ => panic!("unrecognized network ID"),
}
}