Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for eth_getAccount #9625

Closed
mattsse opened this issue Jul 18, 2024 · 13 comments
Closed

Add support for eth_getAccount #9625

mattsse opened this issue Jul 18, 2024 · 13 comments
Assignees
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started

Comments

@mattsse
Copy link
Collaborator

mattsse commented Jul 18, 2024

Describe the feature

ref https://www.quicknode.com/docs/ethereum/eth_getAccount

TODO

  • add endpoint to trait, like
    /// Returns information about a block by hash.
    #[method(name = "getBlockByHash")]
    async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<RichBlock>>;
  • implement it like
    /// Handler for: `eth_getBlockByHash`
    async fn block_by_hash(&self, hash: B256, full: bool) -> RpcResult<Option<RichBlock>> {
    trace!(target: "rpc::eth", ?hash, ?full, "Serving eth_getBlockByHash");
    Ok(EthBlocks::rpc_block(self, hash.into(), full).await?)
    }

the latter likely needs more work, so this can be two prs where the first just introduces the trait function and when figure out how to get the account's storage root cc @rkrasiuk

Additional context

No response

@mattsse mattsse added C-enhancement New feature or request S-needs-triage This issue needs to be labelled D-good-first-issue Nice and easy! A great choice to get started A-rpc Related to the RPC implementation and removed S-needs-triage This issue needs to be labelled labels Jul 18, 2024
@mvares
Copy link
Contributor

mvares commented Jul 18, 2024

:shipit:

@mvares
Copy link
Contributor

mvares commented Jul 18, 2024

   graph TD
    A[Get Account]
    B[codeHash]
    C[storageRoot]
    D[balance]
    E[nonce]

    A --> B
    A --> C
    A --> D
    A --> E
Loading

As was done here, this can be a starting point to address this the second question of this issue.

@mattsse
Copy link
Collaborator Author

mattsse commented Jul 19, 2024

@rkrasiuk I assume getting the storageroot at any block number isn't that easy, same issue as eth_getProof?

@rkrasiuk
Copy link
Member

rkrasiuk commented Jul 19, 2024

@mattsse actually it's much easier since you only need to load storage changes for a given account. so, as long as all touched storage can fit in memory, we would be good

@mattsse
Copy link
Collaborator Author

mattsse commented Jul 19, 2024

could you please add some pointers on where to start, I see we have an AccountReader trait

@rkrasiuk
Copy link
Member

we would need to expose the interface in HashedStorage similar to HashedPostState::from_revert_range that only loads storage changes for a single account. then we would be able to initialize storage root with in-memory hashed state
e.g.

let address = ();
let hashed_address = keccack256(address);
let hashed_storage = HashedStorage::from_revert_range(address, &tx, block_range)?;
let hahed_storage_sorted = hashed_storage.into_sorted();
let root = StorageRoot::new_hashed(
    &tx,
    HashedPostStateStorageCursor::new(
        DatabaseHashedStorageCursor::new(
            tx.cursor_dup_read::<tables::HashedStorages>()?,
            hashed_address,
        ),
        Some(&hashed_storage_sorted)
    ),
    hashed_address,
).root()?

@mvares
Copy link
Contributor

mvares commented Jul 19, 2024

@rkrasiuk, in the part of balance, could we use the getBalance? (Already it's created)

@mvares
Copy link
Contributor

mvares commented Jul 19, 2024

@rkrasiuk
Copy link
Member

@mvares you can just retrieve account information from HistoricalStateProvider through state_at_block_* fns

@mvares
Copy link
Contributor

mvares commented Jul 20, 2024

@mvares you can just retrieve account information from HistoricalStateProvider through state_at_block_* fns

Wouldn't it be better to use the balance method from EthApiServer?

@greged93
Copy link
Contributor

hey @mvares are you still working on this? otherwise I'm down to give it a go

@mvares
Copy link
Contributor

mvares commented Aug 12, 2024

@greged93 go for it

@Rjected
Copy link
Member

Rjected commented Aug 19, 2024

This should be fixed by #10369

@Rjected Rjected closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started
Projects
Archived in project
Development

No branches or pull requests

5 participants