Skip to content

Commit

Permalink
feat: Update substrate to v0.9.43 (#3584)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitry Novikov <[email protected]>
  • Loading branch information
ukint-vs and breathx authored Dec 14, 2023
1 parent 602d0dc commit 2d05b44
Show file tree
Hide file tree
Showing 45 changed files with 3,234 additions and 2,514 deletions.
4,307 changes: 2,354 additions & 1,953 deletions Cargo.lock

Large diffs are not rendered by default.

237 changes: 119 additions & 118 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
8 changes: 6 additions & 2 deletions gcli/tests/cmd/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::common::{
Args, Result,
};

// ExtraFlags is hardcoded
// const IS_NEW_LOGIC: u128 = 0x80000000_00000000_00000000_00000000u128;
const EXPECTED_BALANCE: &str = r#"
AccountInfo {
nonce: 0,
Expand All @@ -32,8 +34,10 @@ AccountInfo {
data: AccountData {
free: 1000000000000000000,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
frozen: 0,
flags: ExtraFlags(
170141183460469231731687303715884105728,
),
},
}
"#;
Expand Down
57 changes: 26 additions & 31 deletions gclient/src/api/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use gsdk::{
event::{CodeChangeKind, MessageEntry},
ActiveProgram,
},
pallet_balances::{pallet::Call as BalancesCall, AccountData},
pallet_balances::{pallet::Call as BalancesCall, types::AccountData},
pallet_gear::pallet::Call as GearCall,
pallet_gear_bank::pallet::BankAccount,
sp_weights::weight_v2::Weight,
Expand Down Expand Up @@ -289,8 +289,10 @@ impl GearApi {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
frozen: 0,
flags: gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(
170141183460469231731687303715884105728,
),
})
} else {
Err(e)
Expand All @@ -316,8 +318,10 @@ impl GearApi {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
frozen: 0,
flags: gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(
170141183460469231731687303715884105728,
),
})
} else {
Err(e)
Expand Down Expand Up @@ -378,19 +382,14 @@ impl GearApi {

// Apply data to the target program
dest_node_api
.set_balance(
.force_set_balance(
dest_program_id.into_account_id(),
src_program_account_data.free,
src_program_account_data.reserved,
)
.await?;

dest_node_api
.set_balance(
crate::bank_address(),
src_bank_account_data.free,
src_bank_account_data.reserved,
)
.force_set_balance(crate::bank_address(), src_bank_account_data.free)
.await?;

dest_node_api
Expand Down Expand Up @@ -421,9 +420,6 @@ impl GearApi {
.await?;

for account_with_reserved_funds in accounts_with_reserved_funds {
let src_account_data = self
.account_data_at(account_with_reserved_funds, src_block_hash)
.await?;
let src_account_bank_data = self
.bank_data_at(account_with_reserved_funds, src_block_hash)
.await
Expand All @@ -443,8 +439,11 @@ impl GearApi {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
frozen: 0,
flags:
gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(
170141183460469231731687303715884105728,
),
})
} else {
Err(e)
Expand All @@ -462,12 +461,9 @@ impl GearApi {
})?;

dest_node_api
.set_balance(
.force_set_balance(
account_with_reserved_funds.into_account_id(),
dest_account_data.free,
dest_account_data
.reserved
.saturating_add(src_account_data.reserved),
)
.await?;

Expand Down Expand Up @@ -565,8 +561,11 @@ impl GearApi {
Ok(AccountData {
free: 0u128,
reserved: 0,
misc_frozen: 0,
fee_frozen: 0,
frozen: 0,
flags:
gsdk::metadata::runtime_types::pallet_balances::types::ExtraFlags(
170141183460469231731687303715884105728,
),
})
} else {
Err(e)
Expand Down Expand Up @@ -597,10 +596,9 @@ impl GearApi {
.map(|(page_number, page_data)| (page_number.raw(), page_data.encode()))
.collect::<HashMap<_, _>>();

self.set_balance(
self.force_set_balance(
MultiAddress::Id(program_id.into_account_id()),
memory_dump.balance,
memory_dump.reserved_balance,
)
.await?;

Expand Down Expand Up @@ -1302,24 +1300,21 @@ impl GearApi {
self.set_code_without_checks(code).await
}

/// Set the free and reserved balance of the `to` account to `new_free` and
/// `new_reserved` respectively.
/// Set the free balance of the `to` account to `new_free`.
///
/// Sends the [`pallet_balances::set_balance`](https://crates.parity.io/pallet_balances/pallet/struct.Pallet.html#method.set_balance) extrinsic.
pub async fn set_balance(
pub async fn force_set_balance(
&self,
to: impl Into<MultiAddress<AccountId32, ()>>,
new_free: u128,
new_reserved: u128,
) -> Result<H256> {
let events = self
.0
.calls
.sudo_unchecked_weight(
RuntimeCall::Balances(BalancesCall::set_balance {
RuntimeCall::Balances(BalancesCall::force_set_balance {
who: to.into().convert(),
new_free,
new_reserved,
}),
Weight {
ref_time: 0,
Expand Down
2 changes: 1 addition & 1 deletion gclient/src/api/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use gsdk::{
ext::sp_core::{crypto::Ss58Codec, H256},
metadata::runtime_types::{
gear_common::storage::primitives::Interval, gear_core::message::user,
pallet_balances::AccountData, pallet_gear_bank::pallet::BankAccount,
pallet_balances::types::AccountData, pallet_gear_bank::pallet::BankAccount,
},
};

Expand Down
15 changes: 13 additions & 2 deletions gsdk/api-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,29 @@ fn main() -> Result<()> {
/// Get the metadata of vara runtime.
fn metadata() -> Vec<u8> {
use gear_runtime_interface as gear_ri;
use sc_executor::WasmExecutionMethod;
use sc_executor::{WasmExecutionMethod, WasmtimeInstantiationStrategy};
use sc_executor_common::runtime_blob::RuntimeBlob;

// 1. Get the wasm binary of `RUNTIME_WASM`.
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::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
})
.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
Loading

0 comments on commit 2d05b44

Please sign in to comment.