Skip to content

Commit

Permalink
Remove owner_index table from nodes (#7878)
Browse files Browse the repository at this point in the history
Indexer covers this now.
  • Loading branch information
lxfind authored and williampsmith committed Feb 3, 2023
1 parent b028704 commit f748d70
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 223 deletions.
16 changes: 0 additions & 16 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,13 +1432,6 @@ impl AuthorityState {
.await
}

pub async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError> {
self.make_account_info(request.account)
}

pub async fn handle_object_info_request(
&self,
request: ObjectInfoRequest,
Expand Down Expand Up @@ -2400,15 +2393,6 @@ impl AuthorityState {
}))
}

fn make_account_info(&self, account: SuiAddress) -> Result<AccountInfoResponse, SuiError> {
self.database
.get_owner_objects(Owner::AddressOwner(account))
.map(|object_ids| AccountInfoResponse {
object_ids: object_ids.into_iter().map(|id| id.into()).collect(),
owner: account,
})
}

// Helper function to manage transaction_locks

/// Set the transaction lock to a specific transaction
Expand Down
107 changes: 5 additions & 102 deletions crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,6 @@ impl AuthorityStore {
.await
}

// Methods to read the store
pub fn get_owner_objects(&self, owner: Owner) -> Result<Vec<ObjectInfo>, SuiError> {
debug!(?owner, "get_owner_objects");
Ok(self.get_owner_objects_iterator(owner)?.collect())
}

// Methods to read the store
pub fn get_owner_objects_iterator(
&self,
owner: Owner,
) -> Result<impl Iterator<Item = ObjectInfo> + '_, SuiError> {
debug!(?owner, "get_owner_objects");
Ok(self
.perpetual_tables
.owner_index
.iter()
// The object id 0 is the smallest possible
.skip_to(&(owner, ObjectID::ZERO))?
.take_while(move |((object_owner, _), _)| (object_owner == &owner))
.map(|(_, object_info)| object_info))
}

pub fn get_object_by_key(
&self,
object_id: &ObjectID,
Expand Down Expand Up @@ -529,14 +507,6 @@ impl AuthorityStore {

// Update the index
if object.get_single_owner().is_some() {
write_batch = write_batch.insert_batch(
&self.perpetual_tables.owner_index,
std::iter::once((
&(object.owner, object_ref.0),
&ObjectInfo::new(&object_ref, object),
)),
)?;

// Only initialize lock for address owned objects.
if !object.is_child_object() {
write_batch = self.initialize_locks_impl(write_batch, &[object_ref], false)?;
Expand Down Expand Up @@ -569,12 +539,6 @@ impl AuthorityStore {
.iter()
.map(|(oref, o)| (ObjectKey::from(oref), **o)),
)?
.insert_batch(
&self.perpetual_tables.owner_index,
ref_and_objects
.iter()
.map(|(oref, o)| ((o.owner, oref.0), ObjectInfo::new(oref, o))),
)?
.insert_batch(
&self.perpetual_tables.parent_sync,
ref_and_objects
Expand Down Expand Up @@ -676,31 +640,6 @@ impl AuthorityStore {
.cloned()
.collect();

// Make an iterator over all objects that are either deleted or have changed owner,
// along with their old owner. This is used to update the owner index.
// For wrapped objects, although their owners technically didn't change, we will lose track
// of them and there is no guarantee on their owner in the future. Hence we treat them
// the same as deleted.
let old_object_owners =
deleted
.iter()
// We need to call get() on objects because some object that were just deleted may not
// be in the objects list. This can happen if these deleted objects were wrapped in the past,
// and hence will not show up in the input objects.
.filter_map(|(id, _)| objects.get(id).and_then(Object::get_owner_and_id))
.chain(written.iter().filter_map(
|(id, (_, new_object, _))| match objects.get(id) {
Some(old_object) if old_object.owner != new_object.owner => {
old_object.get_owner_and_id()
}
_ => None,
},
));

// Delete the old owner index entries
write_batch =
write_batch.delete_batch(&self.perpetual_tables.owner_index, old_object_owners)?;

// Index the certificate by the objects mutated
write_batch = write_batch.insert_batch(
&self.perpetual_tables.parent_sync,
Expand Down Expand Up @@ -728,19 +667,6 @@ impl AuthorityStore {
}),
)?;

// Update the indexes of the objects written
write_batch = write_batch.insert_batch(
&self.perpetual_tables.owner_index,
written
.iter()
.filter_map(|(_id, (object_ref, new_object, _kind))| {
trace!(?object_ref, owner =? new_object.owner, "Updating owner_index");
new_object
.get_owner_and_id()
.map(|owner_id| (owner_id, ObjectInfo::new(object_ref, new_object)))
}),
)?;

// Insert each output object into the stores
write_batch = write_batch.insert_batch(
&self.perpetual_tables.objects,
Expand Down Expand Up @@ -1077,21 +1003,6 @@ impl AuthorityStore {
write_batch = write_batch
.delete_batch(&self.perpetual_tables.objects, all_new_object_keys.clone())?;

// Reverting the change to the owner_index table is most complex.
// For each newly created (i.e. created and unwrapped) object, the entry in owner_index
// needs to be deleted; for each mutated object, we need to query the object state of
// the older version, and then rewrite the entry with the old object info.
// TODO: Validators should not need to maintain owner_index.
// This is dependent on https://github.com/MystenLabs/sui/issues/2629.
let owners_to_delete = effects
.created
.iter()
.chain(effects.unwrapped.iter())
.chain(effects.mutated.iter())
.map(|((id, _, _), owner)| (*owner, *id));
write_batch =
write_batch.delete_batch(&self.perpetual_tables.owner_index, owners_to_delete)?;

let modified_object_keys = effects
.modified_at_versions
.iter()
Expand All @@ -1113,31 +1024,23 @@ impl AuthorityStore {
}

let obj_ref = obj.compute_object_reference();
Some((
((obj.owner, obj.id()), ObjectInfo::new(&obj_ref, &obj)),
obj.is_address_owned().then_some(obj_ref),
))
Some(obj.is_address_owned().then_some(obj_ref))
})
.unzip()
};
}

let (old_modified_objects, old_locks): (Vec<_>, Vec<_>) =
get_objects_and_locks!(modified_object_keys);
let (_, new_locks): (Vec<_>, Vec<_>) = get_objects_and_locks!(all_new_object_keys);

let old_locks: Vec<_> = old_locks.into_iter().flatten().collect();
let old_locks = get_objects_and_locks!(modified_object_keys);
let new_locks = get_objects_and_locks!(all_new_object_keys);

write_batch =
write_batch.insert_batch(&self.perpetual_tables.owner_index, old_modified_objects)?;
let old_locks: Vec<_> = old_locks.flatten().collect();

// Re-create old locks.
write_batch = self.initialize_locks_impl(write_batch, &old_locks, true)?;

// Delete new locks
write_batch = write_batch.delete_batch(
&self.perpetual_tables.owned_object_transaction_locks,
new_locks.into_iter().flatten(),
new_locks.flatten(),
)?;

write_batch.write()?;
Expand Down
6 changes: 0 additions & 6 deletions crates/sui-core/src/authority/authority_store_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ pub struct AuthorityPerpetualTables {
#[default_options_override_fn = "owned_object_transaction_locks_table_default_config"]
pub(crate) owned_object_transaction_locks: DBMap<ObjectRef, Option<LockDetails>>,

/// This is a an index of object references to currently existing objects, indexed by the
/// composite key of the SuiAddress of their owner and the object ID of the object.
/// This composite index allows an efficient iterator to list all objected currently owned
/// by a specific user, and their object reference.
pub(crate) owner_index: DBMap<(Owner, ObjectID), ObjectInfo>,

/// This is a map between the transaction digest and the corresponding certificate for all
/// certificates that have been successfully processed by this authority. This set of certificates
/// along with the genesis allows the reconstruction of all other state, and a full sync to this
Expand Down
17 changes: 0 additions & 17 deletions crates/sui-core/src/authority_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ pub trait AuthorityAPI {
certificate: CertifiedTransaction,
) -> Result<HandleCertificateResponse, SuiError>;

/// Handle Account information requests for this account.
async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError>;

/// Handle Object information requests for this account.
async fn handle_object_info_request(
&self,
Expand Down Expand Up @@ -120,17 +114,6 @@ impl AuthorityAPI for NetworkAuthorityClient {
.map_err(Into::into)
}

async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError> {
self.client()
.account_info(request)
.await
.map(tonic::Response::into_inner)
.map_err(Into::into)
}

async fn handle_object_info_request(
&self,
request: ObjectInfoRequest,
Expand Down
11 changes: 0 additions & 11 deletions crates/sui-core/src/authority_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,6 @@ impl Validator for ValidatorService {
.unwrap()
}

async fn account_info(
&self,
request: tonic::Request<AccountInfoRequest>,
) -> Result<tonic::Response<AccountInfoResponse>, tonic::Status> {
let request = request.into_inner();

let response = self.state.handle_account_info_request(request).await?;

Ok(tonic::Response::new(response))
}

async fn object_info(
&self,
request: tonic::Request<ObjectInfoRequest>,
Expand Down
9 changes: 0 additions & 9 deletions crates/sui-core/src/safe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,6 @@ where
Ok(verified)
}

pub async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError> {
self.authority_client
.handle_account_info_request(request)
.await
}

/// Pass `skip_committee_check_during_reconfig = true` during reconfiguration, so that
/// we can tolerate missing committee information when processing the object data.
pub async fn handle_object_info_request(
Expand Down
28 changes: 2 additions & 26 deletions crates/sui-core/src/test_authority_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use sui_types::{
crypto::AuthorityKeyPair,
error::SuiError,
messages::{
AccountInfoRequest, AccountInfoResponse, CertifiedTransaction, CommitteeInfoRequest,
CommitteeInfoResponse, ObjectInfoRequest, ObjectInfoResponse, Transaction,
TransactionInfoRequest, TransactionInfoResponse,
CertifiedTransaction, CommitteeInfoRequest, CommitteeInfoResponse, ObjectInfoRequest,
ObjectInfoResponse, Transaction, TransactionInfoRequest, TransactionInfoResponse,
},
messages_checkpoint::{CheckpointRequest, CheckpointResponse},
};
Expand Down Expand Up @@ -75,14 +74,6 @@ impl AuthorityAPI for LocalAuthorityClient {
.unwrap()
}

async fn handle_account_info_request(
&self,
request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError> {
let state = self.state.clone();
state.handle_account_info_request(request).await
}

async fn handle_object_info_request(
&self,
request: ObjectInfoRequest,
Expand Down Expand Up @@ -222,14 +213,6 @@ impl AuthorityAPI for MockAuthorityApi {
unreachable!()
}

/// Handle Account information requests for this account.
async fn handle_account_info_request(
&self,
_request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError> {
unreachable!();
}

/// Handle Object information requests for this account.
async fn handle_object_info_request(
&self,
Expand Down Expand Up @@ -298,13 +281,6 @@ impl AuthorityAPI for HandleTransactionTestAuthorityClient {
unimplemented!()
}

async fn handle_account_info_request(
&self,
_request: AccountInfoRequest,
) -> Result<AccountInfoResponse, SuiError> {
unimplemented!()
}

async fn handle_object_info_request(
&self,
_request: ObjectInfoRequest,
Expand Down
10 changes: 0 additions & 10 deletions crates/sui-core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2672,16 +2672,6 @@ async fn test_store_revert_transfer_sui() {
db.get_latest_parent_entry(gas_object_id).unwrap().unwrap(),
(gas_object_ref, TransactionDigest::genesis()),
);
assert!(db
.get_owner_objects(Owner::AddressOwner(recipient))
.unwrap()
.is_empty());
assert_eq!(
db.get_owner_objects(Owner::AddressOwner(sender))
.unwrap()
.len(),
1
);
assert!(db.get_certified_transaction(&tx_digest).unwrap().is_none());
assert!(db.as_ref().get_effects(&tx_digest).is_err());
}
Expand Down
9 changes: 0 additions & 9 deletions crates/sui-network/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ fn main() -> Result<()> {
.codec_path(codec_path)
.build(),
)
.method(
Method::builder()
.name("account_info")
.route_name("AccountInfo")
.input_type("sui_types::messages::AccountInfoRequest")
.output_type("sui_types::messages::AccountInfoResponse")
.codec_path(codec_path)
.build(),
)
.method(
Method::builder()
.name("object_info")
Expand Down
17 changes: 0 additions & 17 deletions crates/sui-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,17 +1207,6 @@ pub type TxCertAndSignedEffects = (CertifiedTransaction, SignedTransactionEffect
pub type VerifiedCertificate = VerifiedEnvelope<SenderSignedData, AuthorityStrongQuorumSignInfo>;
pub type TrustedCertificate = TrustedEnvelope<SenderSignedData, AuthorityStrongQuorumSignInfo>;

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub struct AccountInfoRequest {
pub account: SuiAddress,
}

impl From<SuiAddress> for AccountInfoRequest {
fn from(account: SuiAddress) -> Self {
AccountInfoRequest { account }
}
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub enum ObjectInfoRequestKind {
/// Request the latest object state, if a format option is provided,
Expand Down Expand Up @@ -1261,12 +1250,6 @@ impl ObjectInfoRequest {
}
}

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
pub struct AccountInfoResponse {
pub object_ids: Vec<ObjectRef>,
pub owner: SuiAddress,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectResponse<T = SignedTransaction> {
/// Value of the requested object in this authority
Expand Down

0 comments on commit f748d70

Please sign in to comment.