-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change(rpc): Add getpeerinfo RPC method (#5951)
* adds ValidateBlock request to state * adds `Request` enum in block verifier skips solution check for BlockProposal requests calls CheckBlockValidity instead of Commit block for BlockProposal requests * uses new Request in references to chain verifier * adds getblocktemplate proposal mode response type * makes getblocktemplate-rpcs feature in zebra-consensus select getblocktemplate-rpcs in zebra-state * Adds PR review revisions * adds info log in CheckBlockProposalValidity * Reverts replacement of match statement * adds `GetBlockTemplate::capabilities` fn * conditions calling checkpoint verifier on !request.is_proposal * updates references to validate_and_commit_non_finalized * adds snapshot test, updates test vectors * adds `should_count_metrics` to NonFinalizedState * Returns an error from chain verifier for block proposal requests below checkpoint height adds feature flags * adds "proposal" to GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD * adds back block::Request to zebra-consensus lib * updates snapshots * Removes unnecessary network arg * skips req in tracing intstrument for read state * Moves out block proposal validation to its own fn * corrects `difficulty_threshold_is_valid` docs adds/fixes some comments, adds TODOs general cleanup from a self-review. * Update zebra-state/src/service.rs * Apply suggestions from code review Co-authored-by: teor <[email protected]> * Update zebra-rpc/src/methods/get_block_template_rpcs.rs Co-authored-by: teor <[email protected]> * check best chain tip * Update zebra-state/src/service.rs Co-authored-by: teor <[email protected]> * Applies cleanup suggestions from code review * updates gbt acceptance test to make a block proposal * fixes json parsing mistake * adds retries * returns reject reason if there are no retries left * moves result deserialization to RPCRequestClient method, adds docs, moves jsonrpc_core to dev-dependencies * moves sleep(EXPECTED_TX_TIME) out of loop * updates/adds info logs in retry loop * Revert "moves sleep(EXPECTED_TX_TIME) out of loop" This reverts commit f7f0926. * adds `allow(dead_code)` * tests with curtime, mintime, & maxtime * Fixes doc comment * Logs error responses from chain_verifier CheckProposal requests * Removes retry loop, adds num_txs log * removes verbose info log * sorts mempool_txs before generating merkle root * Make imports conditional on a feature * Disable new CI tests until bugs are fixed * adds support for getpeerinfo RPC * adds vector test * Always passes address_book to RpcServer * Update zebra-network/src/address_book.rs Co-authored-by: teor <[email protected]> * Renames PeerObserver to AddressBookPeers * adds getpeerinfo acceptance test * Asserts that addresses parse into SocketAddr * adds launches_lightwalletd field to TestType::LaunchWithEmptyState and uses it from the get_peer_info test * renames peer_observer mod * uses SocketAddr as `addr` field type in PeerInfo Co-authored-by: teor <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
dcf3067
commit 1bb8a9c
Showing
18 changed files
with
370 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//! A AddressBookPeers trait for getting the [`MetaAddr`] of recently live peers. | ||
use chrono::Utc; | ||
|
||
use crate::meta_addr::MetaAddr; | ||
|
||
#[cfg(any(test, feature = "proptest-impl"))] | ||
pub mod mock; | ||
|
||
#[cfg(any(test, feature = "proptest-impl"))] | ||
pub use mock::MockAddressBookPeers; | ||
|
||
/// Method signatures for getting [`MetaAddr`]s of recently live peers. | ||
pub trait AddressBookPeers { | ||
/// Return an Vec of peers we've seen recently, in reconnection attempt order. | ||
fn recently_live_peers(&self, now: chrono::DateTime<Utc>) -> Vec<MetaAddr>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Mock [`AddressBookPeers`] for use in tests. | ||
use crate::{meta_addr::MetaAddr, AddressBookPeers}; | ||
|
||
/// A mock [`AddressBookPeers`] implementation that's always empty. | ||
#[derive(Default, Clone)] | ||
pub struct MockAddressBookPeers { | ||
/// Return value for mock `recently_live_peers` method. | ||
recently_live_peers: Vec<MetaAddr>, | ||
} | ||
|
||
impl MockAddressBookPeers { | ||
/// Creates a new [`MockAddressBookPeers`] | ||
pub fn new(recently_live_peers: Vec<MetaAddr>) -> Self { | ||
Self { | ||
recently_live_peers, | ||
} | ||
} | ||
} | ||
|
||
impl AddressBookPeers for MockAddressBookPeers { | ||
fn recently_live_peers(&self, _now: chrono::DateTime<chrono::Utc>) -> Vec<MetaAddr> { | ||
self.recently_live_peers.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
zebra-rpc/src/methods/get_block_template_rpcs/types/peer_info.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//! An array of [`PeerInfo`] is the output of the `getpeerinfo` RPC method. | ||
use std::net::SocketAddr; | ||
|
||
use zebra_network::types::MetaAddr; | ||
|
||
/// Item of the `getpeerinfo` response | ||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] | ||
pub struct PeerInfo { | ||
/// The IP address and port of the peer | ||
pub addr: SocketAddr, | ||
} | ||
|
||
impl From<MetaAddr> for PeerInfo { | ||
fn from(meta_addr: MetaAddr) -> Self { | ||
Self { | ||
addr: meta_addr.addr(), | ||
} | ||
} | ||
} |
Oops, something went wrong.