Skip to content

Commit

Permalink
Shiden block fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jul 10, 2023
1 parent adf7117 commit d74a159
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
20 changes: 18 additions & 2 deletions client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use fc_rpc_core::types::*;
use fp_rpc::EthereumRuntimeRPCApi;

use crate::{
eth::{rich_block_build, Eth, EthConfig},
eth::{empty_block_from, rich_block_build, Eth, EthConfig},
frontier_backend_client, internal_err,
};

Expand Down Expand Up @@ -198,7 +198,23 @@ where
_ => Ok(None),
}
}
None => Ok(None),
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,
false,
)))
} else {
Ok(None)
}
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,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
Original file line number Diff line number Diff line change
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 d74a159

Please sign in to comment.