Skip to content

feat: admin_NodeInfo endpoint#312

Merged
mpaulucci merged 24 commits into
mainfrom
admin-nodeinfo
Sep 2, 2024
Merged

feat: admin_NodeInfo endpoint#312
mpaulucci merged 24 commits into
mainfrom
admin-nodeinfo

Conversation

@vicentevieytes

@vicentevieytes vicentevieytes commented Aug 28, 2024

Copy link
Copy Markdown
Contributor

Motivation

The RPC method admin_nodeInfo of the admin namespace is a non standard endpoint that might be necessary for configuring the hive p2p tests, it provides information about the node's network and protocol configuration.

Description

Introduces the RPC admin_nodeInfo endpoint which is only accessible through the HTTP API. It returns the enode configuration and, for the eth protocol, the chain config that was set on genesis.
To achieve this, a ChainConfig struct and a Node struct representing the eth and p2p configurations respectively must be passed to the http request handler so that it can provide the correct response.
This data is passed to the handler by adding it to the RpcApiContext struct .

Introduces a small refactor to the net crate, extracting the types Endpoint Node and NodeRecord to a public types module.

Contains a small rewrite to the RPC routing of requests, separating them by namespace.

Example output:

➜  ethereum_rust git:(admin-nodeinfo) curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0", "method":"admin_nodeInfo", "params":[], "id":1}' "localhost:59196"


{
   "id":1,
   "jsonrpc":"2.0",
   "result":{
      "enode":"enode://f76e29b3291f595ac9e0465250e6e4e1cc57f8d2b02503d52b5e5175739878ae6d6222d38b777b0f89888ad65806d0c97a8643b54b67d161201aa43a88765d34@0.0.0.0:30303?discport=30303",
      "id":"f76e29b3291f595ac9e0465250e6e4e1cc57f8d2b02503d52b5e5175739878ae6d6222d38b777b0f89888ad65806d0c97a8643b54b67d161201aa43a88765d34",
      "ip":"0.0.0.0",
      "name":"ethereum_rust/0.1.0/rust1.80",
      "ports":{
         "discovery":30303,
         "listener":30303
      },
      "protocols":{
         "eth":{
            "chainId":"0x301824",
            "homesteadBlock":0,
            "daoForkBlock":null,
            "daoForkSupport":false,
            "eip150Block":0,
            "eip155Block":0,
            "eip158Block":0,
            "byzantiumBlock":0,
            "constantinopleBlock":0,
            "petersburgBlock":0,
            "istanbulBlock":0,
            "muirGlacierBlock":null,
            "berlinBlock":0,
            "londonBlock":0,
            "arrowGlacierBlock":null,
            "grayGlacierBlock":null,
            "mergeNetsplitBlock":0,
            "shanghaiTime":0,
            "cancunTime":0,
            "pragueTime":1725062017,
            "verkleTime":null,
            "terminalTotalDifficulty":"0x0",
            "terminalTotalDifficultyPassed":true
         }
      }
   }
}%

Closes #248

@vicentevieytes vicentevieytes changed the title implement admin_NodeInfo endpoint feat: admin_NodeInfo endpoint Aug 28, 2024
@vicentevieytes vicentevieytes marked this pull request as ready for review August 28, 2024 20:02
@vicentevieytes vicentevieytes requested a review from a team as a code owner August 28, 2024 20:02
Comment thread crates/rpc/utils.rs
}

impl RpcRequest {
pub fn namespace(&self) -> Result<RpcNamespace, RpcErr> {

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.

nice!

Comment thread crates/rpc/admin/mod.rs Outdated
Eth(ChainConfig),
}

pub fn node_info(chain_config: ChainConfig, local_node: Node) -> Result<Value, RpcErr> {

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.

instead of passing chain config as a param/context, you should be able to get it from storage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done!

@vicentevieytes vicentevieytes requested review from a team and mpaulucci August 30, 2024 15:35
@mpaulucci mpaulucci added this pull request to the merge queue Sep 2, 2024
Merged via the queue into main with commit 92b499d Sep 2, 2024
@mpaulucci mpaulucci deleted the admin-nodeinfo branch September 2, 2024 15:24
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 admin_nodeInfo RPC endpoint

3 participants