Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
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
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 @@ -550,75 +550,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 @@ -888,7 +892,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 @@ -963,7 +971,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 @@ -1374,65 +1374,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 @@ -1869,7 +1874,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 @@ -1934,7 +1939,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