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:
Michal Kucharczyk
2023-02-20 23:47:21 +01:00
committed by GitHub
parent ac13aaeb2f
commit 7a10154188
52 changed files with 321 additions and 391 deletions
@@ -291,20 +291,14 @@ fn client_initializes_from_genesis_ok() {
assert_eq!(
client
.runtime_api()
.balance_of(
&BlockId::Number(client.chain_info().best_number),
AccountKeyring::Alice.into(),
)
.balance_of(client.chain_info().best_hash, AccountKeyring::Alice.into())
.unwrap(),
1000
);
assert_eq!(
client
.runtime_api()
.balance_of(
&BlockId::Number(client.chain_info().best_number),
AccountKeyring::Ferdie.into(),
)
.balance_of(client.chain_info().best_hash, AccountKeyring::Ferdie.into())
.unwrap(),
0
);
@@ -351,20 +345,14 @@ fn block_builder_works_with_transactions() {
assert_eq!(
client
.runtime_api()
.balance_of(
&BlockId::Number(client.chain_info().best_number),
AccountKeyring::Alice.into(),
)
.balance_of(client.chain_info().best_hash, AccountKeyring::Alice.into())
.unwrap(),
958
);
assert_eq!(
client
.runtime_api()
.balance_of(
&BlockId::Number(client.chain_info().best_number),
AccountKeyring::Ferdie.into(),
)
.balance_of(client.chain_info().best_hash, AccountKeyring::Ferdie.into())
.unwrap(),
42
);
@@ -1256,10 +1244,7 @@ fn state_reverted_on_reorg() {
let current_balance = |client: &substrate_test_runtime_client::TestClient| {
client
.runtime_api()
.balance_of(
&BlockId::number(client.chain_info().best_number),
AccountKeyring::Alice.into(),
)
.balance_of(client.chain_info().best_hash, AccountKeyring::Alice.into())
.unwrap()
};
@@ -1996,10 +1981,10 @@ fn use_dalek_ext_works() {
// On block zero it will use dalek and then on block 1 it will use zebra
assert!(!client
.runtime_api()
.verify_ed25519(&BlockId::Number(0), zero_ed_sig(), zero_ed_pub(), vec![])
.verify_ed25519(client.chain_info().genesis_hash, zero_ed_sig(), zero_ed_pub(), vec![])
.unwrap());
assert!(client
.runtime_api()
.verify_ed25519(&BlockId::Number(1), zero_ed_sig(), zero_ed_pub(), vec![])
.verify_ed25519(a1.hash(), zero_ed_sig(), zero_ed_pub(), vec![])
.unwrap());
}