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

feat: add rpc endpoints eth_getBlockByNumber & eth_getBlockByHash #145

Merged
merged 34 commits into from
Jul 18, 2024

Conversation

fmoletta
Copy link
Contributor

@fmoletta fmoletta commented Jul 12, 2024

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
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
Copy link
Collaborator

@MegaRedHand MegaRedHand left a comment

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
6 checks passed
@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
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this pull request Oct 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 lambdaclass#111, Resolves lambdaclass#222 -->

Closes None, but is needed for lambdaclass#145
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this pull request Oct 16, 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 lambdaclass#111, Resolves lambdaclass#222 -->

Closes None, but addresses comment on lambdaclass#145
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this pull request Oct 16, 2024
…lambdaclass#145)

Based on lambdaclass#150, please merge it first

**Motivation**

Comply with rpc spec for `eth_getBlockByNumber` & `eth_getBlockByHash`

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

**Description**
* Integrate `Store` as a state for the rpc api

* Add RPC endpoints `eth_getBlockByNumber` & `eth_getBlockByHash`

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

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

Closes lambdaclass#31
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this pull request Oct 16, 2024
…class#152)

Based on lambdaclass#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 lambdaclass#111, Resolves lambdaclass#222 -->

Closes lambdaclass#33

---------

Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
mpaulucci pushed a commit to mpaulucci/lambda_ethereum_rust that referenced this pull request Oct 16, 2024
Based on lambdaclass#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 lambdaclass#111, Resolves lambdaclass#222 -->

Closes lambdaclass#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