Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update substrate to v0.9.43 #2957

Closed
wants to merge 15 commits into from
1,611 changes: 900 additions & 711 deletions Cargo.lock

Large diffs are not rendered by default.

224 changes: 112 additions & 112 deletions Cargo.toml

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions gcli/src/keystore/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ impl Key {
}

/// Verify messages
pub fn verify<P>(sig: &[u8], message: &[u8], pubkey: &[u8]) -> Result<bool>
pub fn verify<'a, P>(sig: &'a [u8], message: &[u8], pubkey: &'a [u8]) -> Result<bool>
where
P: Pair,
<P as gsdk::ext::sp_core::Pair>::Signature: TryFrom<&'a [u8]>,
<P as gsdk::ext::sp_core::Pair>::Public: TryFrom<&'a [u8]>,
{
Ok(P::verify_weak(sig, message, pubkey))
let pubkey = P::Public::try_from(pubkey).map_err(|_| Error::InvalidPublic)?;
let sig = P::Signature::try_from(sig).map_err(|_| Error::InvalidSignature)?;
Ok(P::verify(&sig, message, &pubkey))
}
}
2 changes: 2 additions & 0 deletions gcli/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub enum Error {
InvalidPassword,
#[error("Invalid public key")]
InvalidPublic,
#[error("Invalid signature")]
InvalidSignature,
#[error("Invalid secret key")]
InvalidSecret,
#[error(transparent)]
Expand Down
11 changes: 10 additions & 1 deletion gsdk/api-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,20 @@ fn metadata() -> Vec<u8> {
let path = env::var(RUNTIME_WASM).expect("Missing RUNTIME_WASM env var.");
let code = fs::read(path).expect("Failed to read runtime wasm");

let heap_pages =
sc_executor_common::wasm_runtime::HeapAllocStrategy::Static { extra_pages: 1024 };

// 2. Create wasm executor.
let executor = sc_executor::WasmExecutor::<(
gear_ri::gear_ri::HostFunctions,
sp_io::SubstrateHostFunctions,
)>::new(WasmExecutionMethod::Interpreted, Some(1024), 8, None, 2);
)>::builder()
.with_execution_method(WasmExecutionMethod::Interpreted)
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.with_max_runtime_instances(8)
.with_runtime_cache_size(2)
.build();

// 3. Extract metadata.
executor
Expand Down
2 changes: 1 addition & 1 deletion node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ codec = { workspace = true, features = ["derive"] }
futures.workspace = true
futures-timer.workspace = true
hex-literal.workspace = true
jsonrpsee = { workspace = true, features = ["server", "macros"] }
jsonrpsee = { workspace = true, features = ["server"] }
log.workspace = true
serde = { workspace = true, features = ["derive"] }

Expand Down
54 changes: 20 additions & 34 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
use sc_client_api::{Backend as BackendT, BlockBackend, UsageProvider};
use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch};
use sc_executor::NativeExecutionDispatch;
use sc_network::NetworkService;
use sc_network_common::sync::warp::WarpSyncParams;
use sc_network_sync::SyncingService;
Expand Down Expand Up @@ -179,12 +179,6 @@ where
RuntimeApiCollection<StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
ExecutorDispatch: NativeExecutionDispatch + 'static,
{
if config.keystore_remote.is_some() {
return Err(ServiceError::Other(
"Remote Keystores are not supported.".into(),
));
}

let telemetry = config
.telemetry_endpoints
.clone()
Expand All @@ -196,12 +190,7 @@ where
})
.transpose()?;

let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(
config.wasm_method,
config.default_heap_pages,
config.max_runtime_instances,
config.runtime_cache_size,
);
let executor = sc_service::new_native_or_wasm_executor::<ExecutorDispatch>(config);

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
Expand Down Expand Up @@ -243,7 +232,7 @@ where
)?;

let slot_duration = babe_link.config().slot_duration();
let import_queue = sc_consensus_babe::import_queue(
let (import_queue, babe_worker_handle) = sc_consensus_babe::import_queue(
babe_link.clone(),
block_import.clone(),
Some(Box::new(justification_import)),
Expand All @@ -253,10 +242,10 @@ where
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

Ok((slot, timestamp))
},
Expand All @@ -268,7 +257,7 @@ where
let import_setup = (block_import, grandpa_link, babe_link);

let (rpc_extensions_builder, rpc_setup) = {
let (_, grandpa_link, babe_link) = &import_setup;
let (_, grandpa_link, _) = &import_setup;

let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
Expand All @@ -280,13 +269,10 @@ where
Some(shared_authority_set.clone()),
);

let babe_config = babe_link.config().clone();
let shared_epoch_changes = babe_link.epoch_changes().clone();

let client = client.clone();
let pool = transaction_pool.clone();
let select_chain = select_chain.clone();
let keystore = keystore_container.sync_keystore();
let keystore = keystore_container.keystore();
let chain_spec = config.chain_spec.cloned_box();

let rpc_backend = backend.clone();
Expand All @@ -298,9 +284,8 @@ where
chain_spec: chain_spec.cloned_box(),
deny_unsafe,
babe: crate::rpc::BabeDeps {
babe_config: babe_config.clone(),
shared_epoch_changes: shared_epoch_changes.clone(),
keystore: keystore.clone(),
babe_worker_handle: babe_worker_handle.clone(),
},
grandpa: crate::rpc::GrandpaDeps {
shared_voter_state: shared_voter_state.clone(),
Expand Down Expand Up @@ -397,6 +382,7 @@ where
} = new_partial(&config)?;

let shared_voter_state = rpc_setup;
let _auth_disc_publish_non_global_ips = config.network.allow_non_globals_in_dht;
let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name(
&client
.block_hash(0)
Expand Down Expand Up @@ -450,7 +436,7 @@ where
config,
backend,
client: client.clone(),
keystore: keystore_container.sync_keystore(),
keystore: keystore_container.keystore(),
network: network.clone(),
rpc_builder: Box::new(rpc_builder),
transaction_pool: transaction_pool.clone(),
Expand Down Expand Up @@ -495,7 +481,7 @@ where
let client_clone = client.clone();
let slot_duration = babe_link.config().slot_duration();
let babe_config = sc_consensus_babe::BabeParams {
keystore: keystore_container.sync_keystore(),
keystore: keystore_container.keystore(),
client: client.clone(),
select_chain,
env: proposer,
Expand All @@ -508,10 +494,10 @@ where
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot =
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);

let storage_proof =
sp_transaction_storage_proof::registration::new_data_provider(
Expand Down Expand Up @@ -541,14 +527,14 @@ where
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() {
Some(keystore_container.sync_keystore())
Some(keystore_container.keystore())
} else {
None
};

let config = sc_consensus_grandpa::Config {
// FIXME substrate#1578 make this available through chainspec
gossip_duration: std::time::Duration::from_millis(1000),
// FIXME #1578 make this available through chainspec
gossip_duration: std::time::Duration::from_millis(333),
justification_period: 512,
name: Some(name),
observer_enabled: false,
Expand Down
27 changes: 11 additions & 16 deletions node/service/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ use std::sync::Arc;

use jsonrpsee::RpcModule;
use runtime_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index};
use sc_client_api::{AuxStore, BlockBackend, StorageProvider};
use sc_consensus_babe::{BabeConfiguration, Epoch};
use sc_consensus_epochs::SharedEpochChanges;
use sc_client_api::AuxStore;
use sc_consensus_babe::BabeWorkerHandle;
use sc_consensus_grandpa::{
FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
};
Expand All @@ -38,18 +37,16 @@ use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi;
use sp_keystore::SyncCryptoStorePtr;
use sp_keystore::KeystorePtr;

mod runtime_info;

/// Extra dependencies for BABE.
pub struct BabeDeps {
/// BABE protocol config.
pub babe_config: BabeConfiguration,
/// BABE pending epoch changes.
pub shared_epoch_changes: SharedEpochChanges<Block, Epoch>,
/// A handle to the BABE worker for issuing requests.
pub babe_worker_handle: BabeWorkerHandle<Block>,
/// The keystore that manages the keys of the node.
pub keystore: SyncCryptoStorePtr,
pub keystore: KeystorePtr,
}

/// Extra dependencies for GRANDPA
Expand Down Expand Up @@ -91,11 +88,11 @@ pub fn create_full<C, P, SC, B>(
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ BlockBackend<Block>
+ sc_client_api::BlockBackend<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ StorageProvider<Block, B>
+ sc_client_api::StorageProvider<Block, B>
+ Sync
+ Send
+ 'static,
Expand Down Expand Up @@ -133,8 +130,7 @@ where

let BabeDeps {
keystore,
babe_config,
shared_epoch_changes,
babe_worker_handle,
} = babe;
let GrandpaDeps {
shared_voter_state,
Expand All @@ -158,9 +154,8 @@ where
io.merge(
Babe::new(
client.clone(),
shared_epoch_changes.clone(),
babe_worker_handle.clone(),
keystore,
babe_config,
select_chain,
deny_unsafe,
)
Expand All @@ -182,7 +177,7 @@ where
chain_spec,
client.clone(),
shared_authority_set,
shared_epoch_changes,
babe_worker_handle,
)?
.into_rpc(),
)?;
Expand Down
6 changes: 3 additions & 3 deletions pallets/airdrop/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::Pallet as Airdrop;
use crate::*;
use common::{benchmarking, Origin};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use frame_support::traits::Currency;
use frame_support::traits::fungible::{Inspect, Mutate};
use frame_system::RawOrigin;
use sp_runtime::traits::UniqueSaturatedInto;

Expand All @@ -34,14 +34,14 @@ benchmarks! {
let q in 1 .. 256;

let source: T::AccountId = benchmarking::account("source", 0, 0);
<T as pallet_gear::Config>::Currency::deposit_creating(&source, (1u128 << 60).unique_saturated_into());
<T as pallet_gear::Config>::Currency::set_balance(&source, (1u128 << 60).unique_saturated_into());
let recipient: T::AccountId = benchmarking::account("recipient", 0, 0);
// Keeping in mind the existential deposit
let amount = 100_000_u128.saturating_add(10_u128.saturating_mul(q.into()));

}: _(RawOrigin::Root, source, recipient.clone(), amount.unique_saturated_into())
verify {
assert_eq!(pallet_balances::Pallet::<T>::total_balance(&recipient), amount.unique_saturated_into());
assert_eq!(<T as pallet_gear::Config>::Currency::total_balance(&recipient), amount.unique_saturated_into());
}
}

Expand Down
12 changes: 8 additions & 4 deletions pallets/airdrop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

use frame_support::{
pallet_prelude::*,
traits::{Currency, ExistenceRequirement, VestingSchedule},
traits::{
fungible::{Inspect, Mutate},
tokens::Preservation,
Currency, ExistenceRequirement, VestingSchedule,
},
};
pub use pallet::*;
use sp_runtime::traits::{Convert, Saturating};
Expand All @@ -37,7 +41,7 @@ mod mock;
#[cfg(test)]
mod tests;

pub(crate) type BalanceOf<T> = <<T as pallet_gear::Config>::Currency as Currency<
pub(crate) type BalanceOf<T> = <<T as pallet_gear::Config>::Currency as Inspect<
<T as frame_system::Config>::AccountId,
>>::Balance;

Expand Down Expand Up @@ -118,11 +122,11 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;

<<T as pallet_gear::Config>::Currency as Currency<_>>::transfer(
<<T as pallet_gear::Config>::Currency>::transfer(
&source,
&dest,
amount,
ExistenceRequirement::KeepAlive,
Preservation::Protect,
)?;
Self::deposit_event(Event::TokensDeposited {
account: dest,
Expand Down
7 changes: 6 additions & 1 deletion pallets/airdrop/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate as pallet_airdrop;
use frame_support::{
construct_runtime, parameter_types,
traits::{ConstU64, GenesisBuild, WithdrawReasons},
traits::{ConstU32, ConstU64, GenesisBuild, WithdrawReasons},
};
use frame_support_test::TestRandomness;
use frame_system as system;
Expand Down Expand Up @@ -107,6 +107,10 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type HoldIdentifier = RuntimeHoldReason;
type MaxFreezes = ConstU32<100>;
type MaxHolds = ConstU32<100>;
}

impl pallet_sudo::Config for Test {
Expand Down Expand Up @@ -158,6 +162,7 @@ impl pallet_gear::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Randomness = TestRandomness<Self>;
type Currency = Balances;
type RuntimeHoldReason = RuntimeHoldReason;
type GasPrice = GasConverter;
type WeightInfo = ();
type Schedule = GearSchedule;
Expand Down
Loading