Skip to content

Commit

Permalink
Shiden block fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Mar 26, 2024
1 parent e262e80 commit 76939a1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
21 changes: 19 additions & 2 deletions client/rpc/src/eth/block.rs
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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(&eth_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 => {
Expand Down
25 changes: 25 additions & 0 deletions client/rpc/src/eth/mod.rs
Expand Up @@ -628,6 +628,31 @@ fn rich_block_build(
}
}

fn empty_block_from(number: U256) -> ethereum::BlockV2 {
let ommers = Vec::<ethereum::Header>::new();
let receipts = Vec::<ethereum::ReceiptV2>::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>,
Expand Down
5 changes: 4 additions & 1 deletion primitives/consensus/src/lib.rs
Expand Up @@ -130,5 +130,8 @@ pub fn find_log(digest: &Digest) -> Result<Log, FindLogError> {
}

pub fn ensure_log(digest: &Digest) -> Result<(), FindLogError> {
find_log(digest).map(|_log| ())
match find_log(digest) {
Err(FindLogError::MultipleLogs) => Err(FindLogError::MultipleLogs),
_ => Ok(()),
}
}

0 comments on commit 76939a1

Please sign in to comment.