From 02dbe53ded9ef21ddbb90d0e4caa5e8a4ad3fd89 Mon Sep 17 00:00:00 2001 From: phoenix <51927076+phoenix-o@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:23:15 -0400 Subject: [PATCH] Revert "repair coin index" (#19406) ## Description This reverts commit bb778828e36d53a7d91a27e55109f2f45621badc It was a temporary fix for one release only --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --- crates/sui-core/src/authority.rs | 4 +- crates/sui-core/src/verify_indexes.rs | 60 --------------------------- crates/sui-storage/src/indexes.rs | 6 +-- 3 files changed, 4 insertions(+), 66 deletions(-) diff --git a/crates/sui-core/src/authority.rs b/crates/sui-core/src/authority.rs index 1e626d50c5897..f572cc9b6980c 100644 --- a/crates/sui-core/src/authority.rs +++ b/crates/sui-core/src/authority.rs @@ -6,7 +6,7 @@ use crate::execution_cache::ExecutionCacheTraitPointers; use crate::execution_cache::TransactionCacheRead; use crate::rest_index::RestIndexStore; use crate::transaction_outputs::TransactionOutputs; -use crate::verify_indexes::{fix_indexes, verify_indexes}; +use crate::verify_indexes::verify_indexes; use anyhow::anyhow; use arc_swap::{ArcSwap, Guard}; use async_trait::async_trait; @@ -2709,8 +2709,6 @@ impl AuthorityState { validator_tx_finalizer, }); - let state_clone = Arc::downgrade(&state); - spawn_monitored_task!(fix_indexes(state_clone)); // Start a task to execute ready certificates. let authority_state = Arc::downgrade(&state); spawn_monitored_task!(execution_process( diff --git a/crates/sui-core/src/verify_indexes.rs b/crates/sui-core/src/verify_indexes.rs index befec1a5b3809..38b4fd2dcd2b0 100644 --- a/crates/sui-core/src/verify_indexes.rs +++ b/crates/sui-core/src/verify_indexes.rs @@ -1,17 +1,14 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use std::sync::Weak; use std::{collections::BTreeMap, sync::Arc}; use anyhow::{anyhow, bail, Result}; -use sui_storage::indexes::CoinIndexKey; use sui_storage::{indexes::CoinInfo, IndexStore}; use sui_types::{base_types::ObjectInfo, object::Owner}; use tracing::info; use typed_store::traits::Map; -use crate::authority::AuthorityState; use crate::{authority::authority_store_tables::LiveObject, state_accumulator::AccumulatorStore}; /// This is a very expensive function that verifies some of the secondary indexes. This is done by @@ -91,60 +88,3 @@ pub fn verify_indexes(store: &dyn AccumulatorStore, indexes: Arc) -> Ok(()) } - -// temporary code to repair the coin index. This should be removed in the next release -pub async fn fix_indexes(authority_state: Weak) -> Result<()> { - let is_violation = |coin_index_key: &CoinIndexKey, - state: &Arc| - -> anyhow::Result { - if let Some(object) = state.get_object_store().get_object(&coin_index_key.2)? { - if matches!(object.owner, Owner::AddressOwner(real_owner_id) | Owner::ObjectOwner(real_owner_id) if coin_index_key.0 == real_owner_id) - { - return Ok(false); - } - } - Ok(true) - }; - - tracing::info!("Starting fixing coin index"); - // populate candidate list without locking. Some entries are benign - let authority_state_clone = authority_state.clone(); - let candidates = tokio::task::spawn_blocking(move || { - if let Some(authority) = authority_state_clone.upgrade() { - let mut batch = vec![]; - if let Some(indexes) = &authority.indexes { - for (coin_index_key, _) in indexes.tables().coin_index().unbounded_iter() { - if is_violation(&coin_index_key, &authority)? { - batch.push(coin_index_key); - } - } - } - return Ok::, anyhow::Error>(batch); - } - Ok(vec![]) - }) - .await??; - - if let Some(authority) = authority_state.upgrade() { - if let Some(indexes) = &authority.indexes { - for chunk in candidates.chunks(100) { - let _locks = indexes - .caches - .locks - .acquire_locks(chunk.iter().map(|key| key.0)) - .await; - let mut batch = vec![]; - for key in chunk { - if is_violation(key, &authority)? { - batch.push(key); - } - } - let mut wb = indexes.tables().coin_index().batch(); - wb.delete_batch(indexes.tables().coin_index(), batch)?; - wb.write()?; - } - } - } - tracing::info!("Finished fix for the coin index"); - Ok(()) -} diff --git a/crates/sui-storage/src/indexes.rs b/crates/sui-storage/src/indexes.rs index 6302045a55f88..2f170c86d3ff4 100644 --- a/crates/sui-storage/src/indexes.rs +++ b/crates/sui-storage/src/indexes.rs @@ -42,7 +42,7 @@ use typed_store::traits::{TableSummary, TypedStoreDebug}; use typed_store::DBMapUtils; type OwnerIndexKey = (SuiAddress, ObjectID); -pub type CoinIndexKey = (SuiAddress, String, ObjectID); +type CoinIndexKey = (SuiAddress, String, ObjectID); type DynamicFieldKey = (ObjectID, ObjectID); type EventId = (TxSequenceNumber, usize); type EventIndex = (TransactionEventsDigest, TransactionDigest, u64); @@ -129,7 +129,7 @@ impl IndexStoreMetrics { pub struct IndexStoreCaches { per_coin_type_balance: ShardedLruCache<(SuiAddress, TypeTag), SuiResult>, all_balances: ShardedLruCache>>>, - pub locks: MutexTable, + locks: MutexTable, } #[derive(Default)] @@ -229,7 +229,7 @@ impl IndexStoreTables { pub struct IndexStore { next_sequence_number: AtomicU64, tables: IndexStoreTables, - pub caches: IndexStoreCaches, + caches: IndexStoreCaches, metrics: Arc, max_type_length: u64, remove_deprecated_tables: bool,