Skip to content

Commit

Permalink
Update substrate to polkadot v0.9.37 (polkadot-evm#980)
Browse files Browse the repository at this point in the history
* fix: use block hash instead of id

See paritytech/substrate@657c808

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* fix: optional state_prunning field

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* build: update substrate to polkadot-v0.9.37

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* fix: use old error message on missing block

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

* style: remove unused import

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>

---------

Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
  • Loading branch information
CertainLach authored Feb 8, 2023
1 parent c34c032 commit abc025a
Show file tree
Hide file tree
Showing 11 changed files with 1,956 additions and 989 deletions.
2,889 changes: 1,924 additions & 965 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/cli/src/frontier_db_cmd/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn cmd(key: String, value: Option<PathBuf>, operation: Operation, column: Column
detailed_log_output: false,
},
pruning_params: sc_cli::PruningParams {
state_pruning: DatabasePruningMode::Archive,
state_pruning: Some(DatabasePruningMode::Archive),
blocks_pruning: DatabasePruningMode::Archive,
},
}
Expand Down
10 changes: 5 additions & 5 deletions client/db/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{

use scale_codec::{Decode, Encode};
use sp_core::H256;
use sp_runtime::traits::{Block as BlockT, Header};
use sp_runtime::traits::Block as BlockT;

use crate::DatabaseSource;

Expand Down Expand Up @@ -194,11 +194,11 @@ where
if decoded.is_err() || decoded.unwrap().is_empty() {
// Verify the substrate hash is part of the canonical chain.
if let Ok(Some(number)) = client.number(Block::Hash::decode(&mut &substrate_hash[..]).unwrap()) {
if let Ok(Some(header)) = client.header(sp_runtime::generic::BlockId::Number(number)) {
if let Ok(Some(hash)) = client.hash(number) {
transaction.put_vec(
crate::columns::BLOCK_MAPPING,
ethereum_hash,
vec![header.hash()].encode(),
vec![hash].encode(),
);
res.success += 1;
maybe_error = false;
Expand Down Expand Up @@ -280,11 +280,11 @@ where
if decoded.is_err() || decoded.unwrap().is_empty() {
// Verify the substrate hash is part of the canonical chain.
if let Ok(Some(number)) = client.number(Block::Hash::decode(&mut &substrate_hash[..]).unwrap()) {
if let Ok(Some(header)) = client.header(sp_runtime::generic::BlockId::Number(number)) {
if let Ok(Some(hash)) = client.hash(number) {
transaction.push((
crate::columns::BLOCK_MAPPING as u8,
ethereum_hash,
Some(vec![header.hash()].encode()),
Some(vec![hash].encode()),
));
res.success += 1;
maybe_error = false;
Expand Down
2 changes: 1 addition & 1 deletion client/mapping-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ where
return Ok(None);
}

match substrate_backend.header(BlockId::Hash(checking_tip)) {
match substrate_backend.header(checking_tip) {
Ok(Some(checking_header)) if checking_header.number() >= &sync_from => {
Ok(Some(checking_header))
}
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sc_network_common::ExHashT;
use sc_transaction_pool::ChainApi;
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::{BlockStatus, HeaderBackend};
use sp_blockchain::HeaderBackend;
use sp_runtime::{
generic::BlockId,
traits::{BlakeTwo256, Block as BlockT},
Expand Down Expand Up @@ -112,9 +112,9 @@ where
}
};

if let Ok(BlockStatus::Unknown) = self.client.status(id) {
let Ok(_hash) = self.client.expect_block_hash_from_id(&id) else {
return Err(crate::err(JSON_RPC_ERROR_DEFAULT, "header not found", None));
}
};

let api_version =
if let Ok(Some(api_version)) = api.api_version::<dyn EthereumRuntimeRPCApi<B>>(&id) {
Expand Down
6 changes: 5 additions & 1 deletion client/rpc/src/eth/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ where
self.backend.as_ref(),
Some(newest_block),
) {
let header = match self.client.header(id) {
let Ok(hash) = self.client.expect_block_hash_from_id(&id) else {
return Err(internal_err(format!("Failed to retrieve block hash at {id}")));
};
let header = match self.client.header(hash) {
Ok(Some(h)) => h,
_ => {
return Err(internal_err(format!("Failed to retrieve header at {}", id)));
}
};
// Canonical chain block number.
let number = match self.client.number(header.hash()) {
Ok(Some(n)) => n,
_ => {
Expand Down
5 changes: 3 additions & 2 deletions client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,16 @@ where
{
// In case of Pending, we need an overlayed state to query over.
let api = client.runtime_api();
let best = BlockId::Hash(client.info().best_hash);
let best_hash = client.info().best_hash;
let best = BlockId::Hash(best_hash);
// Get all transactions in the ready queue.
let xts: Vec<<B as BlockT>::Extrinsic> = graph
.validated_pool()
.ready()
.map(|in_pool_tx| in_pool_tx.data().clone())
.collect::<Vec<<B as BlockT>::Extrinsic>>();
// Manually initialize the overlay.
if let Ok(Some(header)) = client.header(best) {
if let Ok(Some(header)) = client.header(best_hash) {
let parent_hash = BlockId::Hash(*header.parent_hash());
api.initialize_block(&parent_hash, &header)
.map_err(|e| internal_err(format!("Runtime api access error: {:?}", e)))?;
Expand Down
7 changes: 5 additions & 2 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ pub mod frontier_backend_client {
BE: Backend<B> + 'static,
BE::State: StateBackend<BlakeTwo256>,
{
let Ok(at) = client.expect_block_hash_from_id(&at) else {
return EthereumStorageSchema::Undefined
};
if let Ok(Some(header)) = client.header(at) {
match client.storage(header.hash(), &StorageKey(PALLET_ETHEREUM_SCHEMA.to_vec())) {
Ok(Some(bytes)) => Decode::decode(&mut &bytes.0[..])
Expand All @@ -169,8 +172,8 @@ pub mod frontier_backend_client {
C: HeaderBackend<B> + Send + Sync + 'static,
{
if let Ok(Some(number)) = client.number(target_hash) {
if let Ok(Some(header)) = client.header(BlockId::Number(number)) {
return header.hash() == target_hash;
if let Ok(Some(hash)) = client.hash(number) {
return hash == target_hash;
}
}
false
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/src/overrides/schema_v1_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sc_client_api::backend::{Backend, StateBackend, StorageProvider};
use sp_api::BlockId;
use sp_blockchain::HeaderBackend;
use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT},
traits::{BlakeTwo256, Block as BlockT},
Permill,
};
use sp_storage::StorageKey;
Expand Down Expand Up @@ -58,8 +58,8 @@ where
BE::State: StateBackend<BlakeTwo256>,
{
fn query_storage<T: Decode>(&self, id: &BlockId<B>, key: &StorageKey) -> Option<T> {
if let Ok(Some(header)) = self.client.header(*id) {
if let Ok(Some(data)) = self.client.storage(header.hash(), key) {
if let Ok(Some(hash)) = self.client.block_hash_from_id(id) {
if let Ok(Some(data)) = self.client.storage(hash, key) {
if let Ok(result) = Decode::decode(&mut &data.0[..]) {
return Some(result);
}
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/src/overrides/schema_v2_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sc_client_api::backend::{Backend, StateBackend, StorageProvider};
use sp_api::BlockId;
use sp_blockchain::HeaderBackend;
use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT},
traits::{BlakeTwo256, Block as BlockT},
Permill,
};
use sp_storage::StorageKey;
Expand Down Expand Up @@ -58,8 +58,8 @@ where
BE::State: StateBackend<BlakeTwo256>,
{
fn query_storage<T: Decode>(&self, id: &BlockId<B>, key: &StorageKey) -> Option<T> {
if let Ok(Some(header)) = self.client.header(*id) {
if let Ok(Some(data)) = self.client.storage(header.hash(), key) {
if let Ok(Some(hash)) = self.client.block_hash_from_id(id) {
if let Ok(Some(data)) = self.client.storage(hash, key) {
if let Ok(result) = Decode::decode(&mut &data.0[..]) {
return Some(result);
}
Expand Down
6 changes: 3 additions & 3 deletions client/rpc/src/overrides/schema_v3_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sc_client_api::backend::{Backend, StateBackend, StorageProvider};
use sp_api::BlockId;
use sp_blockchain::HeaderBackend;
use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT},
traits::{BlakeTwo256, Block as BlockT},
Permill,
};
use sp_storage::StorageKey;
Expand Down Expand Up @@ -58,8 +58,8 @@ where
BE::State: StateBackend<BlakeTwo256>,
{
fn query_storage<T: Decode>(&self, id: &BlockId<B>, key: &StorageKey) -> Option<T> {
if let Ok(Some(header)) = self.client.header(*id) {
if let Ok(Some(data)) = self.client.storage(header.hash(), key) {
if let Ok(Some(hash)) = self.client.block_hash_from_id(id) {
if let Ok(Some(data)) = self.client.storage(hash, key) {
if let Ok(result) = Decode::decode(&mut &data.0[..]) {
return Some(result);
}
Expand Down

0 comments on commit abc025a

Please sign in to comment.