From 76939a19b45d9908f0358b0aaed9a5ab20398f45 Mon Sep 17 00:00:00 2001 From: Dinonard Date: Thu, 4 Aug 2022 10:56:21 +0200 Subject: [PATCH] Shiden block fix --- client/rpc/src/eth/block.rs | 21 +++++++++++++++++++-- client/rpc/src/eth/mod.rs | 25 +++++++++++++++++++++++++ primitives/consensus/src/lib.rs | 5 ++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/client/rpc/src/eth/block.rs b/client/rpc/src/eth/block.rs index f7131375a0..96aaf3afb2 100644 --- a/client/rpc/src/eth/block.rs +++ b/client/rpc/src/eth/block.rs @@ -33,7 +33,7 @@ use fc_rpc_core::types::*; use fp_rpc::EthereumRuntimeRPCApi; use crate::{ - eth::{rich_block_build, BlockInfo, Eth}, + eth::{empty_block_from, rich_block_build, BlockInfo, Eth, EthConfig}, frontier_backend_client, internal_err, }; @@ -135,7 +135,24 @@ where Ok(Some(rich_block)) } - _ => Ok(None), + _ => { + if let BlockNumberOrHash::Num(block_number) = number_or_hash { + let eth_block = empty_block_from(block_number.into()); + let eth_hash = H256::from_slice( + keccak_256(&rlp::encode(ð_block.header)).as_slice(), + ); + Ok(Some(rich_block_build( + eth_block, + Default::default(), + Some(eth_hash), + full, + None, + false, + ))) + } else { + Ok(None) + } + } } } None if number_or_hash == BlockNumberOrHash::Pending => { diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index 9bc8fc205f..0f838c7c35 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -628,6 +628,31 @@ fn rich_block_build( } } +fn empty_block_from(number: U256) -> ethereum::BlockV2 { + let ommers = Vec::::new(); + let receipts = Vec::::new(); + let receipts_root = ethereum::util::ordered_trie_root( + receipts.iter().map(ethereum::EnvelopedEncodable::encode), + ); + let logs_bloom = ethereum_types::Bloom::default(); + let partial_header = ethereum::PartialHeader { + parent_hash: H256::default(), + beneficiary: Default::default(), + state_root: Default::default(), + receipts_root, + logs_bloom, + difficulty: U256::zero(), + number, + gas_limit: U256::from(4_000_000), + gas_used: U256::zero(), + timestamp: Default::default(), + extra_data: Vec::new(), + mix_hash: H256::default(), + nonce: H64::default(), + }; + ethereum::Block::new(partial_header, Default::default(), ommers) +} + fn transaction_build( ethereum_transaction: &EthereumTransaction, block: Option<&EthereumBlock>, diff --git a/primitives/consensus/src/lib.rs b/primitives/consensus/src/lib.rs index e9643d8eee..98c9a47217 100644 --- a/primitives/consensus/src/lib.rs +++ b/primitives/consensus/src/lib.rs @@ -130,5 +130,8 @@ pub fn find_log(digest: &Digest) -> Result { } pub fn ensure_log(digest: &Digest) -> Result<(), FindLogError> { - find_log(digest).map(|_log| ()) + match find_log(digest) { + Err(FindLogError::MultipleLogs) => Err(FindLogError::MultipleLogs), + _ => Ok(()), + } }