mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 01:11:10 +00:00
BlockId removal: runtime-api refactor (#13255)
* BlockId removal: refactor of runtime API It changes the arguments of: - `ApiExt` methods: `has_api`, `has_api_with`, `api_version` - `CallApiAt` method: `runtime_version_at` from: `BlockId<Block>` to: `Block::Hash` It also changes the first argument of all generated runtime API calls from: `BlockId<Block>` to: `Block::Hash` This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292) * BlockId removal: refactor of runtime API - tests - tests adjusted to new runtime API, - some tests migrated from block number to block hash * benchmarking-cli: BlockId(0) migrated to info().genesis_hash `runtime_api.call()` now requires the block hash instead of BlockId::Number. To access the genesis hash widely used in benchmarking engine the Client was constrained to satisfy `sp_blockchain::HeaderBackend<Block>` trait which provides `info().genesis_hash`. * trivial: api.call(BlockId) -> api.call(Hash) - Migrated all `runtime_api.calls` to use Hash - Noteworthy (?): -- `validate_transaction_blocking` in transaction pool, * CallApiAtParams::at changed to Block::Hash * missed doc updated * Apply suggestions from code review Co-authored-by: Bastian Köcher <git@kchr.de> * ".git/.scripts/commands/fmt/fmt.sh" * BlockId removal: Benchmark::consumed_weight Little refactor around `Benchmark::consumed_weight`: `BlockId` removed. * at_hash renamed * wrong merge fixed * beefy worker: merged with master * beefy: tests: missing block problem fixed * Apply review suggestion * fix --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
ac13aaeb2f
commit
7a10154188
@@ -1353,7 +1353,6 @@ mod tests {
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_core::storage::well_known_keys::HEAP_PAGES;
|
||||
use sp_runtime::generic::BlockId;
|
||||
use sp_state_machine::ExecutionStrategy;
|
||||
use substrate_test_runtime_client::{
|
||||
prelude::*, runtime::TestAPI, DefaultTestClientBuilderExt, TestClientBuilder,
|
||||
@@ -1368,27 +1367,27 @@ mod tests {
|
||||
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
|
||||
.set_heap_pages(8)
|
||||
.build();
|
||||
let block_id = BlockId::Hash(client.chain_info().best_hash);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
// Try to allocate 1024k of memory on heap. This is going to fail since it is twice larger
|
||||
// than the heap.
|
||||
let ret = client.runtime_api().vec_with_capacity(&block_id, 1048576);
|
||||
let ret = client.runtime_api().vec_with_capacity(best_hash, 1048576);
|
||||
assert!(ret.is_err());
|
||||
|
||||
// Create a block that sets the `:heap_pages` to 32 pages of memory which corresponds to
|
||||
// ~2048k of heap memory.
|
||||
let (new_block_id, block) = {
|
||||
let (new_at_hash, block) = {
|
||||
let mut builder = client.new_block(Default::default()).unwrap();
|
||||
builder.push_storage_change(HEAP_PAGES.to_vec(), Some(32u64.encode())).unwrap();
|
||||
let block = builder.build().unwrap().block;
|
||||
let hash = block.header.hash();
|
||||
(BlockId::Hash(hash), block)
|
||||
(hash, block)
|
||||
};
|
||||
|
||||
futures::executor::block_on(client.import(BlockOrigin::Own, block)).unwrap();
|
||||
|
||||
// Allocation of 1024k while having ~2048k should succeed.
|
||||
let ret = client.runtime_api().vec_with_capacity(&new_block_id, 1048576);
|
||||
let ret = client.runtime_api().vec_with_capacity(new_at_hash, 1048576);
|
||||
assert!(ret.is_ok());
|
||||
}
|
||||
|
||||
@@ -1397,9 +1396,9 @@ mod tests {
|
||||
let client =
|
||||
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Hash(client.chain_info().best_hash);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
runtime_api.test_storage(&block_id).unwrap();
|
||||
runtime_api.test_storage(best_hash).unwrap();
|
||||
}
|
||||
|
||||
fn witness_backend() -> (sp_trie::MemoryDB<crate::Hashing>, crate::Hash) {
|
||||
@@ -1424,8 +1423,8 @@ mod tests {
|
||||
let client =
|
||||
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
|
||||
let runtime_api = client.runtime_api();
|
||||
let block_id = BlockId::Hash(client.chain_info().best_hash);
|
||||
let best_hash = client.chain_info().best_hash;
|
||||
|
||||
runtime_api.test_witness(&block_id, proof, root).unwrap();
|
||||
runtime_api.test_witness(best_hash, proof, root).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user