From af245f2e828503fa71a7e78cffdc395deda14009 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Mon, 8 Jun 2020 11:12:48 +0200 Subject: [PATCH] pallet-ethereum: add number to hash mapping for Ethereum headers (#29) --- Cargo.lock | 3 +++ frame/ethereum/src/lib.rs | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e15cbf3a7..12572bcb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1100,10 +1100,13 @@ dependencies = [ "pallet-ethereum 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec", "rlp", + "sc-client-api", + "sc-service", "sha3", "sp-api", "sp-consensus", "sp-runtime", + "sp-storage", "sp-transaction-pool", ] diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index 3bdc2255a..2a60b9730 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -57,7 +57,8 @@ decl_storage! { // storage items are isolated from other pallets. // ---------------------------------vvvvvvv trait Store for Module as Example { - BlocksAndReceipts: map hasher(blake2_128_concat) T::BlockNumber => Option<(ethereum::Block, Vec)>; + BlocksAndReceipts: map hasher(blake2_128_concat) H256 => Option<(ethereum::Block, Vec)>; + BlockNumbers: map hasher(blake2_128_concat) T::BlockNumber => H256; PendingTransactionsAndReceipts: Vec<(ethereum::Transaction, ethereum::Receipt)>; TransactionStatuses: map hasher(blake2_128_concat) H256 => Option; } @@ -182,6 +183,7 @@ decl_module! { mix_hash: H256::default(), nonce: H64::default(), }; + let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&header)).as_slice()); let block = ethereum::Block { header, @@ -189,7 +191,8 @@ decl_module! { ommers, }; - BlocksAndReceipts::::insert(n, (block, receipts)); + BlocksAndReceipts::insert(hash, (block, receipts)); + BlockNumbers::::insert(n, hash); } // A runtime code run after every block and have access to extended set of APIs.