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 22, 2023
1 parent c614661 commit aff8c5b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
19 changes: 17 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, Eth},
eth::{empty_block_from, rich_block_build, Eth},
frontier_backend_client, internal_err,
};

Expand Down Expand Up @@ -174,7 +174,22 @@ where
}
Ok(Some(rich_block))
}
_ => Ok(None),
_ => {
if let BlockNumber::Num(block_number) = number {
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,
)))
} else {
Ok(None)
}
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions client/rpc/src/eth/mod.rs
Expand Up @@ -424,6 +424,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 aff8c5b

Please sign in to comment.