Skip to content

Commit

Permalink
fix block parent hash (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Sep 27, 2020
1 parent c893936 commit c0908a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<T: Trait> Module<T> {

let ommers = Vec::<ethereum::Header>::new();
let header = ethereum::Header {
parent_hash: frame_system::Module::<T>::parent_hash(),
parent_hash: Self::current_block_hash().unwrap_or_default(),
ommers_hash: H256::from_slice(
Keccak256::digest(&rlp::encode_list(&ommers)[..]).as_slice(),
), // TODO: check ommers hash.
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<T: Trait> Module<T> {
mix_hash: H256::default(),
nonce: H64::default(),
};
let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&header)).as_slice());
let hash = Self::ethereum_block_hash(&header);

let block = ethereum::Block {
header,
Expand Down Expand Up @@ -313,11 +313,16 @@ impl<T: Trait> Module<T> {
CurrentTransactionStatuses::get()
}

/// Get block by number.
/// Get current block.
pub fn current_block() -> Option<ethereum::Block> {
CurrentBlock::get()
}

/// Get current block hash
pub fn current_block_hash() -> Option<H256> {
Self::current_block().map(|block| Self::ethereum_block_hash(&block.header))
}

/// Get receipts by number.
pub fn current_receipts() -> Option<Vec<ethereum::Receipt>> {
CurrentReceipts::get()
Expand Down Expand Up @@ -430,4 +435,8 @@ impl<T: Trait> Module<T> {
ExitError::Other(_s) => return Error::<T>::ExitErrorOther,
}
}

fn ethereum_block_hash(header: &ethereum::Header) -> H256 {
H256::from_slice(Keccak256::digest(&rlp::encode(header)).as_slice())
}
}
2 changes: 1 addition & 1 deletion ts-tests/tests/test-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describeWithFrontier("Frontier RPC (Block)", `simple-specs.json`, (context) => {
expect(block).not.null;
});

it.skip("should include previous block hash as parent", async function () {
it("should include previous block hash as parent", async function () {
this.timeout(15000);
await createAndFinalizeBlock(context.web3);
const block = await context.web3.eth.getBlock("latest");
Expand Down

0 comments on commit c0908a0

Please sign in to comment.