risechain / pevm

Blazingly fast Parallel EVM
MIT License
227 stars 47 forks source link

Replace `PlainAccount` with our own `Account` type #143

Closed hai-rise closed 4 months ago

hai-rise commented 5 months ago

We can rename InMemoryAccount to Account and replace most PlainAccount usage with it. Then the only conversion needed is probably in the state test where we would convert our Account to PlainAccount to call REVM's state_merkle_trie_root function. In the future we can implement that ourselves, too.

The end goal is to have consistent types both internally and for library users and minimize leaking underlying types like REVM's anywhere.

chirag-bgh commented 4 months ago

Hey, I can work on this. I think we need to rename InMemoryStorage right?


pub struct InMemoryStorage {
    accounts: HashMap<Address, EvmAccount, BuildAddressHasher>,
    block_hashes: AHashMap<U256, B256>,
}
hai-rise commented 4 months ago

@chirag-bgh Thank you for your interest!

This task is all about replacing PlainAccount with our new EvmAccount type currently defined here: https://github.com/risechain/pevm/blob/d7904031711c61b927a703539e7e08784963cdb9/src/storage.rs#L13-L23

I think a good place to start is to change the ChainState type for tests and benches:

diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 04ac6da..bf7deab 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -7,14 +7,14 @@ use std::{
 use ahash::AHashMap;
 use alloy_primitives::{Address, Bloom, Bytes, B256, U256};
 use alloy_rpc_types::{Block, Header};
-use pevm::InMemoryStorage;
+use pevm::{EvmAccount, InMemoryStorage};
 use revm::{db::PlainAccount, primitives::KECCAK_EMPTY};

 pub mod runner;
 pub use runner::{assert_execution_result, mock_account, test_execute_alloy, test_execute_revm};
 pub mod storage;

-pub type ChainState = AHashMap<Address, PlainAccount>;
+pub type ChainState = AHashMap<Address, EvmAccount>;
 pub type BlockHashes = AHashMap<U256, B256>;

 pub static MOCK_ALLOY_BLOCK_HEADER: Header = Header {

Then run cargo test --release -- --test-threads=1 to get compile errors on where we should replace PlainAccounts with EvmAccounts :pray:.

hai-rise commented 4 months ago

Completed the rest as part of #200 🙏.