Skip to content
Open
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
15 changes: 12 additions & 3 deletions packages/zaino-fetch/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ and this library adheres to Rust's notion of
## [Unreleased]

### Added
- `JsonRpSeeConnector::get_tx_out_set_info` — JSON-RPC client method for the
upstream `gettxoutsetinfo` call.
- `jsonrpsee::response::GetTxOutSetInfoResponse` (`Info` | `Empty` untagged
- `JsonRpSeeConnector`: — JSON-RPC client method for the upstream calls.
- `get_tx_out_set_info` - RPC gettxoutsetinfo
- `get_chain_tips` - RPC getchaintips
- `get_tx_out` - RPC gettxout
- `get_spent_info` - RPC getspentinfo
- `jsonrpsee::response`
- `GetTxOutSetInfoResponse` (`Info` | `Empty` untagged
enum), `GetTxOutSetInfo` and `EmptyTxOutSetInfo` types covering both the
populated and stats-collection-failed shapes returned by zcashd.
- `chain_tip` mod containing `ChainTip`, `ChainTipStatus`, `GetChainTipsResponse`
- `GetTxOutResponse`
- `GetSpentInfoRequest`
- `GetSpentInfoResponse`, `GetSpentInfoError`

### Changed
### Deprecated
### Removed
Expand Down
2 changes: 2 additions & 0 deletions packages/zaino-proto/src/proto/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ pub fn compact_block_with_pool_types(
pub fn compact_block_to_nullifiers(mut block: CompactBlock) -> CompactBlock {
for ctransaction in &mut block.vtx {
ctransaction.outputs = Vec::new();
ctransaction.vin = Vec::new();
ctransaction.vout = Vec::new();
for caction in &mut ctransaction.actions {
*caction = CompactOrchardAction {
nullifier: caction.nullifier.clone(),
Expand Down
7 changes: 7 additions & 0 deletions packages/zaino-serve/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ and this library adheres to Rust's notion of
## [Unreleased]

### Added
- `rpc::grpc_routes` helper function to expose routes
without callers needing direct `zaino-proto` dependency
- `rpc::jsonrpc::service::ZcashIndexerRpc` new trait methods:
- `get_tx_out_set_info`
- `get_chain_tips`
- `get_tx_out`
- `get_spent_info`
### Changed
### Deprecated
### Removed
Expand Down
136 changes: 74 additions & 62 deletions packages/zaino-state/src/backends/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,75 +573,79 @@ impl ZcashIndexer for FetchServiceSubscriber {
&self,
hash_or_height: String,
) -> Result<GetTreestateResponse, Self::Error> {
let hash_or_height_struct: HashOrHeight = HashOrHeight::from_str(&hash_or_height)?;
let snapshot = self.indexer.snapshot_nonfinalized_state().await?;

let block_data = match hash_or_height_struct {
HashOrHeight::Hash(hash) => self
.indexer
.get_indexed_block_by_hash(&snapshot, &hash.into())
.await
.map_err(|_error| {
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
))
})?
.ok_or(
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
)),
)?,
HashOrHeight::Height(height) => self
.indexer
.get_indexed_block_by_height(&snapshot, &height.into())
.await
.map_err(|_error| {
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
))
})?
.ok_or(
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
)),
)?,
};
let fallback_hash_or_height = hash_or_height.clone();
let local_result: Result<GetTreestateResponse, Self::Error> = async {
let hash_or_height_struct: HashOrHeight = HashOrHeight::from_str(&hash_or_height)?;
let snapshot = self.indexer.snapshot_nonfinalized_state().await?;

let block_data = match hash_or_height_struct {
HashOrHeight::Hash(hash) => self
.indexer
.get_indexed_block_by_hash(&snapshot, &hash.into())
.await?
.ok_or(
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
)),
)?,
HashOrHeight::Height(height) => self
.indexer
.get_indexed_block_by_height(&snapshot, &height.into())
.await?
.ok_or(
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
)),
)?,
};

let (sapling, orchard) = self
.indexer
.get_treestate(block_data.hash())
.await
.map_err(|_error| {
let (sapling, orchard) = self.indexer.get_treestate(block_data.hash()).await?;
let time: u32 = block_data.data().time().try_into().map_err(|_error| {
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch treestate.",
"Block time is out of range for u32.",
))
})?;
let time: u32 = block_data.data().time().try_into().map_err(|_error| {

#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Block time is out of range for u32.",
Ok(GetTreestateResponse::from_parts(
(*block_data.hash()).into(),
block_data.height().into(),
time,
sapling,
orchard,
))
})?;
}
.await;

#[allow(deprecated)]
Ok(GetTreestateResponse::from_parts(
(*block_data.hash()).into(),
block_data.height().into(),
time,
sapling,
orchard,
))
if let Ok(response) = local_result {
return Ok(response);
}

self.fetcher
.get_treestate(fallback_hash_or_height)
.await
.map_err(|_error| {
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch treestate.",
))
})
.and_then(|treestate| {
treestate.try_into().map_err(|_error| {
#[allow(deprecated)]
FetchServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to parse treestate.",
))
})
})
}

/// Returns information about a range of Sapling or Orchard subtrees.
Expand Down Expand Up @@ -932,7 +936,11 @@ impl LightWalletIndexer for FetchServiceSubscriber {

match self
.indexer
.get_compact_block(&snapshot, types::Height(height), PoolTypeFilter::default())
.get_compact_block(
&snapshot,
types::Height(height),
PoolTypeFilter::includes_all(),
)
.await
{
Ok(Some(block)) => Ok(block),
Expand Down Expand Up @@ -1007,7 +1015,11 @@ impl LightWalletIndexer for FetchServiceSubscriber {
};
match self
.indexer
.get_compact_block(&snapshot, types::Height(height), PoolTypeFilter::default())
.get_compact_block(
&snapshot,
types::Height(height),
PoolTypeFilter::includes_all(),
)
.await
{
Ok(Some(block)) => Ok(compact_block_to_nullifiers(block)),
Expand Down
101 changes: 53 additions & 48 deletions packages/zaino-state/src/backends/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,65 +1378,70 @@ impl ZcashIndexer for StateServiceSubscriber {
&self,
hash_or_height: String,
) -> Result<GetTreestateResponse, Self::Error> {
let hash_or_height_struct: HashOrHeight = HashOrHeight::from_str(&hash_or_height)?;
let snapshot = self.indexer.snapshot_nonfinalized_state().await?;
let fallback_hash_or_height = hash_or_height.clone();
let local_result: Result<GetTreestateResponse, Self::Error> = async {
let hash_or_height_struct: HashOrHeight = HashOrHeight::from_str(&hash_or_height)?;
let snapshot = self.indexer.snapshot_nonfinalized_state().await?;

let block_data = match hash_or_height_struct {
HashOrHeight::Hash(hash) => self
.indexer
.get_indexed_block_by_hash(&snapshot, &hash.into())
.await
.map_err(|_error| {
StateServiceError::RpcError(RpcError::new_from_legacycode(
let block_data = match hash_or_height_struct {
HashOrHeight::Hash(hash) => self
.indexer
.get_indexed_block_by_hash(&snapshot, &hash.into())
.await?
.ok_or(StateServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
))
})?
.ok_or(StateServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
)))?,
HashOrHeight::Height(height) => self
.indexer
.get_indexed_block_by_height(&snapshot, &height.into())
.await
.map_err(|_error| {
StateServiceError::RpcError(RpcError::new_from_legacycode(
)))?,
HashOrHeight::Height(height) => self
.indexer
.get_indexed_block_by_height(&snapshot, &height.into())
.await?
.ok_or(StateServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
))
})?
.ok_or(StateServiceError::RpcError(RpcError::new_from_legacycode(
)))?,
};

let (sapling, orchard) = self.indexer.get_treestate(block_data.hash()).await?;
let time: u32 = block_data.data().time().try_into().map_err(|_error| {
StateServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch block data.",
)))?,
};
"Block time is out of range for u32.",
))
})?;

let (sapling, orchard) = self
.indexer
.get_treestate(block_data.hash())
#[allow(deprecated)]
Ok(GetTreestateResponse::from_parts(
(*block_data.hash()).into(),
block_data.height().into(),
time,
sapling,
orchard,
))
}
.await;

if let Ok(response) = local_result {
return Ok(response);
}

self.rpc_client
.get_treestate(fallback_hash_or_height)
.await
.map_err(|_error| {
StateServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to fetch treestate.",
))
})?;
let time: u32 = block_data.data().time().try_into().map_err(|_error| {
StateServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Block time is out of range for u32.",
))
})?;

#[allow(deprecated)]
Ok(GetTreestateResponse::from_parts(
(*block_data.hash()).into(),
block_data.height().into(),
time,
sapling,
orchard,
))
})
.and_then(|treestate| {
treestate.try_into().map_err(|_error| {
StateServiceError::RpcError(RpcError::new_from_legacycode(
zebra_rpc::server::error::LegacyCode::InvalidParameter,
"Failed to parse treestate.",
))
})
})
}

async fn get_mining_info(&self) -> Result<GetMiningInfoWire, Self::Error> {
Expand Down Expand Up @@ -1914,7 +1919,7 @@ impl LightWalletIndexer for StateServiceSubscriber {

match self
.indexer
.get_compact_block(&snapshot, block_height, PoolTypeFilter::default())
.get_compact_block(&snapshot, block_height, PoolTypeFilter::includes_all())
.await
{
Ok(Some(block)) => Ok(block),
Expand Down Expand Up @@ -1979,7 +1984,7 @@ impl LightWalletIndexer for StateServiceSubscriber {

match self
.indexer
.get_compact_block(&snapshot, block_height, PoolTypeFilter::default())
.get_compact_block(&snapshot, block_height, PoolTypeFilter::includes_all())
.await
{
Ok(Some(block)) => Ok(compact_block_to_nullifiers(block)),
Expand Down
Loading
Loading