mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
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:
@@ -29,16 +29,18 @@ schnorrkel = "0.11"
|
||||
|
||||
libp2p = "0.52"
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-keystore = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-timestamp = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-io = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-blockchain = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-api = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-block-builder = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-keystore = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-state-machine = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-blockchain = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/substrate" }
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
serai-runtime = { path = "../runtime", features = ["std"] }
|
||||
|
||||
@@ -46,35 +48,37 @@ clap = { version = "4", features = ["derive"] }
|
||||
|
||||
futures-util = "0.3"
|
||||
tokio = { version = "1", features = ["sync", "rt-multi-thread"] }
|
||||
jsonrpsee = { version = "0.16", features = ["server"] }
|
||||
jsonrpsee = { version = "0.24", features = ["server"] }
|
||||
|
||||
sc-offchain = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-transaction-pool-api = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-executor = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-service = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-client-api = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-network-common = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-network = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-transaction-pool-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-basic-authorship = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-executor = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-service = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-client-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-network-common = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-network = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
sc-consensus = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-consensus-grandpa = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-authority-discovery = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
sc-telemetry = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-cli = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-telemetry = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-chain-spec = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-cli = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
sc-rpc-api = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-rpc-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
sc-rpc = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
substrate-frame-rpc-system = { git = "https://github.com/serai-dex/substrate" }
|
||||
pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/substrate" }
|
||||
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
substrate-frame-rpc-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
serai-env = { path = "../../common/env" }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-build-script-utils = { git = "https://github.com/serai-dex/substrate" }
|
||||
substrate-build-script-utils = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "7f2a8865cd0ded35e1d62fc330915d44dfa3beab" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
@@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use zeroize::Zeroize;
|
||||
|
||||
use sp_core::{crypto::*, ed25519, sr25519};
|
||||
use sp_core::{crypto::*, sr25519};
|
||||
use sp_keystore::*;
|
||||
|
||||
pub struct Keystore(sr25519::Pair);
|
||||
@@ -58,36 +58,19 @@ impl sp_keystore::Keystore for Keystore {
|
||||
}
|
||||
}
|
||||
|
||||
fn sr25519_vrf_output(
|
||||
fn sr25519_vrf_pre_output(
|
||||
&self,
|
||||
_: KeyTypeId,
|
||||
public: &sr25519::Public,
|
||||
input: &sr25519::vrf::VrfInput,
|
||||
) -> Result<Option<sr25519::vrf::VrfOutput>, Error> {
|
||||
) -> Result<Option<sr25519::vrf::VrfPreOutput>, Error> {
|
||||
if public == &self.0.public() {
|
||||
Ok(Some(self.0.vrf_output(input)))
|
||||
Ok(Some(self.0.vrf_pre_output(input)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn ed25519_public_keys(&self, _: KeyTypeId) -> Vec<ed25519::Public> {
|
||||
panic!("asked for ed25519 keys");
|
||||
}
|
||||
|
||||
fn ed25519_generate_new(&self, _: KeyTypeId, _: Option<&str>) -> Result<ed25519::Public, Error> {
|
||||
panic!("asked to generate an ed25519 key");
|
||||
}
|
||||
|
||||
fn ed25519_sign(
|
||||
&self,
|
||||
_: KeyTypeId,
|
||||
_: &ed25519::Public,
|
||||
_: &[u8],
|
||||
) -> Result<Option<ed25519::Signature>, Error> {
|
||||
panic!("asked to produce an ed25519 signature");
|
||||
}
|
||||
|
||||
fn insert(&self, _: KeyTypeId, _: &str, _: &[u8]) -> Result<(), ()> {
|
||||
panic!("asked to insert a key");
|
||||
}
|
||||
|
||||
@@ -15,14 +15,12 @@ use tokio::sync::RwLock;
|
||||
|
||||
use jsonrpsee::RpcModule;
|
||||
|
||||
pub use sc_rpc_api::DenyUnsafe;
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
|
||||
pub struct FullDeps<C, P> {
|
||||
pub id: String,
|
||||
pub client: Arc<C>,
|
||||
pub pool: Arc<P>,
|
||||
pub deny_unsafe: DenyUnsafe,
|
||||
pub authority_discovery: Option<sc_authority_discovery::Service>,
|
||||
}
|
||||
|
||||
@@ -38,7 +36,7 @@ pub fn create_full<
|
||||
deps: FullDeps<C, P>,
|
||||
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
|
||||
where
|
||||
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, PublicKey, Nonce>
|
||||
C::Api: frame_system_rpc_runtime_api::AccountNonceApi<Block, PublicKey, Nonce>
|
||||
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, SubstrateAmount>
|
||||
+ SeraiRuntimeApi<Block>
|
||||
+ BlockBuilder<Block>,
|
||||
@@ -47,9 +45,9 @@ where
|
||||
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
|
||||
|
||||
let mut module = RpcModule::new(());
|
||||
let FullDeps { id, client, pool, deny_unsafe, authority_discovery } = deps;
|
||||
let FullDeps { id, client, pool, authority_discovery } = deps;
|
||||
|
||||
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
|
||||
module.merge(System::new(client.clone(), pool).into_rpc())?;
|
||||
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
|
||||
|
||||
if let Some(authority_discovery) = authority_discovery {
|
||||
@@ -57,17 +55,25 @@ where
|
||||
RpcModule::new((id, client, RwLock::new(authority_discovery)));
|
||||
authority_discovery_module.register_async_method(
|
||||
"p2p_validators",
|
||||
|params, context| async move {
|
||||
|params, context, _ext| async move {
|
||||
let network: NetworkId = params.parse()?;
|
||||
let (id, client, authority_discovery) = &*context;
|
||||
let latest_block = client.info().best_hash;
|
||||
|
||||
let validators = client.runtime_api().validators(latest_block, network).map_err(|_| {
|
||||
jsonrpsee::core::Error::to_call_error(std::io::Error::other(format!(
|
||||
"couldn't get validators from the latest block, which is likely a fatal bug. {}",
|
||||
"please report this at https://github.com/serai-dex/serai",
|
||||
)))
|
||||
})?;
|
||||
jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||
-1,
|
||||
format!(
|
||||
"couldn't get validators from the latest block, which is likely a fatal bug. {}",
|
||||
"please report this at https://github.com/serai-dex/serai",
|
||||
),
|
||||
Option::<()>::None,
|
||||
)
|
||||
});
|
||||
let validators = match validators {
|
||||
Ok(validators) => validators,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
// Always return the protocol's bootnodes
|
||||
let mut all_p2p_addresses = crate::chain_spec::bootnode_multiaddrs(id);
|
||||
// Additionally returns validators found over the DHT
|
||||
@@ -87,9 +93,9 @@ where
|
||||
// It isn't beneficial to use multiple addresses for a single peer here
|
||||
if !returned_addresses.is_empty() {
|
||||
all_p2p_addresses.push(
|
||||
returned_addresses.remove(
|
||||
usize::try_from(OsRng.next_u64() >> 32).unwrap() % returned_addresses.len(),
|
||||
),
|
||||
returned_addresses
|
||||
.remove(usize::try_from(OsRng.next_u64() >> 32).unwrap() % returned_addresses.len())
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,11 @@ use sp_consensus_babe::{SlotDuration, inherents::InherentDataProvider as BabeInh
|
||||
use sp_io::SubstrateHostFunctions;
|
||||
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, WasmExecutor};
|
||||
|
||||
use sc_network_common::sync::warp::WarpSyncParams;
|
||||
use sc_network::{Event, NetworkEventStream};
|
||||
use sc_network::{Event, NetworkEventStream, NetworkBackend};
|
||||
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, TFullClient};
|
||||
|
||||
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
|
||||
use sc_client_api::{BlockBackend, Backend};
|
||||
use sc_client_api::BlockBackend;
|
||||
|
||||
use sc_telemetry::{Telemetry, TelemetryWorker};
|
||||
|
||||
@@ -40,8 +39,8 @@ type PartialComponents = sc_service::PartialComponents<
|
||||
FullClient,
|
||||
FullBackend,
|
||||
SelectChain,
|
||||
sc_consensus::DefaultImportQueue<Block, FullClient>,
|
||||
sc_transaction_pool::FullPool<Block, FullClient>,
|
||||
sc_consensus::DefaultImportQueue<Block>,
|
||||
sc_transaction_pool::TransactionPoolWrapper<Block, FullClient>,
|
||||
(
|
||||
BabeBlockImport,
|
||||
sc_consensus_babe::BabeLink<Block>,
|
||||
@@ -74,11 +73,11 @@ pub fn new_partial(
|
||||
|
||||
#[allow(deprecated)]
|
||||
let executor = Executor::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
config.max_runtime_instances,
|
||||
config.executor.wasm_method,
|
||||
config.executor.default_heap_pages,
|
||||
config.executor.max_runtime_instances,
|
||||
None,
|
||||
config.runtime_cache_size,
|
||||
config.executor.runtime_cache_size,
|
||||
);
|
||||
|
||||
let (client, backend, keystore_container, task_manager) =
|
||||
@@ -103,16 +102,19 @@ pub fn new_partial(
|
||||
|
||||
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
||||
|
||||
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
|
||||
config.transaction_pool.clone(),
|
||||
config.role.is_authority().into(),
|
||||
config.prometheus_registry(),
|
||||
let transaction_pool = sc_transaction_pool::Builder::new(
|
||||
task_manager.spawn_essential_handle(),
|
||||
client.clone(),
|
||||
);
|
||||
config.role.is_authority().into(),
|
||||
)
|
||||
.with_options(config.transaction_pool.clone())
|
||||
.with_prometheus(config.prometheus_registry())
|
||||
.build();
|
||||
let transaction_pool = Arc::new(transaction_pool);
|
||||
|
||||
let (grandpa_block_import, grandpa_link) = grandpa::block_import(
|
||||
client.clone(),
|
||||
u32::MAX,
|
||||
&client,
|
||||
select_chain.clone(),
|
||||
telemetry.as_ref().map(Telemetry::handle),
|
||||
@@ -181,22 +183,26 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
config.network.listen_addresses =
|
||||
vec!["/ip4/0.0.0.0/tcp/30333".parse().unwrap(), "/ip6/::/tcp/30333".parse().unwrap()];
|
||||
|
||||
let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
|
||||
type N = sc_network::service::NetworkWorker<Block, <Block as sp_runtime::traits::Block>::Hash>;
|
||||
let mut net_config = sc_network::config::FullNetworkConfiguration::<_, _, N>::new(
|
||||
&config.network,
|
||||
config.prometheus_registry().cloned(),
|
||||
);
|
||||
let metrics = N::register_notification_metrics(config.prometheus_registry());
|
||||
|
||||
let grandpa_protocol_name =
|
||||
grandpa::protocol_standard_name(&client.block_hash(0).unwrap().unwrap(), &config.chain_spec);
|
||||
net_config.add_notification_protocol(sc_consensus_grandpa::grandpa_peers_set_config(
|
||||
grandpa_protocol_name.clone(),
|
||||
));
|
||||
let (grandpa_protocol_config, grandpa_notification_service) =
|
||||
sc_consensus_grandpa::grandpa_peers_set_config::<Block, N>(
|
||||
grandpa_protocol_name.clone(),
|
||||
metrics.clone(),
|
||||
net_config.peer_store_handle(),
|
||||
);
|
||||
net_config.add_notification_protocol(grandpa_protocol_config);
|
||||
|
||||
let publish_non_global_ips = config.network.allow_non_globals_in_dht;
|
||||
|
||||
let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new(
|
||||
backend.clone(),
|
||||
grandpa_link.shared_authority_set().clone(),
|
||||
vec![],
|
||||
));
|
||||
|
||||
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
|
||||
let (network, system_rpc_tx, tx_handler_controller, sync_service) =
|
||||
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||
config: &config,
|
||||
net_config,
|
||||
@@ -205,7 +211,9 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
import_queue,
|
||||
block_announce_validator_builder: None,
|
||||
warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
|
||||
metrics,
|
||||
block_relay: None,
|
||||
warp_sync_config: None,
|
||||
})?;
|
||||
|
||||
task_manager.spawn_handle().spawn("bootnodes", "bootnodes", {
|
||||
@@ -233,7 +241,10 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
.multiplex(libp2p::yamux::Config::default());
|
||||
let Ok(transport) = transport.dial(multiaddr.clone()) else { None? };
|
||||
let Ok((peer_id, _)) = transport.await else { None? };
|
||||
Some(sc_network::config::MultiaddrWithPeerId { multiaddr, peer_id })
|
||||
Some(sc_network::config::MultiaddrWithPeerId {
|
||||
multiaddr: multiaddr.into(),
|
||||
peer_id: peer_id.into(),
|
||||
})
|
||||
}),
|
||||
));
|
||||
}
|
||||
@@ -261,25 +272,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
}
|
||||
});
|
||||
|
||||
if config.offchain_worker.enabled {
|
||||
task_manager.spawn_handle().spawn(
|
||||
"offchain-workers-runner",
|
||||
"offchain-worker",
|
||||
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
|
||||
runtime_api_provider: client.clone(),
|
||||
is_validator: config.role.is_authority(),
|
||||
keystore: Some(keystore_container.clone()),
|
||||
offchain_db: backend.offchain_storage(),
|
||||
transaction_pool: Some(OffchainTransactionPoolFactory::new(transaction_pool.clone())),
|
||||
network_provider: network.clone(),
|
||||
enable_http_requests: true,
|
||||
custom_extensions: |_| vec![],
|
||||
})
|
||||
.run(client.clone(), task_manager.spawn_handle()),
|
||||
);
|
||||
}
|
||||
|
||||
let role = config.role.clone();
|
||||
let role = config.role;
|
||||
let keystore = keystore_container;
|
||||
let prometheus_registry = config.prometheus_registry().cloned();
|
||||
|
||||
@@ -294,7 +287,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
worker
|
||||
},
|
||||
client.clone(),
|
||||
network.clone(),
|
||||
Arc::new(network.clone()),
|
||||
Box::pin(network.event_stream("authority-discovery").filter_map(|e| async move {
|
||||
match e {
|
||||
Event::Dht(e) => Some(e),
|
||||
@@ -303,6 +296,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
})),
|
||||
sc_authority_discovery::Role::PublishAndDiscover(keystore.clone()),
|
||||
prometheus_registry.clone(),
|
||||
task_manager.spawn_handle(),
|
||||
);
|
||||
task_manager.spawn_handle().spawn(
|
||||
"authority-discovery-worker",
|
||||
@@ -320,12 +314,11 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
let client = client.clone();
|
||||
let pool = transaction_pool.clone();
|
||||
|
||||
Box::new(move |deny_unsafe, _| {
|
||||
Box::new(move |_| {
|
||||
crate::rpc::create_full(crate::rpc::FullDeps {
|
||||
id: id.clone(),
|
||||
client: client.clone(),
|
||||
pool: pool.clone(),
|
||||
deny_unsafe,
|
||||
authority_discovery: authority_discovery.clone(),
|
||||
})
|
||||
.map_err(Into::into)
|
||||
@@ -392,7 +385,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
grandpa::run_grandpa_voter(grandpa::GrandpaParams {
|
||||
config: grandpa::Config {
|
||||
gossip_duration: std::time::Duration::from_millis(333),
|
||||
justification_period: 512,
|
||||
justification_generation_period: 512,
|
||||
name: Some(name),
|
||||
observer_enabled: false,
|
||||
keystore: if role.is_authority() { Some(keystore) } else { None },
|
||||
@@ -408,10 +401,10 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
prometheus_registry,
|
||||
shared_voter_state,
|
||||
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool),
|
||||
notification_service: grandpa_notification_service,
|
||||
})?,
|
||||
);
|
||||
}
|
||||
|
||||
network_starter.start_network();
|
||||
Ok(task_manager)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user