Skip to content

Commit

Permalink
types: move InputObjects into the types crate
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jul 8, 2022
1 parent e6401eb commit 85a6173
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 116 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

12 changes: 5 additions & 7 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ use chrono::prelude::*;
use move_binary_format::CompiledModule;
use move_bytecode_utils::module_cache::SyncModuleCache;
use move_core_types::{
account_address::AccountAddress,
ident_str,
language_storage::{ModuleId, StructTag},
resolver::{ModuleResolver, ResourceResolver},
account_address::AccountAddress, ident_str, language_storage::ModuleId,
resolver::ModuleResolver,
};
use move_vm_runtime::{move_vm::MoveVM, native_functions::NativeFunctionTable};
use narwhal_executor::ExecutionStateError;
Expand All @@ -32,7 +30,7 @@ use prometheus::{
};
use std::ops::Deref;
use std::{
collections::{BTreeMap, HashMap, HashSet, VecDeque},
collections::{HashMap, HashSet, VecDeque},
pin::Pin,
sync::{
atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering},
Expand All @@ -53,10 +51,10 @@ use sui_types::{
committee::Committee,
crypto::AuthoritySignature,
error::{SuiError, SuiResult},
fp_bail, fp_ensure,
fp_ensure,
gas::SuiGasStatus,
messages::*,
object::{Data, Object, ObjectFormatOptions, ObjectRead},
object::{Object, ObjectFormatOptions, ObjectRead},
storage::{BackingPackageStore, DeleteKind, Storage},
MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS, SUI_SYSTEM_STATE_OBJECT_ID,
};
Expand Down
9 changes: 4 additions & 5 deletions crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
use std::iter;
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use super::*;
use crate::epoch::EpochInfoLocals;
use crate::gateway_state::GatewayTxSeqNumber;
use crate::transaction_input_checker::InputObjects;
use narwhal_executor::ExecutionIndices;
use rocksdb::Options;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use std::iter;
use std::path::Path;
use std::sync::atomic::AtomicU64;
use sui_storage::{
default_db_options,
mutex_table::{LockGuard, MutexTable},
write_ahead_log::DBWriteAheadLog,
LockService,
};
use tokio::sync::Notify;

use std::sync::atomic::AtomicU64;
use sui_types::base_types::SequenceNumber;
use sui_types::batch::{SignedBatch, TxSequenceNumber};
use sui_types::committee::EpochId;
use sui_types::crypto::{AuthoritySignInfo, EmptySignInfo};
use sui_types::object::{Owner, OBJECT_START_VERSION};
use tokio::sync::Notify;
use tokio_retry::strategy::{jitter, ExponentialBackoff};
use tracing::{debug, error, info, trace};
use typed_store::rocks::{DBBatch, DBMap};
Expand Down
17 changes: 13 additions & 4 deletions crates/sui-core/src/authority/temporary_store.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
use crate::transaction_input_checker::InputObjects;

use move_core_types::account_address::AccountAddress;
use sui_types::error::ExecutionError;
use move_core_types::language_storage::{ModuleId, StructTag};
use move_core_types::resolver::{ModuleResolver, ResourceResolver};
use std::collections::{BTreeMap, HashSet};
use std::sync::Arc;
use sui_types::base_types::{
ObjectDigest, ObjectID, ObjectRef, SequenceNumber, SuiAddress, TransactionDigest,
};
use sui_types::error::{ExecutionError, SuiError};
use sui_types::fp_bail;
use sui_types::messages::{ExecutionStatus, InputObjects, TransactionEffects};
use sui_types::object::{Data, Object};
use sui_types::storage::{BackingPackageStore, DeleteKind, Storage};
use sui_types::{
event::Event,
gas::{GasCostSummary, SuiGasStatus},
object::Owner,
};

use super::*;

pub type InnerTemporaryStore = (
BTreeMap<ObjectID, Object>,
Vec<ObjectRef>,
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-core/src/epoch/tests/reconfiguration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ use sui_types::{
crypto::{get_key_pair, AuthoritySignature, Signature},
error::SuiError,
gas::SuiGasStatus,
messages::{SignatureAggregator, Transaction, TransactionData},
messages::{InputObjects, SignatureAggregator, Transaction, TransactionData},
object::Object,
SUI_SYSTEM_STATE_OBJECT_ID,
};

use crate::gateway_state::GatewayMetrics;
use crate::{
authority::AuthorityTemporaryStore, authority_active::ActiveAuthority,
authority_aggregator::authority_aggregator_tests::init_local_authorities,
checkpoints::CheckpointLocals, epoch::reconfiguration::CHECKPOINT_COUNT_PER_EPOCH,
execution_engine,
};
use crate::{gateway_state::GatewayMetrics, transaction_input_checker::InputObjects};

#[tokio::test]
async fn test_start_epoch_change() {
Expand Down
2 changes: 0 additions & 2 deletions crates/sui-core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ use sui_json_rpc_api::rpc_types::{
TransactionResponse, TransferObjectParams,
};

use crate::transaction_input_checker::InputObjects;

#[cfg(test)]
#[path = "unit_tests/gateway_state_tests.rs"]
mod gateway_state_tests;
Expand Down
97 changes: 7 additions & 90 deletions crates/sui-core/src/transaction_input_checker.rs
Original file line number Diff line number Diff line change
@@ -1,104 +1,21 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::collections::{BTreeMap, BTreeSet, HashSet};

use crate::authority::SuiDataStore;
use prometheus::IntCounter;
use serde::{Deserialize, Serialize};
use sui_types::base_types::TransactionDigest;
use std::collections::HashSet;
use sui_types::{
base_types::{ObjectID, ObjectRef, SequenceNumber, SuiAddress},
base_types::{ObjectID, SequenceNumber, SuiAddress},
error::{SuiError, SuiResult},
fp_ensure,
gas::{self, SuiGasStatus},
messages::{InputObjectKind, SingleTransactionKind, TransactionData, TransactionEnvelope},
messages::{
InputObjectKind, InputObjects, SingleTransactionKind, TransactionData, TransactionEnvelope,
},
object::{Object, Owner},
};
use tracing::{debug, instrument};

use crate::authority::SuiDataStore;

pub struct InputObjects {
objects: Vec<(InputObjectKind, Object)>,
}

impl InputObjects {
pub fn new(objects: Vec<(InputObjectKind, Object)>) -> Self {
Self { objects }
}

pub fn len(&self) -> usize {
self.objects.len()
}

pub fn is_empty(&self) -> bool {
self.objects.is_empty()
}

pub fn filter_owned_objects(&self) -> Vec<ObjectRef> {
let owned_objects: Vec<_> = self
.objects
.iter()
.filter_map(|(object_kind, object)| match object_kind {
InputObjectKind::MovePackage(_) => None,
InputObjectKind::ImmOrOwnedMoveObject(object_ref) => {
if object.is_immutable() {
None
} else {
Some(*object_ref)
}
}
InputObjectKind::SharedMoveObject(_) => None,
})
.collect();

debug!(
num_mutable_objects = owned_objects.len(),
"Checked locks and found mutable objects"
);

owned_objects
}

pub fn filter_shared_objects(&self) -> Vec<ObjectRef> {
self.objects
.iter()
.filter(|(kind, _)| matches!(kind, InputObjectKind::SharedMoveObject(_)))
.map(|(_, obj)| obj.compute_object_reference())
.collect()
}

pub fn transaction_dependencies(&self) -> BTreeSet<TransactionDigest> {
self.objects
.iter()
.map(|(_, obj)| obj.previous_transaction)
.collect()
}

pub fn mutable_inputs(&self) -> Vec<ObjectRef> {
self.objects
.iter()
.filter_map(|(kind, object)| match kind {
InputObjectKind::MovePackage(_) => None,
InputObjectKind::ImmOrOwnedMoveObject(object_ref) => {
if object.is_immutable() {
None
} else {
Some(*object_ref)
}
}
InputObjectKind::SharedMoveObject(_) => Some(object.compute_object_reference()),
})
.collect()
}

pub fn into_object_map(self) -> BTreeMap<ObjectID, Object> {
self.objects
.into_iter()
.map(|(_, object)| (object.id(), object))
.collect()
}
}
use tracing::instrument;

#[instrument(level = "trace", skip_all)]
pub async fn check_transaction_input<S, T>(
Expand Down
7 changes: 4 additions & 3 deletions crates/sui-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ use move_core_types::{
};
use narwhal_executor::ExecutionIndices;
use rand::{prelude::StdRng, SeedableRng};
use std::collections::BTreeMap;
use std::fs;
use std::{convert::TryInto, env};
use sui_adapter::genesis;
use sui_types::object::Data;
use sui_types::{
base_types::dbg_addr,
crypto::KeyPair,
Expand All @@ -24,9 +28,6 @@ use sui_types::{
SUI_SYSTEM_STATE_OBJECT_ID,
};

use std::fs;
use std::{convert::TryInto, env};

pub enum TestCallArg {
Object(ObjectID),
U64(u64),
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-transactional-test-runner/src/test_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use std::{
sync::Arc,
};
use sui_adapter::{adapter::new_move_vm, genesis};
use sui_core::transaction_input_checker::InputObjects;
use sui_core::{authority::AuthorityTemporaryStore, execution_engine};
use sui_framework::DEFAULT_FRAMEWORK_PATH;
use sui_types::{
Expand All @@ -48,7 +47,7 @@ use sui_types::{
crypto::{get_key_pair_from_rng, KeyPair, Signature},
event::Event,
gas,
messages::{ExecutionStatus, Transaction, TransactionData, TransactionEffects},
messages::{ExecutionStatus, InputObjects, Transaction, TransactionData, TransactionEffects},
object::{self, Object, ObjectFormatOptions, GAS_VALUE_FOR_TESTING},
MOVE_STDLIB_ADDRESS, SUI_FRAMEWORK_ADDRESS,
};
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ curve25519-dalek = { version = "3", default-features = false, features = ["serde
serde-name = "0.2.1"
sha3 = "0.10.1"
thiserror = "1.0.31"
tracing = "0.1"
hex = "0.4.3"
serde_bytes = "0.11.6"
serde_json = "1.0.80"
Expand Down
86 changes: 85 additions & 1 deletion crates/sui-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ use serde_with::Bytes;
use std::fmt::Write;
use std::fmt::{Display, Formatter};
use std::{
collections::{BTreeSet, HashSet},
collections::{BTreeMap, BTreeSet, HashSet},
hash::{Hash, Hasher},
};
use tracing::debug;

#[cfg(test)]
#[path = "unit_tests/messages_tests.rs"]
Expand Down Expand Up @@ -1203,6 +1204,89 @@ impl InputObjectKind {
}
}
}

pub struct InputObjects {
objects: Vec<(InputObjectKind, Object)>,
}

impl InputObjects {
pub fn new(objects: Vec<(InputObjectKind, Object)>) -> Self {
Self { objects }
}

pub fn len(&self) -> usize {
self.objects.len()
}

pub fn is_empty(&self) -> bool {
self.objects.is_empty()
}

pub fn filter_owned_objects(&self) -> Vec<ObjectRef> {
let owned_objects: Vec<_> = self
.objects
.iter()
.filter_map(|(object_kind, object)| match object_kind {
InputObjectKind::MovePackage(_) => None,
InputObjectKind::ImmOrOwnedMoveObject(object_ref) => {
if object.is_immutable() {
None
} else {
Some(*object_ref)
}
}
InputObjectKind::SharedMoveObject(_) => None,
})
.collect();

debug!(
num_mutable_objects = owned_objects.len(),
"Checked locks and found mutable objects"
);

owned_objects
}

pub fn filter_shared_objects(&self) -> Vec<ObjectRef> {
self.objects
.iter()
.filter(|(kind, _)| matches!(kind, InputObjectKind::SharedMoveObject(_)))
.map(|(_, obj)| obj.compute_object_reference())
.collect()
}

pub fn transaction_dependencies(&self) -> BTreeSet<TransactionDigest> {
self.objects
.iter()
.map(|(_, obj)| obj.previous_transaction)
.collect()
}

pub fn mutable_inputs(&self) -> Vec<ObjectRef> {
self.objects
.iter()
.filter_map(|(kind, object)| match kind {
InputObjectKind::MovePackage(_) => None,
InputObjectKind::ImmOrOwnedMoveObject(object_ref) => {
if object.is_immutable() {
None
} else {
Some(*object_ref)
}
}
InputObjectKind::SharedMoveObject(_) => Some(object.compute_object_reference()),
})
.collect()
}

pub fn into_object_map(self) -> BTreeMap<ObjectID, Object> {
self.objects
.into_iter()
.map(|(_, object)| (object.id(), object))
.collect()
}
}

pub struct SignatureAggregator<'a> {
committee: &'a Committee,
weight: StakeUnit,
Expand Down

0 comments on commit 85a6173

Please sign in to comment.