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

change(rpc): Add getpeerinfo RPC method #5951

Merged
merged 58 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
37d5afd
adds ValidateBlock request to state
arya2 Dec 15, 2022
6eb6048
adds `Request` enum in block verifier
arya2 Dec 15, 2022
162dedb
uses new Request in references to chain verifier
arya2 Dec 15, 2022
f7c5941
adds getblocktemplate proposal mode response type
arya2 Dec 15, 2022
9e0b8d1
makes getblocktemplate-rpcs feature in zebra-consensus select getbloc…
arya2 Dec 15, 2022
8420b75
Adds PR review revisions
arya2 Dec 16, 2022
e3b6d28
adds info log in CheckBlockProposalValidity
arya2 Dec 16, 2022
95cea02
Reverts replacement of match statement
arya2 Dec 16, 2022
31472a8
adds `GetBlockTemplate::capabilities` fn
arya2 Dec 16, 2022
ba302f7
conditions calling checkpoint verifier on !request.is_proposal
arya2 Dec 16, 2022
02b6758
updates references to validate_and_commit_non_finalized
arya2 Dec 16, 2022
2faa823
adds snapshot test, updates test vectors
arya2 Dec 16, 2022
32e6ac9
adds `should_count_metrics` to NonFinalizedState
arya2 Dec 16, 2022
a2ae3fb
Returns an error from chain verifier for block proposal requests belo…
arya2 Dec 16, 2022
40d002a
adds "proposal" to GET_BLOCK_TEMPLATE_CAPABILITIES_FIELD
arya2 Dec 17, 2022
1b658a1
Merge branch 'main' into gbt-proposal-mode
arya2 Dec 19, 2022
da1b308
adds back block::Request to zebra-consensus lib
arya2 Dec 19, 2022
cb26b8a
updates snapshots
arya2 Dec 19, 2022
78e95d9
Removes unnecessary network arg
arya2 Dec 22, 2022
0c55a67
skips req in tracing intstrument for read state
arya2 Dec 22, 2022
616d280
Moves out block proposal validation to its own fn
arya2 Dec 22, 2022
8978541
corrects `difficulty_threshold_is_valid` docs
arya2 Dec 23, 2022
4551cf0
Update zebra-state/src/service.rs
arya2 Jan 5, 2023
e888039
Merge branch 'main' into gbt-proposal-mode
arya2 Jan 5, 2023
5cc7378
Apply suggestions from code review
arya2 Jan 10, 2023
67bf095
Update zebra-rpc/src/methods/get_block_template_rpcs.rs
arya2 Jan 10, 2023
f774822
check best chain tip
arya2 Jan 9, 2023
d75e17a
Update zebra-state/src/service.rs
arya2 Jan 10, 2023
9ce7d8a
Applies cleanup suggestions from code review
arya2 Jan 10, 2023
8b89cba
updates gbt acceptance test to make a block proposal
arya2 Dec 19, 2022
0bf81c7
fixes json parsing mistake
arya2 Dec 19, 2022
1d043b1
adds retries
arya2 Dec 22, 2022
da54e85
returns reject reason if there are no retries left
arya2 Dec 22, 2022
ee0fc0b
moves result deserialization to RPCRequestClient method, adds docs, m…
arya2 Jan 2, 2023
a6ac270
moves sleep(EXPECTED_TX_TIME) out of loop
arya2 Jan 2, 2023
d58d474
updates/adds info logs in retry loop
arya2 Jan 2, 2023
f105b58
Revert "moves sleep(EXPECTED_TX_TIME) out of loop"
arya2 Jan 2, 2023
fc4bd13
adds `allow(dead_code)`
arya2 Jan 3, 2023
509f890
Merge branch 'main' into gbt-proposal-test
mergify[bot] Jan 12, 2023
516f17c
tests with curtime, mintime, & maxtime
arya2 Jan 12, 2023
60c7a13
Fixes doc comment
arya2 Jan 12, 2023
d2cae99
Logs error responses from chain_verifier CheckProposal requests
arya2 Jan 13, 2023
bb32c52
Removes retry loop, adds num_txs log
arya2 Jan 13, 2023
71c335f
removes verbose info log
arya2 Jan 13, 2023
f052448
sorts mempool_txs before generating merkle root
arya2 Jan 13, 2023
dc3f2fc
Merge branch 'fix-gbt-merkle-root' into gbt-proposal-test
arya2 Jan 13, 2023
8c51e13
Make imports conditional on a feature
arya2 Jan 16, 2023
dd2438b
Disable new CI tests until bugs are fixed
arya2 Jan 16, 2023
632fca6
adds support for getpeerinfo RPC
arya2 Jan 4, 2023
c24b618
adds vector test
arya2 Jan 6, 2023
836ba74
Always passes address_book to RpcServer
arya2 Jan 13, 2023
8f597a4
Update zebra-network/src/address_book.rs
arya2 Jan 16, 2023
4bf183e
Renames PeerObserver to AddressBookPeers
arya2 Jan 16, 2023
7b72395
adds getpeerinfo acceptance test
arya2 Jan 17, 2023
493412f
Asserts that addresses parse into SocketAddr
arya2 Jan 17, 2023
e80940e
adds launches_lightwalletd field to TestType::LaunchWithEmptyState an…
arya2 Jan 17, 2023
6c56341
renames peer_observer mod
arya2 Jan 17, 2023
f58b0f1
uses SocketAddr as `addr` field type in PeerInfo
arya2 Jan 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moves out block proposal validation to its own fn
  • Loading branch information
arya2 committed Dec 22, 2022
commit 616d2809736e5573c23e919c405b4875d02aee3a
39 changes: 9 additions & 30 deletions zebra-rpc/src/methods/get_block_template_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ use crate::methods::{
DEFAULT_SOLUTION_RATE_WINDOW_SIZE, GET_BLOCK_TEMPLATE_MEMPOOL_LONG_POLL_INTERVAL,
},
get_block_template::{
check_get_block_template_parameters, check_miner_address, check_synced_to_tip,
fetch_mempool_transactions, fetch_state_tip_and_local_time,
generate_coinbase_and_roots,
check_miner_address, check_synced_to_tip, fetch_mempool_transactions,
fetch_state_tip_and_local_time, generate_coinbase_and_roots, validate_block_proposal,
},
types::{
get_block_template::GetBlockTemplate, get_mining_info, hex_data::HexData,
Expand Down Expand Up @@ -331,43 +330,23 @@ where
let mut latest_chain_tip = self.latest_chain_tip.clone();
let sync_status = self.sync_status.clone();
let state = self.state.clone();
let mut chain_verifier = self.chain_verifier.clone();
let chain_verifier = self.chain_verifier.clone();

// To implement long polling correctly, we split this RPC into multiple phases.
async move {
check_get_block_template_parameters(&parameters)?;

let client_long_poll_id = parameters
.as_mut()
.and_then(|params| params.long_poll_id.take());
get_block_template::check_parameters(&parameters)?;

if let Some(HexData(block_proposal_bytes)) = parameters
.as_mut()
.and_then(get_block_template::JsonParameters::block_proposal_data)
{
let block: Block = match block_proposal_bytes.zcash_deserialize_into() {
Ok(block_bytes) => block_bytes,
Err(_) => return Ok(get_block_template::ProposalRejectReason::Rejected.into()),
};

let chain_verifier_response = chain_verifier
.ready()
.await
.map_err(|error| Error {
code: ErrorCode::ServerError(0),
message: error.to_string(),
data: None,
})?
.call(zebra_consensus::Request::CheckProposal(Arc::new(block)))
.await;

let response = chain_verifier_response
.map(|_| get_block_template::ProposalResponse::Valid)
.unwrap_or_else(|_| get_block_template::ProposalRejectReason::Rejected.into());

return Ok(response.into());
return validate_block_proposal(chain_verifier, block_proposal_bytes).await;
}

let client_long_poll_id = parameters
.as_mut()
.and_then(|params| params.long_poll_id.take());

// - One-off checks

// Check config and parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ use tower::{Service, ServiceExt};
use zebra_chain::{
amount::{self, Amount, NegativeOrZero, NonNegative},
block::{
self,
merkle::{self, AuthDataRoot},
ChainHistoryBlockTxAuthCommitmentHash, Height,
},
chain_sync_status::ChainSyncStatus,
chain_tip::ChainTip,
parameters::Network,
serialization::ZcashDeserializeInto,
transaction::{Transaction, UnminedTx, VerifiedUnminedTx},
transparent,
};
Expand All @@ -35,7 +37,7 @@ pub use crate::methods::get_block_template_rpcs::types::get_block_template::*;
/// Checks that `data` is omitted in `Template` mode or provided in `Proposal` mode,
///
/// Returns an error if there's a mismatch between the mode and whether `data` is provided.
pub fn check_get_block_template_parameters(parameters: &Option<JsonParameters>) -> Result<()> {
pub fn check_parameters(parameters: &Option<JsonParameters>) -> Result<()> {
let Some(parameters) = parameters else {
return Ok(())
};
Expand Down Expand Up @@ -91,6 +93,42 @@ pub fn check_miner_address(
})
}

/// Attempts to validate block proposal against all of the server's
/// usual acceptance rules (except proof-of-work).
///
/// Returns a `getblocktemplate` [`Response`].
pub async fn validate_block_proposal<ChainVerifier>(
mut chain_verifier: ChainVerifier,
block_proposal_bytes: Vec<u8>,
) -> Result<Response>
where
ChainVerifier: Service<zebra_consensus::Request, Response = block::Hash, Error = zebra_consensus::BoxError>
+ Clone
+ Send
+ Sync
+ 'static,
{
let Ok(block) = block_proposal_bytes.zcash_deserialize_into() else {
return Ok(ProposalRejectReason::Rejected.into())
};

let chain_verifier_response = chain_verifier
.ready()
.await
.map_err(|error| Error {
code: ErrorCode::ServerError(0),
message: error.to_string(),
data: None,
})?
.call(zebra_consensus::Request::CheckProposal(Arc::new(block)))
.await;

Ok(chain_verifier_response
.map(|_| ProposalResponse::Valid)
.unwrap_or_else(|_| ProposalRejectReason::Rejected.into())
.into())
}

// - State and syncer checks

/// Returns an error if Zebra is not synced to the consensus chain tip.
Expand Down