Skip to content

Commit

Permalink
[data-sim] easy: use sync over async for store (MystenLabs#14350)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxade authored Oct 20, 2023
1 parent 8059c44 commit 420b599
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 66 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/simulacrum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ edition = "2021"

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
bcs.workspace = true
fastcrypto.workspace = true
move-binary-format.workspace = true
Expand Down
106 changes: 42 additions & 64 deletions crates/simulacrum/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,167 +410,145 @@ impl KeyStore {
}
}

#[async_trait::async_trait]
pub trait SimulatorStore:
sui_types::storage::BackingPackageStore
+ sui_types::storage::ObjectStore
+ sui_types::storage::ReceivedMarkerQuery
{
async fn get_checkpoint_by_sequence_number(
fn get_checkpoint_by_sequence_number(
&self,
sequence_number: CheckpointSequenceNumber,
) -> Option<&VerifiedCheckpoint>;

async fn get_checkpoint_by_digest(
&self,
digest: &CheckpointDigest,
) -> Option<&VerifiedCheckpoint>;
fn get_checkpoint_by_digest(&self, digest: &CheckpointDigest) -> Option<&VerifiedCheckpoint>;

async fn get_highest_checkpint(&self) -> Option<&VerifiedCheckpoint>;
async fn get_checkpoint_contents(
fn get_highest_checkpint(&self) -> Option<&VerifiedCheckpoint>;
fn get_checkpoint_contents(
&self,
digest: &CheckpointContentsDigest,
) -> Option<&CheckpointContents>;

async fn get_committee_by_epoch(&self, epoch: EpochId) -> Option<&Committee>;
fn get_committee_by_epoch(&self, epoch: EpochId) -> Option<&Committee>;

async fn get_transaction(&self, digest: &TransactionDigest) -> Option<&VerifiedTransaction>;
fn get_transaction(&self, digest: &TransactionDigest) -> Option<&VerifiedTransaction>;

async fn get_transaction_effects(
&self,
digest: &TransactionDigest,
) -> Option<&TransactionEffects>;
async fn get_transaction_events(
fn get_transaction_effects(&self, digest: &TransactionDigest) -> Option<&TransactionEffects>;
fn get_transaction_events(
&self,
digest: &TransactionEventsDigest,
) -> Option<&TransactionEvents>;

async fn get_object(&self, id: &ObjectID) -> Option<&Object>;
async fn get_object_at_version(
&self,
id: &ObjectID,
version: SequenceNumber,
) -> Option<&Object>;
fn get_object(&self, id: &ObjectID) -> Option<&Object>;
fn get_object_at_version(&self, id: &ObjectID, version: SequenceNumber) -> Option<&Object>;

async fn get_system_state(&self) -> sui_types::sui_system_state::SuiSystemState;
fn get_system_state(&self) -> sui_types::sui_system_state::SuiSystemState;

async fn get_clock(&self) -> sui_types::clock::Clock;
fn get_clock(&self) -> sui_types::clock::Clock;

async fn owned_objects(&self, owner: SuiAddress) -> Box<dyn Iterator<Item = &Object> + '_>;
fn owned_objects(&self, owner: SuiAddress) -> Box<dyn Iterator<Item = &Object> + '_>;

async fn insert_checkpoint(&mut self, checkpoint: VerifiedCheckpoint);
fn insert_checkpoint(&mut self, checkpoint: VerifiedCheckpoint);

async fn insert_checkpoint_contents(&mut self, contents: CheckpointContents);
fn insert_checkpoint_contents(&mut self, contents: CheckpointContents);

async fn insert_committee(&mut self, committee: Committee);
fn insert_committee(&mut self, committee: Committee);

async fn insert_executed_transaction(
fn insert_executed_transaction(
&mut self,
transaction: VerifiedTransaction,
effects: TransactionEffects,
events: TransactionEvents,
written_objects: BTreeMap<ObjectID, Object>,
);

async fn insert_transaction(&mut self, transaction: VerifiedTransaction);
fn insert_transaction(&mut self, transaction: VerifiedTransaction);

async fn insert_transaction_effects(&mut self, effects: TransactionEffects);
fn insert_transaction_effects(&mut self, effects: TransactionEffects);

async fn insert_events(&mut self, events: TransactionEvents);
fn insert_events(&mut self, events: TransactionEvents);

async fn update_objects(
fn update_objects(
&mut self,
written_objects: BTreeMap<ObjectID, Object>,
deleted_objects: Vec<(ObjectID, SequenceNumber, ObjectDigest)>,
);
}

#[async_trait::async_trait]
impl SimulatorStore for InMemoryStore {
async fn get_checkpoint_by_sequence_number(
fn get_checkpoint_by_sequence_number(
&self,
sequence_number: CheckpointSequenceNumber,
) -> Option<&VerifiedCheckpoint> {
self.get_checkpoint_by_sequence_number(sequence_number)
}

async fn get_checkpoint_by_digest(
&self,
digest: &CheckpointDigest,
) -> Option<&VerifiedCheckpoint> {
fn get_checkpoint_by_digest(&self, digest: &CheckpointDigest) -> Option<&VerifiedCheckpoint> {
self.get_checkpoint_by_digest(digest)
}

async fn get_highest_checkpint(&self) -> Option<&VerifiedCheckpoint> {
fn get_highest_checkpint(&self) -> Option<&VerifiedCheckpoint> {
self.get_highest_checkpint()
}

async fn get_checkpoint_contents(
fn get_checkpoint_contents(
&self,
digest: &CheckpointContentsDigest,
) -> Option<&CheckpointContents> {
self.get_checkpoint_contents(digest)
}

async fn get_committee_by_epoch(&self, epoch: EpochId) -> Option<&Committee> {
fn get_committee_by_epoch(&self, epoch: EpochId) -> Option<&Committee> {
self.get_committee_by_epoch(epoch)
}

async fn get_transaction(&self, digest: &TransactionDigest) -> Option<&VerifiedTransaction> {
fn get_transaction(&self, digest: &TransactionDigest) -> Option<&VerifiedTransaction> {
self.get_transaction(digest)
}

async fn get_transaction_effects(
&self,
digest: &TransactionDigest,
) -> Option<&TransactionEffects> {
fn get_transaction_effects(&self, digest: &TransactionDigest) -> Option<&TransactionEffects> {
self.get_transaction_effects(digest)
}

async fn get_transaction_events(
fn get_transaction_events(
&self,
digest: &TransactionEventsDigest,
) -> Option<&TransactionEvents> {
self.get_transaction_events(digest)
}

async fn get_object(&self, id: &ObjectID) -> Option<&Object> {
fn get_object(&self, id: &ObjectID) -> Option<&Object> {
self.get_object(id)
}

async fn get_object_at_version(
&self,
id: &ObjectID,
version: SequenceNumber,
) -> Option<&Object> {
fn get_object_at_version(&self, id: &ObjectID, version: SequenceNumber) -> Option<&Object> {
self.get_object_at_version(id, version)
}

async fn get_system_state(&self) -> sui_types::sui_system_state::SuiSystemState {
fn get_system_state(&self) -> sui_types::sui_system_state::SuiSystemState {
self.get_system_state()
}

async fn get_clock(&self) -> sui_types::clock::Clock {
fn get_clock(&self) -> sui_types::clock::Clock {
self.get_clock()
}

async fn owned_objects(&self, owner: SuiAddress) -> Box<dyn Iterator<Item = &Object> + '_> {
fn owned_objects(&self, owner: SuiAddress) -> Box<dyn Iterator<Item = &Object> + '_> {
Box::new(self.owned_objects(owner))
}

async fn insert_checkpoint(&mut self, checkpoint: VerifiedCheckpoint) {
fn insert_checkpoint(&mut self, checkpoint: VerifiedCheckpoint) {
self.insert_checkpoint(checkpoint)
}

async fn insert_checkpoint_contents(&mut self, contents: CheckpointContents) {
fn insert_checkpoint_contents(&mut self, contents: CheckpointContents) {
self.insert_checkpoint_contents(contents)
}

async fn insert_committee(&mut self, committee: Committee) {
fn insert_committee(&mut self, committee: Committee) {
self.insert_committee(committee)
}

async fn insert_executed_transaction(
fn insert_executed_transaction(
&mut self,
transaction: VerifiedTransaction,
effects: TransactionEffects,
Expand All @@ -580,19 +558,19 @@ impl SimulatorStore for InMemoryStore {
self.insert_executed_transaction(transaction, effects, events, written_objects)
}

async fn insert_transaction(&mut self, transaction: VerifiedTransaction) {
fn insert_transaction(&mut self, transaction: VerifiedTransaction) {
self.insert_transaction(transaction)
}

async fn insert_transaction_effects(&mut self, effects: TransactionEffects) {
fn insert_transaction_effects(&mut self, effects: TransactionEffects) {
self.insert_transaction_effects(effects)
}

async fn insert_events(&mut self, events: TransactionEvents) {
fn insert_events(&mut self, events: TransactionEvents) {
self.insert_events(events)
}

async fn update_objects(
fn update_objects(
&mut self,
written_objects: BTreeMap<ObjectID, Object>,
deleted_objects: Vec<(ObjectID, SequenceNumber, ObjectDigest)>,
Expand Down

0 comments on commit 420b599

Please sign in to comment.