Skip to content

feat: get state and storage tries by hash#601

Merged
Arkenan merged 1 commit into
mainfrom
non-canonical-eth-call
Oct 2, 2024
Merged

feat: get state and storage tries by hash#601
Arkenan merged 1 commit into
mainfrom
non-canonical-eth-call

Conversation

@Arkenan

@Arkenan Arkenan commented Oct 1, 2024

Copy link
Copy Markdown
Collaborator

Changes

  • Change the access to tries in storage engines from number to hash
  • In storage.rs, change methods from numbers to hashes if needed, and add wrappers when not.
  • Make accesses by hash in evm_state construction, the trie db wrapper, blockchain, etc.

Regarding the note in the issue:

Endpoints that should accept non canonical blocks:

  • newPayload
  • call
  • newPayload uses add_block, which now uses hash to get the evm state. This will be useful for reorgs too.
  • call gets called by number or string ids, but not by hash, so the number wrapper is supported.

Closes #443

@Arkenan Arkenan marked this pull request as ready for review October 1, 2024 17:17
@Arkenan Arkenan requested a review from a team as a code owner October 1, 2024 17:17
let new_state_root = state
.database()
.apply_account_updates(parent_header.number, &account_updates)?
.apply_account_updates(block.header.parent_hash, &account_updates)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does default do for a new_state_root?
Not saying this is wrong per-se, but this makes me raise an eyebrow. I think it would be better do unwrap_or_else an explicitly do the default case, since If I'm looking this code, now I also have to double-check what the default trait does for this type, please feel correct me If you disagree.

That being said, this is not part of this PR, so maybe we can make an issue to handle it another time.

Comment thread crates/evm/db.rs
.get_storage_at(
self.block_number,
.get_storage_at_hash(
self.block_hash,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from Block Number to Block Hash?
I've read the PR details but I still do not understand it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be more than one block with the same block number but different hash. When you get block by number, you are getting the canonical block. The hash is the unique identifier. This change happens because you want to be able to calculate the state transition on non-canonical blocks too.

@Arkenan Arkenan added this pull request to the merge queue Oct 2, 2024
Merged via the queue into main with commit ed34117 Oct 2, 2024
@Arkenan Arkenan deleted the non-canonical-eth-call branch October 2, 2024 10:45
mpaulucci pushed a commit that referenced this pull request Oct 16, 2024
**Changes**

- Change the access to tries in storage engines from number to hash
- In `storage.rs`, change methods from numbers to hashes if needed, and
add wrappers when not.
- Make accesses by hash in `evm_state` construction, the trie db
wrapper, blockchain, etc.

Regarding the note in the issue:

> Endpoints that should accept non canonical blocks:
> - newPayload
> - call

- `newPayload` uses `add_block`, which now uses hash to get the evm
state. This will be useful for reorgs too.
- call gets called by number or string ids, but not by hash, so the
number wrapper is supported.

Closes #443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to run eth_call on blocks that are non canonical

3 participants