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

sim data source 2/x: impl node state getter for simulacrum #14187

Merged
merged 2 commits into from
Oct 11, 2023
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ mysten-util-mem = { path = "crates/mysten-util-mem" }
mysten-util-mem-derive = { path = "crates/mysten-util-mem-derive" }
prometheus-closure-metric = { path = "crates/prometheus-closure-metric" }
shared-crypto = { path = "crates/shared-crypto" }
simulacrum = { path = "crates/simulacrum" }
sui = { path = "crates/sui" }
sui-adapter-transactional-tests = { path = "crates/sui-adapter-transactional-tests" }
sui-analytics-indexer = { path = "crates/sui-analytics-indexer" }
Expand Down
2 changes: 2 additions & 0 deletions crates/sui-rest-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ serde.workspace = true
bcs.workspace = true
reqwest.workspace = true
axum.workspace = true
rand.workspace = true
simulacrum.workspace = true
sui-types.workspace = true
sui-core.workspace = true
workspace-hack.workspace = true
Expand Down
90 changes: 90 additions & 0 deletions crates/sui-rest-api/src/node_state_getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use sui_core::authority::AuthorityState;
use sui_types::error::UserInputError;
use sui_types::{
base_types::{ObjectID, VersionNumber},
digests::{TransactionDigest, TransactionEventsDigest},
Expand Down Expand Up @@ -118,3 +119,92 @@ impl NodeStateGetter for AuthorityState {
self.database.get_object(object_id)
}
}

impl<T: Sync + Send> NodeStateGetter for simulacrum::Simulacrum<T> {
fn get_verified_checkpoint_by_sequence_number(
&self,
sequence_number: CheckpointSequenceNumber,
) -> SuiResult<VerifiedCheckpoint> {
self.store()
.get_checkpoint_by_sequence_number(sequence_number)
.cloned()
.ok_or(SuiError::UserInputError {
error: UserInputError::VerifiedCheckpointNotFound(sequence_number),
})
}

fn get_latest_checkpoint_sequence_number(&self) -> SuiResult<CheckpointSequenceNumber> {
Ok(self
.store()
.get_highest_checkpint()
.map(|checkpoint| *checkpoint.sequence_number())
.unwrap_or(0))
}

fn get_checkpoint_contents(
&self,
content_digest: CheckpointContentsDigest,
) -> SuiResult<CheckpointContents> {
self.store()
.get_checkpoint_contents(&content_digest)
.cloned()
.ok_or(SuiError::UserInputError {
error: UserInputError::CheckpointContentsNotFound(content_digest),
})
}

fn multi_get_transaction_blocks(
&self,
tx_digests: &[TransactionDigest],
) -> SuiResult<Vec<Option<VerifiedTransaction>>> {
Ok(tx_digests
.iter()
.map(|digest| self.store().get_transaction(digest).cloned())
.collect())
}

fn multi_get_executed_effects(
&self,
digests: &[TransactionDigest],
) -> SuiResult<Vec<Option<TransactionEffects>>> {
Ok(digests
.iter()
.map(|digest| self.store().get_transaction_effects(digest).cloned())
.collect())
}

fn multi_get_events(
&self,
event_digests: &[TransactionEventsDigest],
) -> SuiResult<Vec<Option<TransactionEvents>>> {
Ok(event_digests
.iter()
.map(|digest| self.store().get_transaction_events(digest).cloned())
.collect())
}

fn multi_get_object_by_key(
&self,
object_keys: &[ObjectKey],
) -> Result<Vec<Option<Object>>, SuiError> {
object_keys
.iter()
.map(|key| ObjectStore::get_object_by_key(&self.store(), &key.0, key.1))
.collect::<Result<Vec<_>, SuiError>>()
}

fn get_object_by_key(
&self,
object_id: &ObjectID,
version: VersionNumber,
) -> Result<Option<Object>, SuiError> {
Ok(self
.store()
.get_object_at_version(object_id, version)
.cloned())
}

fn get_object(&self, object_id: &ObjectID) -> Result<Option<Object>, SuiError> {
ObjectStore::get_object(&self.store(), object_id)
}
}
Loading