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(providers): add a subset of admin namespace #1880

Merged
merged 54 commits into from
Nov 30, 2022

Conversation

Rjected
Copy link
Contributor

@Rjected Rjected commented Nov 22, 2022

Motivation

Geth includes an admin namespace which is especially useful for querying its p2p details and prompting the node to add or remove peers.

Solution

  • Add NodeInfo for the admin_nodeInfo return type
  • Add PeerInfo for the admin_peers return type
  • Add the following admin namespace RPCs to Middleware, implementing them on Provider<P>:
    • admin_nodeInfo
    • admin_peers
    • admin_addPeer
    • admin_addTrustedPeer
    • admin_removePeer
    • admin_removeTrustedPeer

This also modifies the Geth and GethInstance structs to support custom chain ids and running without the --dev flag. --dev-specific configuration options, and options that are incompatible with --dev are kept mutually exclusive with the PrivateNetOptions enum. Unless a dev-incompatible option is set, --dev mode will remain the default. An option for disabling discovery is also added.

This also adds a simple test using the new Geth options to set a few custom fields that are visible in the admin_nodeInfo output.

Misc change:

  • expose from_int_or_hex as a general utility so it can be used for admin_nodeInfo response deserialization.

TODO:

  • cover other RPCs - test for adding and removing peers, as well as listing peers.
    • the test added does the following:
      • connect two geth peers
      • ensure that the admin_peers endpoint deserializes correctly
      • the id obtained from the admin_peers RPC call matches the id from the admin_nodeInfo response for that peer
    • more tests should be added for admin endpoints, maybe good for a future PR or issue
    • another thing out of scope for this PR: genesis.json deserialization tests
  • simple (de)serialization tests for NodeInfo and PeerInfo
  • consider other admin_ endpoints to add - admin_peerEvents maybe?
    • admin_peerEvents is of scope for this PR, will create an issue

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

@Rjected Rjected changed the title feat(providers): add part of admin namespace feat(providers): add a subset of admin namespace Nov 26, 2022
@Rjected Rjected marked this pull request as ready for review November 26, 2022 02:54
@Rjected
Copy link
Contributor Author

Rjected commented Nov 26, 2022

Currently fails the deserialize_node_info_post_merge test, ready for review after fixing that bug

@Rjected
Copy link
Contributor Author

Rjected commented Nov 26, 2022

Tests pass and the bug is fixed, the bug was that from_int_or_hex wouldn't deserialize big numbers, luckily serde_json::Number can be used with the arbitrary-precision feature from serde_json

@Rjected Rjected force-pushed the add-admin-nodeinfo branch 4 times, most recently from 153a858 to 4fd5709 Compare November 26, 2022 06:37
Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

nice work! nits

Comment on lines 2267 to 2268
// wait for the geth dial loop to start and connect the static nodes
sleep(Duration::from_secs(20)).await;
Copy link
Owner

Choose a reason for hiding this comment

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

this takes that long? can we instead poll the node like we poll ganache-cli instaed of hardcoding a wait time? it's gonna screw up our reth integration tests otherwise imo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, added a method wait_to_add_peer which polls geth's stderr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

another method would be polling the admin_peers endpoint, we might be able to accomplish this using admin_peerEvents in the future

use super::*;

#[test]
fn deserialize_peer_info() {
Copy link
Owner

Choose a reason for hiding this comment

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

sweet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

ethers-providers/Cargo.toml Outdated Show resolved Hide resolved
Comment on lines +450 to +463
/// Deserializes the input into a U256, accepting both 0x-prefixed hex and decimal strings with
/// arbitrary precision, defined by serde_json's [`Number`](serde_json::Number).
pub fn from_int_or_hex<'de, D>(deserializer: D) -> Result<U256, D::Error>
Copy link
Owner

Choose a reason for hiding this comment

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

should we have this in other desers too? no need to do now

Copy link
Contributor Author

@Rjected Rjected Nov 28, 2022

Choose a reason for hiding this comment

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

some desers already use this, but it would be worth checking other types of rpc responses that might have decimal values

Comment on lines +192 to +231
/// Disable discovery for the geth instance.
///
/// This will put the geth instance into non-dev mode, discarding any previously set dev-mode
/// options.
#[must_use]
pub fn disable_discovery(mut self) -> Self {
Copy link
Owner

Choose a reason for hiding this comment

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

nice. we should consider thinking of how can we use these options on geth to cause partitions intentionally and see how our failure recovery works

@gakonst
Copy link
Owner

gakonst commented Nov 28, 2022

@Rjected lets try to merge by eod?

@Rjected
Copy link
Contributor Author

Rjected commented Nov 28, 2022

@gakonst sounds good, will prioritize

@Rjected
Copy link
Contributor Author

Rjected commented Nov 29, 2022

Mysterious connection refused error in another test that also uses geth hmmm

Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

amazing work

@gakonst gakonst merged commit 4b68562 into gakonst:master Nov 30, 2022
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.

2 participants