Skip to content

Commit

Permalink
git ls-tree --full-tree -r --name-only HEAD | xargs sed -i -e 's/rout…
Browse files Browse the repository at this point in the history
…er_verifier/block_verifier_router/g'

cargo fmt --all
  • Loading branch information
teor2345 committed Jun 19, 2023
1 parent 0da2dcb commit a56d8b4
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 126 deletions.
26 changes: 13 additions & 13 deletions book/src/dev/diagrams/service-dependencies.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions book/src/dev/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ digraph services {
inbound -> state
rpc_server -> state
mempool -> transaction_verifier
router_verifier -> checkpoint_verifier
block_verifier_router -> checkpoint_verifier
inbound -> mempool
rpc_server -> mempool
inbound -> router_verifier
syncer -> router_verifier
rpc_server -> router_verifier [style=dotted]
inbound -> block_verifier_router
syncer -> block_verifier_router
rpc_server -> block_verifier_router [style=dotted]
syncer -> peer_set
mempool -> peer_set
block_verifier -> state
checkpoint_verifier -> state
block_verifier -> transaction_verifier
router_verifier -> block_verifier
block_verifier_router -> block_verifier
rpc_server -> inbound [style=invis] // for layout of the diagram
}
Expand Down
52 changes: 33 additions & 19 deletions zebra-consensus/src/router/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ async fn verifiers_from_network(
+ 'static,
) {
let state_service = zs::init_test(network);
let (router_verifier, _transaction_verifier, _groth16_download_handle, _max_checkpoint_height) =
crate::router::init(Config::default(), network, state_service.clone(), true).await;
let (
block_verifier_router,
_transaction_verifier,
_groth16_download_handle,
_max_checkpoint_height,
) = crate::router::init(Config::default(), network, state_service.clone(), true).await;

// We can drop the download task handle here, because:
// - if the download task fails, the tests will panic, and
// - if the download task hangs, the tests will hang.

(router_verifier, state_service)
(block_verifier_router, state_service)
}

static BLOCK_VERIFY_TRANSCRIPT_GENESIS: Lazy<
Expand Down Expand Up @@ -165,15 +169,19 @@ async fn verify_checkpoint(config: Config) -> Result<(), Report> {
// init_from_verifiers.
//
// Download task panics and timeouts are propagated to the tests that use Groth16 verifiers.
let (router_verifier, _transaction_verifier, _groth16_download_handle, _max_checkpoint_height) =
super::init(config.clone(), network, zs::init_test(network), true).await;
let (
block_verifier_router,
_transaction_verifier,
_groth16_download_handle,
_max_checkpoint_height,
) = super::init(config.clone(), network, zs::init_test(network), true).await;

// Add a timeout layer
let router_verifier =
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(router_verifier);
let block_verifier_router =
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(block_verifier_router);

let transcript = Transcript::from(BLOCK_VERIFY_TRANSCRIPT_GENESIS.iter().cloned());
transcript.check(router_verifier).await.unwrap();
transcript.check(block_verifier_router).await.unwrap();

Ok(())
}
Expand All @@ -194,11 +202,11 @@ async fn verify_fail_no_coinbase() -> Result<(), Report> {
let (router, state_service) = verifiers_from_network(Network::Mainnet).await;

// Add a timeout layer
let router_verifier =
let block_verifier_router =
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(router);

let transcript = Transcript::from(NO_COINBASE_TRANSCRIPT.iter().cloned());
transcript.check(router_verifier).await.unwrap();
transcript.check(block_verifier_router).await.unwrap();

let transcript = Transcript::from(NO_COINBASE_STATE_TRANSCRIPT.iter().cloned());
transcript.check(state_service).await.unwrap();
Expand All @@ -216,14 +224,14 @@ async fn round_trip_checkpoint_test() -> Result<(), Report> {
async fn round_trip_checkpoint() -> Result<(), Report> {
let _init_guard = zebra_test::init();

let (router_verifier, state_service) = verifiers_from_network(Network::Mainnet).await;
let (block_verifier_router, state_service) = verifiers_from_network(Network::Mainnet).await;

// Add a timeout layer
let router_verifier =
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(router_verifier);
let block_verifier_router =
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(block_verifier_router);

let transcript = Transcript::from(BLOCK_VERIFY_TRANSCRIPT_GENESIS.iter().cloned());
transcript.check(router_verifier).await.unwrap();
transcript.check(block_verifier_router).await.unwrap();

let transcript = Transcript::from(STATE_VERIFY_TRANSCRIPT_GENESIS.iter().cloned());
transcript.check(state_service).await.unwrap();
Expand All @@ -241,20 +249,26 @@ async fn verify_fail_add_block_checkpoint_test() -> Result<(), Report> {
async fn verify_fail_add_block_checkpoint() -> Result<(), Report> {
let _init_guard = zebra_test::init();

let (router_verifier, state_service) = verifiers_from_network(Network::Mainnet).await;
let (block_verifier_router, state_service) = verifiers_from_network(Network::Mainnet).await;

// Add a timeout layer
let router_verifier =
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(router_verifier);
let block_verifier_router =
TimeoutLayer::new(Duration::from_secs(VERIFY_TIMEOUT_SECONDS)).layer(block_verifier_router);

let transcript = Transcript::from(BLOCK_VERIFY_TRANSCRIPT_GENESIS.iter().cloned());
transcript.check(router_verifier.clone()).await.unwrap();
transcript
.check(block_verifier_router.clone())
.await
.unwrap();

let transcript = Transcript::from(STATE_VERIFY_TRANSCRIPT_GENESIS.iter().cloned());
transcript.check(state_service.clone()).await.unwrap();

let transcript = Transcript::from(BLOCK_VERIFY_TRANSCRIPT_GENESIS_FAIL.iter().cloned());
transcript.check(router_verifier.clone()).await.unwrap();
transcript
.check(block_verifier_router.clone())
.await
.unwrap();

let transcript = Transcript::from(STATE_VERIFY_TRANSCRIPT_GENESIS.iter().cloned());
transcript.check(state_service.clone()).await.unwrap();
Expand Down
14 changes: 7 additions & 7 deletions zebra-rpc/src/methods/get_block_template_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ pub struct GetBlockTemplateRpcImpl<
latest_chain_tip: Tip,

/// The chain verifier, used for submitting blocks.
router_verifier: BlockVerifierRouter,
block_verifier_router: BlockVerifierRouter,

/// The chain sync status, used for checking if Zebra is likely close to the network chain tip.
sync_status: SyncStatus,
Expand Down Expand Up @@ -319,7 +319,7 @@ where
mempool: Buffer<Mempool, mempool::Request>,
state: State,
latest_chain_tip: Tip,
router_verifier: BlockVerifierRouter,
block_verifier_router: BlockVerifierRouter,
sync_status: SyncStatus,
address_book: AddressBook,
) -> Self {
Expand Down Expand Up @@ -358,7 +358,7 @@ where
mempool,
state,
latest_chain_tip,
router_verifier,
block_verifier_router,
sync_status,
address_book,
}
Expand Down Expand Up @@ -454,7 +454,7 @@ where
.and_then(get_block_template::JsonParameters::block_proposal_data)
{
return validate_block_proposal(
self.router_verifier.clone(),
self.block_verifier_router.clone(),
block_proposal_bytes,
network,
latest_chain_tip,
Expand Down Expand Up @@ -737,7 +737,7 @@ where
HexData(block_bytes): HexData,
_parameters: Option<submit_block::JsonParameters>,
) -> BoxFuture<Result<submit_block::Response>> {
let mut router_verifier = self.router_verifier.clone();
let mut block_verifier_router = self.block_verifier_router.clone();

async move {
let block: Block = match block_bytes.zcash_deserialize_into() {
Expand All @@ -755,7 +755,7 @@ where
.unwrap_or_else(|| "invalid coinbase height".to_string());
let block_hash = block.hash();

let router_verifier_response = router_verifier
let block_verifier_router_response = block_verifier_router
.ready()
.await
.map_err(|error| Error {
Expand All @@ -766,7 +766,7 @@ where
.call(zebra_consensus::Request::Commit(Arc::new(block)))
.await;

let chain_error = match router_verifier_response {
let chain_error = match block_verifier_router_response {
// Currently, this match arm returns `null` (Accepted) for blocks committed
// to any chain, but Accepted is only for blocks in the best chain.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn check_miner_address(
///
/// Returns a `getblocktemplate` [`Response`].
pub async fn validate_block_proposal<BlockVerifierRouter, Tip, SyncStatus>(
mut router_verifier: BlockVerifierRouter,
mut block_verifier_router: BlockVerifierRouter,
block_proposal_bytes: Vec<u8>,
network: Network,
latest_chain_tip: Tip,
Expand Down Expand Up @@ -129,7 +129,7 @@ where
}
};

let router_verifier_response = router_verifier
let block_verifier_router_response = block_verifier_router
.ready()
.await
.map_err(|error| Error {
Expand All @@ -140,12 +140,12 @@ where
.call(zebra_consensus::Request::CheckProposal(Arc::new(block)))
.await;

Ok(router_verifier_response
Ok(block_verifier_router_response
.map(|_hash| ProposalResponse::Valid)
.unwrap_or_else(|verify_chain_error| {
tracing::info!(
?verify_chain_error,
"error response from router_verifier in CheckProposal request"
"error response from block_verifier_router in CheckProposal request"
);

ProposalResponse::rejected("invalid proposal", verify_chain_error)
Expand Down
22 changes: 12 additions & 10 deletions zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub async fn test_responses<State, ReadState>(
<ReadState as Service<zebra_state::ReadRequest>>::Future: Send,
{
let (
router_verifier,
block_verifier_router,
_transaction_verifier,
_parameter_download_task_handle,
_max_checkpoint_height,
Expand Down Expand Up @@ -145,7 +145,7 @@ pub async fn test_responses<State, ReadState>(
Buffer::new(mempool.clone(), 1),
read_state,
mock_chain_tip.clone(),
router_verifier.clone(),
block_verifier_router.clone(),
mock_sync_status.clone(),
mock_address_book,
);
Expand Down Expand Up @@ -267,7 +267,7 @@ pub async fn test_responses<State, ReadState>(
Buffer::new(mempool.clone(), 1),
read_state.clone(),
mock_chain_tip.clone(),
router_verifier,
block_verifier_router,
mock_sync_status.clone(),
MockAddressBookPeers::default(),
);
Expand Down Expand Up @@ -365,16 +365,16 @@ pub async fn test_responses<State, ReadState>(

snapshot_rpc_getblocktemplate("invalid-proposal", get_block_template, None, &settings);

// the following snapshots use a mock read_state and router_verifier
// the following snapshots use a mock read_state and block_verifier_router

let mut mock_router_verifier = MockService::build().for_unit_tests();
let mut mock_block_verifier_router = MockService::build().for_unit_tests();
let get_block_template_rpc_mock_state_verifier = GetBlockTemplateRpcImpl::new(
network,
mining_config,
Buffer::new(mempool.clone(), 1),
read_state.clone(),
mock_chain_tip,
mock_router_verifier.clone(),
mock_block_verifier_router.clone(),
mock_sync_status,
MockAddressBookPeers::default(),
);
Expand All @@ -387,15 +387,17 @@ pub async fn test_responses<State, ReadState>(
}),
);

let mock_router_verifier_request_handler = async move {
mock_router_verifier
let mock_block_verifier_router_request_handler = async move {
mock_block_verifier_router
.expect_request_that(|req| matches!(req, zebra_consensus::Request::CheckProposal(_)))
.await
.respond(Hash::from([0; 32]));
};

let (get_block_template, ..) =
tokio::join!(get_block_template_fut, mock_router_verifier_request_handler,);
let (get_block_template, ..) = tokio::join!(
get_block_template_fut,
mock_block_verifier_router_request_handler,
);

let get_block_template =
get_block_template.expect("unexpected error in getblocktemplate RPC call");
Expand Down
Loading

0 comments on commit a56d8b4

Please sign in to comment.