Skip to content

Commit

Permalink
protos: change sync_height field in StatusResponse and StatusStreamRe…
Browse files Browse the repository at this point in the history
…sponse to full_sync_height and add a partial_sync_height field to support future partial sync functionality
  • Loading branch information
aubrika committed Nov 17, 2023
1 parent 024db06 commit cd109ff
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 45 deletions.
2 changes: 1 addition & 1 deletion crates/bin/pcli/src/command/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ impl TxCmd {
.as_mut()
.context("view service must be initialized")?;

let current_height = view.status(wallet_id).await?.sync_height;
let current_height = view.status(wallet_id).await?.full_sync_height;
let mut client = ChainQueryServiceClient::new(channel.clone());
let current_epoch = client
.epoch_by_height(EpochByHeightRequest {
Expand Down
6 changes: 3 additions & 3 deletions crates/bin/pcli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ impl App {

eprintln!(
"Scanning blocks from last sync height {} to latest height {}",
initial_status.sync_height, initial_status.latest_known_block_height,
initial_status.full_sync_height, initial_status.latest_known_block_height,
);

use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
let progress_bar = ProgressBar::with_draw_target(
initial_status.latest_known_block_height - initial_status.sync_height,
initial_status.latest_known_block_height - initial_status.full_sync_height,
ProgressDrawTarget::stdout(),
)
.with_style(
Expand All @@ -75,7 +75,7 @@ impl App {
progress_bar.set_position(0);

while let Some(status) = status_stream.next().await.transpose()? {
progress_bar.set_position(status.sync_height - initial_status.sync_height);
progress_bar.set_position(status.full_sync_height - initial_status.full_sync_height);
}
progress_bar.finish();

Expand Down
16 changes: 12 additions & 4 deletions crates/proto/src/gen/penumbra.view.v1alpha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,14 @@ pub struct StatusRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StatusResponse {
/// The height the view service has synchronized to so far
/// The height the view service has synchronized to so far when doing a full linear sync
#[prost(uint64, tag = "1")]
pub sync_height: u64,
pub full_sync_height: u64,
/// The height the view service has synchronized to so far when doing a partial sync
#[prost(uint64, tag = "2")]
pub partial_sync_height: u64,
/// Whether the view service is catching up with the chain state
#[prost(bool, tag = "2")]
#[prost(bool, tag = "3")]
pub catching_up: bool,
}
/// Requests streaming updates on the sync height until the view service is synchronized.
Expand All @@ -350,10 +353,15 @@ pub struct StatusStreamRequest {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct StatusStreamResponse {
/// The latest known block height
#[prost(uint64, tag = "1")]
pub latest_known_block_height: u64,
/// The height the view service has synchronized to so far when doing a full linear sync
#[prost(uint64, tag = "2")]
pub sync_height: u64,
pub full_sync_height: u64,
/// The height the view service has synchronized to so far when doing a partial sync
#[prost(uint64, tag = "3")]
pub partial_sync_height: u64,
}
/// A query for notes known by the view service.
///
Expand Down
94 changes: 68 additions & 26 deletions crates/proto/src/gen/penumbra.view.v1alpha1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3443,16 +3443,23 @@ impl serde::Serialize for StatusResponse {
{
use serde::ser::SerializeStruct;
let mut len = 0;
if self.sync_height != 0 {
if self.full_sync_height != 0 {
len += 1;
}
if self.partial_sync_height != 0 {
len += 1;
}
if self.catching_up {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1alpha1.StatusResponse", len)?;
if self.sync_height != 0 {
if self.full_sync_height != 0 {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("fullSyncHeight", ToString::to_string(&self.full_sync_height).as_str())?;
}
if self.partial_sync_height != 0 {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("syncHeight", ToString::to_string(&self.sync_height).as_str())?;
struct_ser.serialize_field("partialSyncHeight", ToString::to_string(&self.partial_sync_height).as_str())?;
}
if self.catching_up {
struct_ser.serialize_field("catchingUp", &self.catching_up)?;
Expand All @@ -3467,15 +3474,18 @@ impl<'de> serde::Deserialize<'de> for StatusResponse {
D: serde::Deserializer<'de>,
{
const FIELDS: &[&str] = &[
"sync_height",
"syncHeight",
"full_sync_height",
"fullSyncHeight",
"partial_sync_height",
"partialSyncHeight",
"catching_up",
"catchingUp",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
SyncHeight,
FullSyncHeight,
PartialSyncHeight,
CatchingUp,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand All @@ -3498,7 +3508,8 @@ impl<'de> serde::Deserialize<'de> for StatusResponse {
E: serde::de::Error,
{
match value {
"syncHeight" | "sync_height" => Ok(GeneratedField::SyncHeight),
"fullSyncHeight" | "full_sync_height" => Ok(GeneratedField::FullSyncHeight),
"partialSyncHeight" | "partial_sync_height" => Ok(GeneratedField::PartialSyncHeight),
"catchingUp" | "catching_up" => Ok(GeneratedField::CatchingUp),
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
}
Expand All @@ -3519,15 +3530,24 @@ impl<'de> serde::Deserialize<'de> for StatusResponse {
where
V: serde::de::MapAccess<'de>,
{
let mut sync_height__ = None;
let mut full_sync_height__ = None;
let mut partial_sync_height__ = None;
let mut catching_up__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::SyncHeight => {
if sync_height__.is_some() {
return Err(serde::de::Error::duplicate_field("syncHeight"));
GeneratedField::FullSyncHeight => {
if full_sync_height__.is_some() {
return Err(serde::de::Error::duplicate_field("fullSyncHeight"));
}
full_sync_height__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::PartialSyncHeight => {
if partial_sync_height__.is_some() {
return Err(serde::de::Error::duplicate_field("partialSyncHeight"));
}
sync_height__ =
partial_sync_height__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
Expand All @@ -3540,7 +3560,8 @@ impl<'de> serde::Deserialize<'de> for StatusResponse {
}
}
Ok(StatusResponse {
sync_height: sync_height__.unwrap_or_default(),
full_sync_height: full_sync_height__.unwrap_or_default(),
partial_sync_height: partial_sync_height__.unwrap_or_default(),
catching_up: catching_up__.unwrap_or_default(),
})
}
Expand Down Expand Up @@ -3651,17 +3672,24 @@ impl serde::Serialize for StatusStreamResponse {
if self.latest_known_block_height != 0 {
len += 1;
}
if self.sync_height != 0 {
if self.full_sync_height != 0 {
len += 1;
}
if self.partial_sync_height != 0 {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.view.v1alpha1.StatusStreamResponse", len)?;
if self.latest_known_block_height != 0 {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("latestKnownBlockHeight", ToString::to_string(&self.latest_known_block_height).as_str())?;
}
if self.sync_height != 0 {
if self.full_sync_height != 0 {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("fullSyncHeight", ToString::to_string(&self.full_sync_height).as_str())?;
}
if self.partial_sync_height != 0 {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("syncHeight", ToString::to_string(&self.sync_height).as_str())?;
struct_ser.serialize_field("partialSyncHeight", ToString::to_string(&self.partial_sync_height).as_str())?;
}
struct_ser.end()
}
Expand All @@ -3675,14 +3703,17 @@ impl<'de> serde::Deserialize<'de> for StatusStreamResponse {
const FIELDS: &[&str] = &[
"latest_known_block_height",
"latestKnownBlockHeight",
"sync_height",
"syncHeight",
"full_sync_height",
"fullSyncHeight",
"partial_sync_height",
"partialSyncHeight",
];

#[allow(clippy::enum_variant_names)]
enum GeneratedField {
LatestKnownBlockHeight,
SyncHeight,
FullSyncHeight,
PartialSyncHeight,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
Expand All @@ -3705,7 +3736,8 @@ impl<'de> serde::Deserialize<'de> for StatusStreamResponse {
{
match value {
"latestKnownBlockHeight" | "latest_known_block_height" => Ok(GeneratedField::LatestKnownBlockHeight),
"syncHeight" | "sync_height" => Ok(GeneratedField::SyncHeight),
"fullSyncHeight" | "full_sync_height" => Ok(GeneratedField::FullSyncHeight),
"partialSyncHeight" | "partial_sync_height" => Ok(GeneratedField::PartialSyncHeight),
_ => Err(serde::de::Error::unknown_field(value, FIELDS)),
}
}
Expand All @@ -3726,7 +3758,8 @@ impl<'de> serde::Deserialize<'de> for StatusStreamResponse {
V: serde::de::MapAccess<'de>,
{
let mut latest_known_block_height__ = None;
let mut sync_height__ = None;
let mut full_sync_height__ = None;
let mut partial_sync_height__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::LatestKnownBlockHeight => {
Expand All @@ -3737,19 +3770,28 @@ impl<'de> serde::Deserialize<'de> for StatusStreamResponse {
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::SyncHeight => {
if sync_height__.is_some() {
return Err(serde::de::Error::duplicate_field("syncHeight"));
GeneratedField::FullSyncHeight => {
if full_sync_height__.is_some() {
return Err(serde::de::Error::duplicate_field("fullSyncHeight"));
}
full_sync_height__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::PartialSyncHeight => {
if partial_sync_height__.is_some() {
return Err(serde::de::Error::duplicate_field("partialSyncHeight"));
}
sync_height__ =
partial_sync_height__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
}
}
Ok(StatusStreamResponse {
latest_known_block_height: latest_known_block_height__.unwrap_or_default(),
sync_height: sync_height__.unwrap_or_default(),
full_sync_height: full_sync_height__.unwrap_or_default(),
partial_sync_height: partial_sync_height__.unwrap_or_default(),
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
10 changes: 6 additions & 4 deletions crates/view/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ impl ViewService {

#[instrument(skip(self))]
pub async fn status(&self) -> anyhow::Result<StatusResponse> {
let sync_height = self.storage.last_sync_height().await?.unwrap_or(0);
let full_sync_height = self.storage.last_sync_height().await?.unwrap_or(0);

let (latest_known_block_height, node_catching_up) =
self.latest_known_block_height().await?;

let height_diff = latest_known_block_height
.checked_sub(sync_height)
.checked_sub(full_sync_height)
.ok_or_else(|| anyhow!("sync height ahead of node height"))?;

let catching_up = match (node_catching_up, height_diff) {
Expand All @@ -300,8 +300,9 @@ impl ViewService {
};

Ok(StatusResponse {
sync_height,
full_sync_height,
catching_up,
partial_sync_height: full_sync_height, // Set these as the same for backwards compatibility following adding the partial_sync_height
})
}
}
Expand Down Expand Up @@ -1048,7 +1049,8 @@ impl ViewProtocolService for ViewService {
while let Some(sync_height) = sync_height_stream.next().await {
yield pb::StatusStreamResponse {
latest_known_block_height,
sync_height,
full_sync_height: sync_height,
partial_sync_height: sync_height, // Set these as the same for backwards compatibility following adding the partial_sync_height
};
if sync_height >= latest_known_block_height {
break;
Expand Down
9 changes: 6 additions & 3 deletions crates/view/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use penumbra_proto::{view::v1alpha1 as pb, DomainType, TypeUrl};
#[derive(Clone, Copy, Debug)]
pub struct StatusStreamResponse {
pub latest_known_block_height: u64,
pub sync_height: u64,
pub full_sync_height: u64,
pub partial_sync_height: u64,
}

impl TypeUrl for StatusStreamResponse {
Expand All @@ -20,7 +21,8 @@ impl TryFrom<pb::StatusStreamResponse> for StatusStreamResponse {
fn try_from(proto: pb::StatusStreamResponse) -> Result<Self, Self::Error> {
Ok(StatusStreamResponse {
latest_known_block_height: proto.latest_known_block_height,
sync_height: proto.sync_height,
full_sync_height: proto.full_sync_height,
partial_sync_height: proto.partial_sync_height,
})
}
}
Expand All @@ -29,7 +31,8 @@ impl From<StatusStreamResponse> for pb::StatusStreamResponse {
fn from(msg: StatusStreamResponse) -> Self {
pb::StatusStreamResponse {
latest_known_block_height: msg.latest_known_block_height,
sync_height: msg.sync_height,
full_sync_height: msg.full_sync_height,
partial_sync_height: msg.partial_sync_height,
}
}
}
14 changes: 10 additions & 4 deletions proto/penumbra/penumbra/view/v1alpha1/view.proto
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,12 @@ message StatusRequest {

// Returns the status of the view service and whether it is synchronized with the chain state.
message StatusResponse {
// The height the view service has synchronized to so far
uint64 sync_height = 1;
// The height the view service has synchronized to so far when doing a full linear sync
uint64 full_sync_height = 1;
// The height the view service has synchronized to so far when doing a partial sync
uint64 partial_sync_height = 2;
// Whether the view service is catching up with the chain state
bool catching_up = 2;
bool catching_up = 3;
}

// Requests streaming updates on the sync height until the view service is synchronized.
Expand All @@ -301,8 +303,12 @@ message StatusStreamRequest {

// A streaming sync status update
message StatusStreamResponse {
// The latest known block height
uint64 latest_known_block_height = 1;
uint64 sync_height = 2;
// The height the view service has synchronized to so far when doing a full linear sync
uint64 full_sync_height = 2;
// The height the view service has synchronized to so far when doing a partial sync
uint64 partial_sync_height = 3;
}

// A query for notes known by the view service.
Expand Down

0 comments on commit cd109ff

Please sign in to comment.