Skip to content

Commit

Permalink
rest: properly expose the lowest available checkpoint watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jun 13, 2024
1 parent 5e86338 commit 34ac111
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 11 deletions.
8 changes: 7 additions & 1 deletion crates/simulacrum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use self::epoch_state::EpochState;
pub use self::store::in_mem_store::InMemoryStore;
use self::store::in_mem_store::KeyStore;
pub use self::store::SimulatorStore;
use sui_types::messages_checkpoint::CheckpointContents;
use sui_types::messages_checkpoint::{CheckpointContents, CheckpointSequenceNumber};
use sui_types::mock_checkpoint_builder::{MockCheckpointBuilder, ValidatorKeypairProvider};
use sui_types::{
gas_coin::GasCoin,
Expand Down Expand Up @@ -559,6 +559,12 @@ impl<T: Send + Sync, V: store::SimulatorStore + Send + Sync> RestStateReader for
todo!()
}

fn get_lowest_available_checkpoint_objects(
&self,
) -> sui_types::storage::error::Result<CheckpointSequenceNumber> {
Ok(0)
}

fn get_chain_identifier(
&self,
) -> sui_types::storage::error::Result<sui_types::digests::ChainIdentifier> {
Expand Down
3 changes: 3 additions & 0 deletions crates/sui-core/src/execution_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ pub trait ObjectCacheRead: Send + Sync {
_ => Ok(false),
}
}

/// Return the watermark for the highest checkpoint for which we've pruned objects.
fn get_highest_pruned_checkpoint(&self) -> SuiResult<CheckpointSequenceNumber>;
}

pub trait TransactionCacheRead: Send + Sync {
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-core/src/execution_cache/passthrough_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ impl ObjectCacheRead for PassthroughCache {
) -> SuiResult<Option<(SequenceNumber, MarkerValue)>> {
self.store.get_latest_marker(object_id, epoch_id)
}

fn get_highest_pruned_checkpoint(&self) -> SuiResult<CheckpointSequenceNumber> {
self.store.perpetual_tables.get_highest_pruned_checkpoint()
}
}

impl TransactionCacheRead for PassthroughCache {
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-core/src/execution_cache/proxy_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ impl ObjectCacheRead for ProxyCache {
) -> SuiResult<Option<(SequenceNumber, MarkerValue)>> {
delegate_method!(self.get_latest_marker(object_id, epoch_id))
}

fn get_highest_pruned_checkpoint(&self) -> SuiResult<CheckpointSequenceNumber> {
delegate_method!(self.get_highest_pruned_checkpoint())
}
}

impl TransactionCacheRead for ProxyCache {
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-core/src/execution_cache/writeback_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,10 @@ impl ObjectCacheRead for WritebackCache {
)?;
Ok(())
}

fn get_highest_pruned_checkpoint(&self) -> SuiResult<CheckpointSequenceNumber> {
self.store.perpetual_tables.get_highest_pruned_checkpoint()
}
}

impl TransactionCacheRead for WritebackCache {
Expand Down
10 changes: 10 additions & 0 deletions crates/sui-core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ impl RestStateReader for RestReadStore {
.map_err(StorageError::custom)
}

fn get_lowest_available_checkpoint_objects(
&self,
) -> sui_types::storage::error::Result<CheckpointSequenceNumber> {
self.state
.get_object_cache_reader()
.get_highest_pruned_checkpoint()
.map(|seq| seq + 1)
.map_err(StorageError::custom)
}

fn get_chain_identifier(
&self,
) -> sui_types::storage::error::Result<sui_types::digests::ChainIdentifier> {
Expand Down
12 changes: 9 additions & 3 deletions crates/sui-rest-api/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ pub async fn node_info(
State(state): State<RestService>,
) -> Result<ResponseContent<NodeInfo>> {
let latest_checkpoint = state.reader.inner().get_latest_checkpoint()?;
let oldest_checkpoint = state.reader.inner().get_lowest_available_checkpoint()?;
let lowest_available_checkpoint = state.reader.inner().get_lowest_available_checkpoint()?;
let lowest_available_checkpoint_objects = state
.reader
.inner()
.get_lowest_available_checkpoint_objects()?;

let response = NodeInfo {
checkpoint_height: latest_checkpoint.sequence_number,
oldest_checkpoint_height: oldest_checkpoint,
lowest_available_checkpoint,
lowest_available_checkpoint_objects,
timestamp_ms: latest_checkpoint.timestamp_ms,
epoch: latest_checkpoint.epoch(),
chain_id: state.chain_id(),
Expand All @@ -40,7 +45,8 @@ pub struct NodeInfo {
pub epoch: u64,
pub checkpoint_height: u64,
pub timestamp_ms: u64,
pub oldest_checkpoint_height: u64,
pub lowest_available_checkpoint: u64,
pub lowest_available_checkpoint_objects: u64,
pub software_version: Cow<'static, str>,
//TODO include current protocol version
}
23 changes: 19 additions & 4 deletions crates/sui-rest-api/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{
content_type::ContentType,
types::{
X_SUI_CHAIN, X_SUI_CHAIN_ID, X_SUI_CHECKPOINT_HEIGHT, X_SUI_EPOCH,
X_SUI_OLDEST_CHECKPOINT_HEIGHT, X_SUI_TIMESTAMP_MS,
X_SUI_LOWEST_AVAILABLE_CHECKPOINT, X_SUI_LOWEST_AVAILABLE_CHECKPOINT_OBJECTS,
X_SUI_TIMESTAMP_MS,
},
RestService, APPLICATION_BCS, TEXT_PLAIN_UTF_8,
};
Expand Down Expand Up @@ -129,12 +130,18 @@ pub async fn append_info_headers(
response: Response,
) -> impl IntoResponse {
let latest_checkpoint = state.reader.inner().get_latest_checkpoint().unwrap();
let oldest_checkpoint = state
let lowest_available_checkpoint = state
.reader
.inner()
.get_lowest_available_checkpoint()
.unwrap();

let lowest_available_checkpoint_objects = state
.reader
.inner()
.get_lowest_available_checkpoint_objects()
.unwrap();

let mut headers = HeaderMap::new();

headers.insert(
Expand Down Expand Up @@ -166,8 +173,16 @@ pub async fn append_info_headers(
.unwrap(),
);
headers.insert(
X_SUI_OLDEST_CHECKPOINT_HEIGHT,
oldest_checkpoint.to_string().try_into().unwrap(),
X_SUI_LOWEST_AVAILABLE_CHECKPOINT,
lowest_available_checkpoint.to_string().try_into().unwrap(),
);

headers.insert(
X_SUI_LOWEST_AVAILABLE_CHECKPOINT_OBJECTS,
lowest_available_checkpoint_objects
.to_string()
.try_into()
.unwrap(),
);

(headers, response)
Expand Down
17 changes: 15 additions & 2 deletions crates/sui-rest-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ pub const X_SUI_CHAIN: &str = "x-sui-chain";
/// Current checkpoint height
pub const X_SUI_CHECKPOINT_HEIGHT: &str = "x-sui-checkpoint-height";

/// Oldest non-pruned checkpoint height
pub const X_SUI_OLDEST_CHECKPOINT_HEIGHT: &str = "x-sui-oldest-checkpoint-height";
/// Lowest available checkpoint for which transaction and checkpoint data can be requested.
///
/// Specifically this is the lowest checkpoint for which the following data can be requested:
/// - checkpoints
/// - transactions
/// - effects
/// - events
pub const X_SUI_LOWEST_AVAILABLE_CHECKPOINT: &str = "x-sui-lowest-available-checkpoint";

/// Lowest available checkpoint for which object data can be requested.
///
/// Specifically this is the lowest checkpoint for which input/output object data will be
/// available.
pub const X_SUI_LOWEST_AVAILABLE_CHECKPOINT_OBJECTS: &str =
"x-sui-lowest-available-checkpoint-objects";

/// Current epoch of the chain
pub const X_SUI_EPOCH: &str = "x-sui-epoch";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@ impl RestStateReader for PersistedStoreInnerReadOnlyWrapper {
todo!()
}

fn get_lowest_available_checkpoint_objects(
&self,
) -> sui_types::storage::error::Result<CheckpointSequenceNumber> {
Ok(0)
}

fn get_chain_identifier(
&self,
) -> sui_types::storage::error::Result<sui_types::digests::ChainIdentifier> {
Expand Down
16 changes: 15 additions & 1 deletion crates/sui-types/src/storage/read_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ pub trait ReadStore: ObjectStore {
/// are guaranteed to be present in the store
fn get_highest_synced_checkpoint(&self) -> Result<VerifiedCheckpoint>;

/// The lowest available checkpoint that hasn't yet been pruned.
/// Lowest available checkpoint for which transaction and checkpoint data can be requested.
///
/// Specifically this is the lowest checkpoint for which the following data can be requested:
/// - checkpoints
/// - transactions
/// - effects
/// - events
///
/// For object availability see `get_lowest_available_checkpoint_objects`.
fn get_lowest_available_checkpoint(&self) -> Result<CheckpointSequenceNumber>;

fn get_checkpoint_by_digest(
Expand Down Expand Up @@ -639,5 +647,11 @@ pub trait RestStateReader: ObjectStore + ReadStore + Send + Sync {
digest: &TransactionDigest,
) -> Result<Option<CheckpointSequenceNumber>>;

/// Lowest available checkpoint for which object data can be requested.
///
/// Specifically this is the lowest checkpoint for which input/output object data will be
/// available.
fn get_lowest_available_checkpoint_objects(&self) -> Result<CheckpointSequenceNumber>;

fn get_chain_identifier(&self) -> Result<ChainIdentifier>;
}

0 comments on commit 34ac111

Please sign in to comment.