Skip to content

Commit

Permalink
refactor(iota-core): Remove deprecated AuthorityPerpetualTables/`Au…
Browse files Browse the repository at this point in the history
…thorityStore` related code (#3829)

* Remove deprecated code

* Clean code

* Clean code

* Add PrintTransaction DbToolCommand

* fix(node): pop and flatten the result instead of indexing

* fix(node): removed `into_iter().collect()`

* fix(node): fix epoch_db in print_transaction

---------

Co-authored-by: muXxer <[email protected]>
  • Loading branch information
bingyanglin and muXxer authored Nov 5, 2024
1 parent 0de2f4c commit d891762
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 279 deletions.
30 changes: 6 additions & 24 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ use crate::{
consensus_adapter::ConsensusAdapter,
epoch::committee_store::CommitteeStore,
execution_cache::{
CheckpointCache, ExecutionCacheCommit, ExecutionCacheReconfigAPI,
ExecutionCacheTraitPointers, ExecutionCacheWrite, ObjectCacheRead, StateSyncAPI,
TransactionCacheRead,
ExecutionCacheCommit, ExecutionCacheReconfigAPI, ExecutionCacheTraitPointers,
ExecutionCacheWrite, ObjectCacheRead, StateSyncAPI, TransactionCacheRead,
},
execution_driver::execution_process,
metrics::{LatencyObserver, RateTracker},
Expand Down Expand Up @@ -2736,10 +2735,6 @@ impl AuthorityState {
&self.execution_cache_trait_pointers.accumulator_store
}

pub fn get_checkpoint_cache(&self) -> &Arc<dyn CheckpointCache> {
&self.execution_cache_trait_pointers.checkpoint_cache
}

pub fn get_state_sync_store(&self) -> &Arc<dyn StateSyncAPI> {
&self.execution_cache_trait_pointers.state_sync_store
}
Expand Down Expand Up @@ -4986,15 +4981,6 @@ impl TransactionKeyValueStoreTrait for AuthorityState {
Ok((summaries, contents, summaries_by_digest, contents_by_digest))
}

async fn deprecated_get_transaction_checkpoint(
&self,
digest: TransactionDigest,
) -> IotaResult<Option<CheckpointSequenceNumber>> {
self.get_checkpoint_cache()
.deprecated_get_transaction_checkpoint(&digest)
.map(|res| res.map(|(_epoch, checkpoint)| checkpoint))
}

async fn get_object(
&self,
object_id: ObjectID,
Expand All @@ -5009,14 +4995,10 @@ impl TransactionKeyValueStoreTrait for AuthorityState {
&self,
digests: &[TransactionDigest],
) -> IotaResult<Vec<Option<CheckpointSequenceNumber>>> {
let res = self
.get_checkpoint_cache()
.deprecated_multi_get_transaction_checkpoint(digests)?;

Ok(res
.into_iter()
.map(|maybe| maybe.map(|(_epoch, checkpoint)| checkpoint))
.collect())
Ok(self
.epoch_store
.load()
.multi_get_transaction_checkpoint(digests)?)
}
}

Expand Down
11 changes: 8 additions & 3 deletions crates/iota-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,13 @@ impl AuthorityEpochTables {
Ok(())
}

pub fn get_transaction_checkpoint(
&self,
digest: &TransactionDigest,
) -> IotaResult<Option<CheckpointSequenceNumber>> {
Ok(self.executed_transactions_to_checkpoint.get(digest)?)
}

/// WARNING: This method is very subtle and can corrupt the database if used
/// incorrectly. It should only be used in one-off cases or tests after
/// fully understanding the risk.
Expand Down Expand Up @@ -1457,9 +1464,7 @@ impl AuthorityPerEpochStore {
Ok(self
.tables()?
.executed_transactions_to_checkpoint
.multi_get(digests)?
.into_iter()
.collect())
.multi_get(digests)?)
}

// For each id in objects_to_init, return the next version for that id as
Expand Down
44 changes: 0 additions & 44 deletions crates/iota-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,50 +541,6 @@ impl AuthorityStore {
Ok(result)
}

// DEPRECATED -- use function of same name in AuthorityPerEpochStore
pub fn deprecated_insert_finalized_transactions(
&self,
digests: &[TransactionDigest],
epoch: EpochId,
sequence: CheckpointSequenceNumber,
) -> IotaResult {
let mut batch = self
.perpetual_tables
.executed_transactions_to_checkpoint
.batch();
batch.insert_batch(
&self.perpetual_tables.executed_transactions_to_checkpoint,
digests.iter().map(|d| (*d, (epoch, sequence))),
)?;
batch.write()?;
trace!("Transactions {digests:?} finalized at checkpoint {sequence} epoch {epoch}");
Ok(())
}

// DEPRECATED -- use function of same name in AuthorityPerEpochStore
pub fn deprecated_get_transaction_checkpoint(
&self,
digest: &TransactionDigest,
) -> IotaResult<Option<(EpochId, CheckpointSequenceNumber)>> {
Ok(self
.perpetual_tables
.executed_transactions_to_checkpoint
.get(digest)?)
}

// DEPRECATED -- use function of same name in AuthorityPerEpochStore
pub fn deprecated_multi_get_transaction_checkpoint(
&self,
digests: &[TransactionDigest],
) -> IotaResult<Vec<Option<(EpochId, CheckpointSequenceNumber)>>> {
Ok(self
.perpetual_tables
.executed_transactions_to_checkpoint
.multi_get(digests)?
.into_iter()
.collect())
}

/// Returns true if there are no objects in the database
pub fn database_is_empty(&self) -> IotaResult<bool> {
self.perpetual_tables.database_is_empty()
Expand Down
4 changes: 0 additions & 4 deletions crates/iota-core/src/authority/authority_store_pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,6 @@ impl AuthorityStorePruner {

perpetual_batch.delete_batch(&perpetual_db.transactions, transactions.iter())?;
perpetual_batch.delete_batch(&perpetual_db.executed_effects, transactions.iter())?;
perpetual_batch.delete_batch(
&perpetual_db.executed_transactions_to_checkpoint,
transactions,
)?;

let mut effect_digests = vec![];
for effects in effects_to_prune {
Expand Down
17 changes: 0 additions & 17 deletions crates/iota-core/src/authority/authority_store_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ pub struct AuthorityPerpetualTables {
#[default_options_override_fn = "events_table_default_config"]
pub(crate) events: DBMap<(TransactionEventsDigest, usize), Event>,

/// DEPRECATED in favor of the table of the same name in
/// authority_per_epoch_store. Please do not add new
/// accessors/callsites. When transaction is executed via checkpoint
/// executor, we store association here
pub(crate) executed_transactions_to_checkpoint:
DBMap<TransactionDigest, (EpochId, CheckpointSequenceNumber)>,

// Finalized root state accumulator for epoch, to be included in CheckpointSummary
// of last checkpoint of epoch. These values should only ever be written once
// and never changed
Expand Down Expand Up @@ -356,15 +349,6 @@ impl AuthorityPerpetualTables {
Ok(self.effects.get(&effect_digest)?)
}

// DEPRECATED as the backing table has been moved to authority_per_epoch_store.
// Please do not add new accessors/callsites.
pub fn get_checkpoint_sequence_number(
&self,
digest: &TransactionDigest,
) -> IotaResult<Option<(EpochId, CheckpointSequenceNumber)>> {
Ok(self.executed_transactions_to_checkpoint.get(digest)?)
}

pub fn get_newer_object_keys(
&self,
object: &(ObjectID, SequenceNumber),
Expand Down Expand Up @@ -434,7 +418,6 @@ impl AuthorityPerpetualTables {
self.live_owned_object_markers.unsafe_clear()?;
self.executed_effects.unsafe_clear()?;
self.events.unsafe_clear()?;
self.executed_transactions_to_checkpoint.unsafe_clear()?;
self.root_state_hash_by_epoch.unsafe_clear()?;
self.epoch_start_configuration.unsafe_clear()?;
self.pruned_checkpoint.unsafe_clear()?;
Expand Down
9 changes: 0 additions & 9 deletions crates/iota-core/src/checkpoints/checkpoint_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,15 +1304,6 @@ async fn finalize_checkpoint(
debug!("finalizing checkpoint");
epoch_store.insert_finalized_transactions(tx_digests, checkpoint.sequence_number)?;

// TODO remove once we no longer need to support this table for read RPC
state
.get_checkpoint_cache()
.deprecated_insert_finalized_transactions(
tx_digests,
epoch_store.epoch(),
checkpoint.sequence_number,
)?;

let checkpoint_acc =
accumulator.accumulate_checkpoint(effects, checkpoint.sequence_number, epoch_store)?;

Expand Down
54 changes: 0 additions & 54 deletions crates/iota-core/src/execution_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub struct ExecutionCacheTraitPointers {
pub object_store: Arc<dyn ObjectStore + Send + Sync>,
pub reconfig_api: Arc<dyn ExecutionCacheReconfigAPI>,
pub accumulator_store: Arc<dyn AccumulatorStore>,
pub checkpoint_cache: Arc<dyn CheckpointCache>,
pub state_sync_store: Arc<dyn StateSyncAPI>,
pub cache_commit: Arc<dyn ExecutionCacheCommit>,
pub testing_api: Arc<dyn TestingAPI>,
Expand All @@ -80,7 +79,6 @@ impl ExecutionCacheTraitPointers {
+ ObjectStore
+ ExecutionCacheReconfigAPI
+ AccumulatorStore
+ CheckpointCache
+ StateSyncAPI
+ ExecutionCacheCommit
+ TestingAPI
Expand All @@ -95,7 +93,6 @@ impl ExecutionCacheTraitPointers {
object_store: cache.clone(),
reconfig_api: cache.clone(),
accumulator_store: cache.clone(),
checkpoint_cache: cache.clone(),
state_sync_store: cache.clone(),
cache_commit: cache.clone(),
testing_api: cache.clone(),
Expand Down Expand Up @@ -658,29 +655,6 @@ pub trait ExecutionCacheWrite: Send + Sync {
) -> BoxFuture<'a, IotaResult>;
}

pub trait CheckpointCache: Send + Sync {
// TODO: In addition to the deprecated methods below, this will eventually
// include access to the CheckpointStore

// DEPRECATED METHODS
fn deprecated_get_transaction_checkpoint(
&self,
digest: &TransactionDigest,
) -> IotaResult<Option<(EpochId, CheckpointSequenceNumber)>>;

fn deprecated_multi_get_transaction_checkpoint(
&self,
digests: &[TransactionDigest],
) -> IotaResult<Vec<Option<(EpochId, CheckpointSequenceNumber)>>>;

fn deprecated_insert_finalized_transactions(
&self,
digests: &[TransactionDigest],
epoch: EpochId,
sequence: CheckpointSequenceNumber,
) -> IotaResult;
}

pub trait ExecutionCacheReconfigAPI: Send + Sync {
fn insert_genesis_object(&self, object: Object) -> IotaResult;
fn bulk_insert_genesis_objects(&self, objects: &[Object]) -> IotaResult;
Expand Down Expand Up @@ -826,33 +800,6 @@ macro_rules! implement_storage_traits {
// store.
macro_rules! implement_passthrough_traits {
($implementor: ident) => {
impl CheckpointCache for $implementor {
fn deprecated_get_transaction_checkpoint(
&self,
digest: &TransactionDigest,
) -> IotaResult<Option<(EpochId, CheckpointSequenceNumber)>> {
self.store.deprecated_get_transaction_checkpoint(digest)
}

fn deprecated_multi_get_transaction_checkpoint(
&self,
digests: &[TransactionDigest],
) -> IotaResult<Vec<Option<(EpochId, CheckpointSequenceNumber)>>> {
self.store
.deprecated_multi_get_transaction_checkpoint(digests)
}

fn deprecated_insert_finalized_transactions(
&self,
digests: &[TransactionDigest],
epoch: EpochId,
sequence: CheckpointSequenceNumber,
) -> IotaResult {
self.store
.deprecated_insert_finalized_transactions(digests, epoch, sequence)
}
}

impl ExecutionCacheReconfigAPI for $implementor {
fn insert_genesis_object(&self, object: Object) -> IotaResult {
self.store.insert_genesis_object(object)
Expand Down Expand Up @@ -953,7 +900,6 @@ pub trait ExecutionCacheAPI:
+ ExecutionCacheWrite
+ ExecutionCacheCommit
+ ExecutionCacheReconfigAPI
+ CheckpointCache
+ StateSyncAPI
{
}
5 changes: 2 additions & 3 deletions crates/iota-core/src/execution_cache/passthrough_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ use tracing::instrument;
use typed_store::Map;

use super::{
CheckpointCache, ExecutionCacheCommit, ExecutionCacheMetrics, ExecutionCacheReconfigAPI,
ExecutionCacheWrite, ObjectCacheRead, StateSyncAPI, TestingAPI, TransactionCacheRead,
implement_passthrough_traits,
ExecutionCacheCommit, ExecutionCacheMetrics, ExecutionCacheReconfigAPI, ExecutionCacheWrite,
ObjectCacheRead, StateSyncAPI, TestingAPI, TransactionCacheRead, implement_passthrough_traits,
};
use crate::{
authority::{
Expand Down
27 changes: 1 addition & 26 deletions crates/iota-core/src/execution_cache/proxy_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use iota_types::{
use parking_lot::RwLock;

use super::{
CheckpointCache, ExecutionCacheCommit, ExecutionCacheConfigType, ExecutionCacheMetrics,
ExecutionCacheCommit, ExecutionCacheConfigType, ExecutionCacheMetrics,
ExecutionCacheReconfigAPI, ExecutionCacheWrite, ObjectCacheRead, PassthroughCache,
StateSyncAPI, TestingAPI, TransactionCacheRead, WritebackCache,
};
Expand Down Expand Up @@ -317,31 +317,6 @@ impl ExecutionCacheCommit for ProxyCache {
}
}

impl CheckpointCache for ProxyCache {
fn deprecated_get_transaction_checkpoint(
&self,
digest: &TransactionDigest,
) -> IotaResult<Option<(EpochId, CheckpointSequenceNumber)>> {
delegate_method!(self.deprecated_get_transaction_checkpoint(digest))
}

fn deprecated_multi_get_transaction_checkpoint(
&self,
digests: &[TransactionDigest],
) -> IotaResult<Vec<Option<(EpochId, CheckpointSequenceNumber)>>> {
delegate_method!(self.deprecated_multi_get_transaction_checkpoint(digests))
}

fn deprecated_insert_finalized_transactions(
&self,
digests: &[TransactionDigest],
epoch: EpochId,
sequence: CheckpointSequenceNumber,
) -> IotaResult {
delegate_method!(self.deprecated_insert_finalized_transactions(digests, epoch, sequence))
}
}

impl ExecutionCacheReconfigAPI for ProxyCache {
fn insert_genesis_object(&self, object: Object) -> IotaResult {
delegate_method!(self.insert_genesis_object(object))
Expand Down
7 changes: 3 additions & 4 deletions crates/iota-core/src/execution_cache/writeback_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ use tap::TapOptional;
use tracing::{debug, info, instrument, trace, warn};

use super::{
CheckpointCache, ExecutionCacheAPI, ExecutionCacheCommit, ExecutionCacheMetrics,
ExecutionCacheReconfigAPI, ExecutionCacheWrite, ObjectCacheRead, StateSyncAPI, TestingAPI,
TransactionCacheRead, cache_types::CachedVersionMap, implement_passthrough_traits,
object_locks::ObjectLocks,
ExecutionCacheAPI, ExecutionCacheCommit, ExecutionCacheMetrics, ExecutionCacheReconfigAPI,
ExecutionCacheWrite, ObjectCacheRead, StateSyncAPI, TestingAPI, TransactionCacheRead,
cache_types::CachedVersionMap, implement_passthrough_traits, object_locks::ObjectLocks,
};
use crate::{
authority::{
Expand Down
Loading

0 comments on commit d891762

Please sign in to comment.