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

Implement Get block nullifiers #85

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 51 additions & 1 deletion zaino-fetch/src/chain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::{
};
use sha2::{Digest, Sha256};
use std::io::Cursor;
use zaino_proto::proto::compact_formats::{ChainMetadata, CompactBlock};
use zaino_proto::proto::compact_formats::{
ChainMetadata, CompactBlock, CompactOrchardAction, CompactTx,
};

/// A block header, containing metadata about a block.
///
Expand Down Expand Up @@ -428,3 +430,51 @@ pub async fn get_block_from_node(
Err(e) => Err(e.into()),
}
}

/// Returns a compact block holding only action nullifiers.
///
/// Retrieves a full block from zebrad/zcashd using 2 get_block calls.
/// This is because a get_block verbose = 1 call is require to fetch txids.
///
/// TODO / NOTE: This should be rewritten when the BlockCache is added.
pub async fn get_nullifiers_from_node(
zebra_uri: &http::Uri,
height: &u32,
) -> Result<CompactBlock, BlockCacheError> {
match get_block_from_node(zebra_uri, height).await {
Ok(block) => Ok(CompactBlock {
proto_version: block.proto_version,
height: block.height,
hash: block.hash,
prev_hash: block.prev_hash,
time: block.time,
header: block.header,
vtx: block
.vtx
.into_iter()
.map(|tx| CompactTx {
index: tx.index,
hash: tx.hash,
fee: tx.fee,
spends: tx.spends,
outputs: Vec::new(),
actions: tx
.actions
.into_iter()
.map(|action| CompactOrchardAction {
nullifier: action.nullifier,
cmx: Vec::new(),
ephemeral_key: Vec::new(),
ciphertext: Vec::new(),
})
.collect(),
})
.collect(),
chain_metadata: Some(ChainMetadata {
sapling_commitment_tree_size: 0,
orchard_commitment_tree_size: 0,
}),
}),
Err(e) => Err(e.into()),
}
}
19 changes: 14 additions & 5 deletions zaino-serve/src/rpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use tokio_stream::wrappers::ReceiverStream;

use crate::{rpc::GrpcClient, utils::get_build_info};
use zaino_fetch::{
chain::{block::get_block_from_node, mempool::Mempool},
chain::{
block::{get_block_from_node, get_nullifiers_from_node},
mempool::Mempool,
},
jsonrpc::{connector::JsonRpcConnector, response::GetTransactionResponse},
};
use zaino_proto::proto::{
Expand Down Expand Up @@ -156,11 +159,10 @@ impl CompactTxStreamer for GrpcClient {

/// Same as GetBlock except actions contain only nullifiers.
///
/// This RPC has not been implemented as it is not currently used by zingolib.
/// If you require this RPC please open an issue or PR at the Zingo-Indexer github (https://github.com/zingolabs/zingo-indexer).
/// NOTE: This should be reimplemented with the introduction of the BlockCache.
fn get_block_nullifiers<'life0, 'async_trait>(
&'life0 self,
_request: tonic::Request<BlockId>,
request: tonic::Request<BlockId>,
) -> core::pin::Pin<
Box<
dyn core::future::Future<
Expand All @@ -175,7 +177,14 @@ impl CompactTxStreamer for GrpcClient {
{
println!("[TEST] Received call of get_block_nullifiers.");
Box::pin(async {
Err(tonic::Status::unimplemented("get_block_nullifiers not yet implemented. If you require this RPC please open an issue or PR at the Zingo-Indexer github (https://github.com/zingolabs/zingo-indexer)."))
let zebrad_uri = self.zebrad_uri.clone();
let height = request.into_inner().height as u32;
match get_nullifiers_from_node(&zebrad_uri, &height).await {
Ok(block) => Ok(tonic::Response::new(block)),
Err(e) => {
return Err(tonic::Status::internal(e.to_string()));
}
}
})
}

Expand Down
Loading