Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
81a8e1c
chore(`getblockheader`): initial passthrough
dorianvp Oct 15, 2025
a5dfd9e
chore(`getblockheader`): add `fetch_service` and unit tests
dorianvp Oct 15, 2025
30c83cf
chore(`getblockheader`): add `state_service` test
dorianvp Oct 16, 2025
63f0c55
chore(`getblockheader`): use `zebra_rpc` types
dorianvp Oct 16, 2025
2eaec55
chore(`getblockheader`): fix `block_header` test
dorianvp Oct 17, 2025
54dae0e
chore(`getblockheader`): fix `block_header` tests
dorianvp Oct 17, 2025
529ec8e
chore(`getblockheader`): expose endpoint & add `json_server` test
dorianvp Oct 17, 2025
d737092
chore(`getblockheader`): run clippy
dorianvp Oct 17, 2025
3cd901e
chore(`getblockheader`): re-export surface types
dorianvp Oct 17, 2025
55e6e53
chore(`getblockheader`): fix doc comments
dorianvp Oct 17, 2025
ca4a280
docs(`getblockheader`): add doc comments
dorianvp Oct 20, 2025
05a0343
Merge branch 'dev' into feat/rpc-getblockheader
dorianvp Oct 22, 2025
63684a0
Merge branch 'dev' into feat/rpc-getblockheader
dorianvp Oct 25, 2025
1c36d02
Merge branch 'dev' into feat/rpc-getblockheader
ala-mode Oct 28, 2025
af79de8
Merge branch 'dev' into feat/rpc-getblockheader
ala-mode Oct 30, 2025
ff8df88
resolve postmerge breakage
ala-mode Oct 30, 2025
de55be3
Merge branch 'dev' into feat/rpc-getblockheader
dorianvp Oct 30, 2025
497a030
chore(`getblockheader`): more tests & comments
dorianvp Oct 31, 2025
8dc98d1
chore(`getblockheader`): fix test
dorianvp Oct 31, 2025
d9dce55
Merge branch 'dev' into feat/rpc-getblockheader
dorianvp Nov 1, 2025
97113f9
chore(`getblockheader`): remove `extra` fields
dorianvp Nov 2, 2025
7a6de96
chore(`getblockheader`): remove invalid `finalorchardroot` field
dorianvp Nov 2, 2025
14bd76a
Merge branch 'dev' into feat/rpc-getblockheader
zancas Nov 4, 2025
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
72 changes: 72 additions & 0 deletions integration-tests/tests/fetch_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,68 @@ async fn fetch_service_get_block(validator: &ValidatorKind) {
test_manager.close().await;
}

async fn fetch_service_get_block_header(validator: &ValidatorKind) {
let (test_manager, _fetch_service, fetch_service_subscriber) =
create_test_manager_and_fetch_service(validator, None, true, true, true).await;

const BLOCK_LIMIT: u32 = 10;

for i in 0..BLOCK_LIMIT {
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;

let block = fetch_service_subscriber
.z_get_block(i.to_string(), Some(1))
.await
.unwrap();

let block_hash = match block {
GetBlock::Object(block) => block.hash(),
GetBlock::Raw(_) => panic!("Expected block object"),
};

let fetch_service_get_block_header = fetch_service_subscriber
.get_block_header(block_hash.to_string(), false)
.await
.unwrap();

let jsonrpc_client = JsonRpSeeConnector::new_with_basic_auth(
test_node_and_return_url(
test_manager.full_node_rpc_listen_address,
None,
Some("xxxxxx".to_string()),
Some("xxxxxx".to_string()),
)
.await
.unwrap(),
"xxxxxx".to_string(),
"xxxxxx".to_string(),
)
.unwrap();

let rpc_block_header_response = jsonrpc_client
.get_block_header(block_hash.to_string(), false)
.await
.unwrap();

let fetch_service_get_block_header_verbose = fetch_service_subscriber
.get_block_header(block_hash.to_string(), true)
.await
.unwrap();

let rpc_block_header_response_verbose = jsonrpc_client
.get_block_header(block_hash.to_string(), true)
.await
.unwrap();

assert_eq!(fetch_service_get_block_header, rpc_block_header_response);
assert_eq!(
fetch_service_get_block_header_verbose,
rpc_block_header_response_verbose
);
}
}

async fn fetch_service_get_best_blockhash(validator: &ValidatorKind) {
let (mut test_manager, _fetch_service, fetch_service_subscriber) =
create_test_manager_and_fetch_service(validator, None, true, true, true).await;
Expand Down Expand Up @@ -1557,6 +1619,11 @@ mod zcashd {
fetch_service_get_block(&ValidatorKind::Zcashd).await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
pub(crate) async fn block_header() {
fetch_service_get_block_header(&ValidatorKind::Zcashd).await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
pub(crate) async fn difficulty() {
assert_fetch_service_difficulty_matches_rpc(&ValidatorKind::Zcashd).await;
Expand Down Expand Up @@ -1772,6 +1839,11 @@ mod zebrad {
fetch_service_get_block(&ValidatorKind::Zebrad).await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
pub(crate) async fn block_header() {
fetch_service_get_block_header(&ValidatorKind::Zebrad).await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
pub(crate) async fn difficulty() {
assert_fetch_service_difficulty_matches_rpc(&ValidatorKind::Zebrad).await;
Expand Down
41 changes: 41 additions & 0 deletions integration-tests/tests/json_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ mod zcashd {
use super::*;

pub(crate) mod zcash_indexer {
use zebra_rpc::methods::GetBlock;

use super::*;

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down Expand Up @@ -789,6 +791,45 @@ mod zcashd {
z_get_block_inner().await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_block_header() {
let (
test_manager,
_zcashd_service,
zcashd_subscriber,
_zaino_service,
zaino_subscriber,
) = create_test_manager_and_fetch_services(false).await;

const BLOCK_LIMIT: u32 = 10;

for i in 0..BLOCK_LIMIT {
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;

let block = zcashd_subscriber
.z_get_block(i.to_string(), Some(1))
.await
.unwrap();

let block_hash = match block {
GetBlock::Object(block) => block.hash(),
GetBlock::Raw(_) => panic!("Expected block object"),
};

let zcashd_get_block_header = zcashd_subscriber
.get_block_header(block_hash.to_string(), false)
.await
.unwrap();

let zainod_block_header_response = zaino_subscriber
.get_block_header(block_hash.to_string(), false)
.await
.unwrap();
assert_eq!(zcashd_get_block_header, zainod_block_header_response);
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_raw_mempool() {
get_raw_mempool_inner().await;
Expand Down
51 changes: 50 additions & 1 deletion integration-tests/tests/state_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ mod zebrad {
use zaino_proto::proto::service::{
AddressList, BlockId, BlockRange, GetAddressUtxosArg, GetSubtreeRootsArg, TxFilter,
};
use zebra_rpc::methods::GetAddressTxIdsRequest;
use zebra_rpc::methods::{GetAddressTxIdsRequest, GetBlock};

use super::*;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down Expand Up @@ -1607,6 +1607,55 @@ mod zebrad {
assert_eq!(state_service_block_by_hash, state_service_block_by_height)
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_block_header() {
let (
test_manager,
_fetch_service,
fetch_service_subscriber,
_state_service,
state_service_subscriber,
) = create_test_manager_and_services(
&ValidatorKind::Zebrad,
None,
false,
false,
Some(NetworkKind::Regtest),
)
.await;

const BLOCK_LIMIT: u32 = 10;

for i in 0..BLOCK_LIMIT {
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;

let block = fetch_service_subscriber
.z_get_block(i.to_string(), Some(1))
.await
.unwrap();

let block_hash = match block {
GetBlock::Object(block) => block.hash(),
GetBlock::Raw(_) => panic!("Expected block object"),
};

let fetch_service_get_block_header = fetch_service_subscriber
.get_block_header(block_hash.to_string(), false)
.await
.unwrap();

let state_service_block_header_response = state_service_subscriber
.get_block_header(block_hash.to_string(), false)
.await
.unwrap();
assert_eq!(
fetch_service_get_block_header,
state_service_block_header_response
);
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_tree_state() {
let (
Expand Down
28 changes: 27 additions & 1 deletion zaino-fetch/src/jsonrpsee/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use zebra_rpc::client::ValidateAddressResponse;
use crate::jsonrpsee::{
error::{JsonRpcError, TransportError},
response::{
block_subsidy::GetBlockSubsidy, mining_info::GetMiningInfoWire, peer_info::GetPeerInfo,
block_header::{GetBlockHeader, GetBlockHeaderError},
block_subsidy::GetBlockSubsidy,
mining_info::GetMiningInfoWire,
peer_info::GetPeerInfo,
GetBalanceError, GetBalanceResponse, GetBlockCountResponse, GetBlockError, GetBlockHash,
GetBlockResponse, GetBlockchainInfoResponse, GetInfoResponse, GetMempoolInfoResponse,
GetSubtreesError, GetSubtreesResponse, GetTransactionResponse, GetTreestateError,
Expand Down Expand Up @@ -541,6 +544,29 @@ impl JsonRpSeeConnector {
}
}

/// If verbose is false, returns a string that is serialized, hex-encoded data for blockheader `hash`.
/// If verbose is true, returns an Object with information about blockheader `hash`.
///
/// # Parameters
///
/// - hash: (string, required) The block hash
/// - verbose: (boolean, optional, default=true) true for a json object, false for the hex encoded data
///
/// zcashd reference: [`getblockheader`](https://zcash.github.io/rpc/getblockheader.html)
/// method: post
/// tags: blockchain
pub async fn get_block_header(
&self,
hash: String,
verbose: bool,
) -> Result<GetBlockHeader, RpcRequestError<GetBlockHeaderError>> {
let params = [
serde_json::to_value(hash).map_err(RpcRequestError::JsonRpc)?,
serde_json::to_value(verbose).map_err(RpcRequestError::JsonRpc)?,
];
self.send_request("getblockheader", params).await
}

/// Returns the hash of the best block (tip) of the longest chain.
/// zcashd reference: [`getbestblockhash`](https://zcash.github.io/rpc/getbestblockhash.html)
/// method: post
Expand Down
3 changes: 2 additions & 1 deletion zaino-fetch/src/jsonrpsee/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//! These types are redefined rather than imported from zebra_rpc
//! to prevent locking consumers into a zebra_rpc version

pub mod block_header;
pub mod block_subsidy;
mod common;
pub mod common;
pub mod mining_info;
pub mod peer_info;

Expand Down
Loading
Loading