Skip to content

feat: add rpc endpoints eth_getBlockByNumber & eth_getBlockByHash#145

Merged
MegaRedHand merged 34 commits into
mainfrom
get_block_by_number
Jul 18, 2024
Merged

feat: add rpc endpoints eth_getBlockByNumber & eth_getBlockByHash#145
MegaRedHand merged 34 commits into
mainfrom
get_block_by_number

Conversation

@fmoletta

@fmoletta fmoletta commented Jul 12, 2024

Copy link
Copy Markdown
Contributor

Based on #150, please merge it first

Motivation

Comply with rpc spec for eth_getBlockByNumber & eth_getBlockByHash

Description

  • Integrate Store as a state for the rpc api

  • Add RPC endpoints eth_getBlockByNumber & eth_getBlockByHash

Closes #31

@fmoletta fmoletta force-pushed the get_block_by_number branch from b9007c3 to 71eabb8 Compare July 12, 2024 19:05
@fmoletta fmoletta changed the base branch from main to add-block-api-to-db July 12, 2024 19:06
@fmoletta fmoletta force-pushed the get_block_by_number branch from 71eabb8 to af6c894 Compare July 15, 2024 19:48
@fmoletta fmoletta changed the base branch from add-block-api-to-db to main July 15, 2024 21:51
@fmoletta fmoletta changed the base branch from main to add-block-api-to-db July 15, 2024 21:52
@fmoletta fmoletta changed the title [WIP] rpc eth_getBlockByNumber [DNM] feat: add rpc endpoints eth_getBlockByNumber & eth_getBlockByHash Jul 15, 2024
fmoletta added a commit that referenced this pull request Jul 16, 2024
**Motivation**

Being able to store and fetch blocks from the db via `Store` api

**Description**

* Replace `Transaction::encode` with `Transaction::encode_with_type`
logic (Reasoning: We cannot decode the transactions without knowing
their type with the current behaviour, making it impossible to implement
`RLPDecode` for `Transaction`)
* Implement `RLPDecode` for `Transaction` (Using the logic that was
previoulsy used in `EncodedTransaction::decode` (payload module))
* Implement `RLPDecode` for `Withdrawal`, `BlockHeader` and `BlockBody`
* Add the folloewng methods to `Store` and `StoreEngine`:
`add_block_header`, `add_block_body`, `get_block_header`,
`get_block_body`, and implement them for `InMemory` and `Libmdbx` engine
types

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes None, but is needed for #145
Base automatically changed from add-block-api-to-db to main July 16, 2024 13:32
@fmoletta fmoletta force-pushed the get_block_by_number branch from 7969462 to b5051ff Compare July 16, 2024 16:51
@fmoletta fmoletta changed the base branch from main to add-block-number-table July 16, 2024 16:52
@fmoletta fmoletta force-pushed the get_block_by_number branch from c97a18d to 631dfa7 Compare July 16, 2024 17:06
@fmoletta fmoletta changed the title [DNM] feat: add rpc endpoints eth_getBlockByNumber & eth_getBlockByHash feat: add rpc endpoints eth_getBlockByNumber & eth_getBlockByHash Jul 16, 2024
@fmoletta fmoletta marked this pull request as ready for review July 16, 2024 17:51
@fmoletta fmoletta requested a review from a team as a code owner July 16, 2024 17:51
Comment thread crates/rpc/src/lib.rs Outdated
Base automatically changed from add-block-number-table to main July 17, 2024 11:22
fmoletta added a commit that referenced this pull request Jul 17, 2024
**Motivation**

Currently, the `handle_http_requests` doesn't allow us to return an
error when handling requests. This can be solved by handling them via a
`map_requests` function like in `handle_authrpc_requests`. While
`handle_authrpc_requests` handles comunication between clients and
`handle_http_requests` handles comunication between the client and
users, there are a lot of requests that are handled by both of them. As
they both use the same request format, there is little reason to
implement two different functions to handle the same requests in the
same way. We can use `map_requests` to handle both auth_rpc and http
requests, and then implement a second handler (such as
`map_internal_requests`) to handle auth_prc-specific requests.

<!-- Why does this pull request exist? What are its goals? -->

**Description**

Replaces `handle_http_requests` request handling with a call to
`map_requests`

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes None, but addresses comment on #145

@MegaRedHand MegaRedHand left a comment

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.

Great work!!

@MegaRedHand MegaRedHand merged commit 5820059 into main Jul 18, 2024
@MegaRedHand MegaRedHand deleted the get_block_by_number branch July 18, 2024 13:10
MegaRedHand added a commit that referenced this pull request Jul 18, 2024
Based on #145 

**Motivation**

Being able to respond to `eth_getBlockTransactionCountByNumber` requests
via rpc
<!-- Why does this pull request exist? What are its goals? -->

**Description**

Add rpc endpoint `eth_getBlockTransactionCountByNumber`

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes #33

---------

Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
fmoletta added a commit that referenced this pull request Jul 18, 2024
Based on #145 

**Motivation**

Support rpc endpoint `eth_getBalance`
**Description**

Add rpc endpoint `eth_getBalance`

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes #36
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.

Implement eth_getBlockByHash and eth_getBlockByNumber RPC endpoints

3 participants