Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/iota-benchmark/tests/simtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod test {
..Default::default()
})
.with_submit_delay_step_override_millis(3000)
.with_state_accumulator_callback(Arc::new(|idx| idx % 2 == 0))
.with_global_state_hash_v1_enabled_callback(Arc::new(|idx| idx % 2 == 0))
.build()
.await
.into();
Expand Down
28 changes: 14 additions & 14 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ use crate::{
TransactionCacheRead,
},
execution_driver::execution_process,
global_state_hasher::{GlobalStateHashStore, GlobalStateHasher},
grpc_indexes::{GRPC_INDEXES_DIR, GrpcIndexesStore},
jsonrpc_index::{CoinInfo, IndexStore, ObjectIndexChanges},
metrics::{LatencyObserver, RateTracker},
module_cache_metrics::ResolverMetrics,
overload_monitor::{AuthorityOverloadInfo, overload_monitor_accept_tx},
stake_aggregator::StakeAggregator,
state_accumulator::{AccumulatorStore, StateAccumulator},
subscription_handler::SubscriptionHandler,
transaction_input_loader::TransactionInputLoader,
transaction_manager::TransactionManager,
Expand Down Expand Up @@ -3110,8 +3110,8 @@ impl AuthorityState {
&self.execution_cache_trait_pointers.reconfig_api
}

pub fn get_accumulator_store(&self) -> &Arc<dyn AccumulatorStore> {
&self.execution_cache_trait_pointers.accumulator_store
pub fn get_global_state_hash_store(&self) -> &Arc<dyn GlobalStateHashStore> {
&self.execution_cache_trait_pointers.global_state_hash_store
}

pub fn get_checkpoint_cache(&self) -> &Arc<dyn CheckpointCache> {
Expand Down Expand Up @@ -3292,7 +3292,7 @@ impl AuthorityState {
supported_protocol_versions: SupportedProtocolVersions,
new_committee: Committee,
epoch_start_configuration: EpochStartConfiguration,
accumulator: Arc<StateAccumulator>,
state_hasher: Arc<GlobalStateHasher>,
expensive_safety_check_config: &ExpensiveSafetyCheckConfig,
epoch_supply_change: i64,
epoch_last_checkpoint: CheckpointSequenceNumber,
Expand Down Expand Up @@ -3349,7 +3349,7 @@ impl AuthorityState {
.clear_state_end_of_epoch(&execution_lock);
self.check_system_consistency(
cur_epoch_store,
accumulator,
state_hasher,
expensive_safety_check_config,
epoch_supply_change,
)?;
Expand Down Expand Up @@ -3435,7 +3435,7 @@ impl AuthorityState {
fn check_system_consistency(
&self,
cur_epoch_store: &AuthorityPerEpochStore,
accumulator: Arc<StateAccumulator>,
state_hasher: Arc<GlobalStateHasher>,
expensive_safety_check_config: &ExpensiveSafetyCheckConfig,
epoch_supply_change: i64,
) -> IotaResult<()> {
Expand All @@ -3458,15 +3458,15 @@ impl AuthorityState {
cur_epoch_store.epoch()
);
self.expensive_check_is_consistent_state(
accumulator,
state_hasher,
cur_epoch_store,
cfg!(debug_assertions), // panic in debug mode only
);
}

if expensive_safety_check_config.enable_secondary_index_checks() {
if let Some(indexes) = self.indexes.clone() {
verify_indexes(self.get_accumulator_store().as_ref(), indexes)
verify_indexes(self.get_global_state_hash_store().as_ref(), indexes)
.expect("secondary indexes are inconsistent");
}
}
Expand All @@ -3476,15 +3476,15 @@ impl AuthorityState {

fn expensive_check_is_consistent_state(
&self,
accumulator: Arc<StateAccumulator>,
state_hasher: Arc<GlobalStateHasher>,
cur_epoch_store: &AuthorityPerEpochStore,
panic: bool,
) {
let live_object_set_hash = accumulator.digest_live_object_set();
let live_object_set_hash = state_hasher.digest_live_object_set();

let root_state_hash: ECMHLiveObjectSetDigest = self
.get_accumulator_store()
.get_root_state_accumulator_for_epoch(cur_epoch_store.epoch())
.get_global_state_hash_store()
.get_root_state_hash_for_epoch(cur_epoch_store.epoch())
.expect("Retrieving root state hash cannot fail")
.expect("Root state hash for epoch must exist")
.1
Expand All @@ -3508,7 +3508,7 @@ impl AuthorityState {
}

if !panic {
accumulator.set_inconsistent_state(is_inconsistent);
state_hasher.set_inconsistent_state(is_inconsistent);
}
}

Expand Down Expand Up @@ -5581,7 +5581,7 @@ impl AuthorityState {
pub(crate) fn iter_live_object_set_for_testing(
&self,
) -> impl Iterator<Item = authority_store_tables::LiveObject> + '_ {
self.get_accumulator_store()
self.get_global_state_hash_store()
.iter_cached_live_object_set_for_testing()
}

Expand Down
47 changes: 24 additions & 23 deletions crates/iota-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use iota_protocol_config::{
};
use iota_storage::mutex_table::{MutexGuard, MutexTable};
use iota_types::{
accumulator::Accumulator,
authenticator_state::{ActiveJwk, get_authenticator_state},
base_types::{
AuthorityName, CommitRound, ConciseableName, EpochId, ObjectID, ObjectRef, SequenceNumber,
Expand All @@ -47,6 +46,7 @@ use iota_types::{
effects::TransactionEffects,
error::{IotaError, IotaResult},
executable_transaction::VerifiedExecutableTransaction,
global_state_hash::GlobalStateHash,
iota_system_state::epoch_start_iota_system_state::{
EpochStartSystemState, EpochStartSystemStateTrait,
},
Expand Down Expand Up @@ -611,9 +611,9 @@ pub struct AuthorityPerEpochStore {
/// the current epoch.
pub(crate) signature_verifier: SignatureVerifier,

pub(crate) checkpoint_state_notify_read: NotifyRead<CheckpointSequenceNumber, Accumulator>,
pub(crate) checkpoint_state_notify_read: NotifyRead<CheckpointSequenceNumber, GlobalStateHash>,

running_root_notify_read: NotifyRead<CheckpointSequenceNumber, Accumulator>,
running_root_notify_read: NotifyRead<CheckpointSequenceNumber, GlobalStateHash>,

executed_digests_notify_read: NotifyRead<TransactionKey, TransactionDigest>,

Expand Down Expand Up @@ -767,13 +767,14 @@ pub struct AuthorityEpochTables {
// Maps checkpoint sequence number to an accumulator with accumulated state
// only for the checkpoint that the key references. Append-only, i.e.,
// the accumulator is complete wrt the checkpoint
pub state_hash_by_checkpoint: DBMap<CheckpointSequenceNumber, Accumulator>,
pub state_hash_by_checkpoint: DBMap<CheckpointSequenceNumber, GlobalStateHash>,

/// Maps checkpoint sequence number to the running (non-finalized) root
/// state accumulator up th that checkpoint. This should be equivalent
/// to the root state hash at end of epoch. Guaranteed to be written to
/// in checkpoint sequence number order.
pub running_root_accumulators: DBMap<CheckpointSequenceNumber, Accumulator>,
#[rename = "running_root_accumulators"]
pub running_root_state_hash: DBMap<CheckpointSequenceNumber, GlobalStateHash>,

/// Record of the capabilities advertised by each authority.
authority_capabilities_v1: DBMap<AuthorityName, AuthorityCapabilitiesV1>,
Expand Down Expand Up @@ -1315,7 +1316,7 @@ impl AuthorityPerEpochStore {
pub fn get_state_hash_for_checkpoint(
&self,
checkpoint: &CheckpointSequenceNumber,
) -> IotaResult<Option<Accumulator>> {
) -> IotaResult<Option<GlobalStateHash>> {
Ok(self
.tables()?
.state_hash_by_checkpoint
Expand All @@ -1326,7 +1327,7 @@ impl AuthorityPerEpochStore {
pub fn insert_state_hash_for_checkpoint(
&self,
checkpoint: &CheckpointSequenceNumber,
accumulator: &Accumulator,
accumulator: &GlobalStateHash,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the param is still called accumulator

) -> IotaResult {
self.tables()?
.state_hash_by_checkpoint
Expand All @@ -1335,37 +1336,37 @@ impl AuthorityPerEpochStore {
Ok(())
}

pub fn get_running_root_accumulator(
pub fn get_running_root_state_hash(
&self,
checkpoint: CheckpointSequenceNumber,
) -> IotaResult<Option<Accumulator>> {
) -> IotaResult<Option<GlobalStateHash>> {
Ok(self
.tables()?
.running_root_accumulators
.running_root_state_hash
.get(&checkpoint)
.expect("db error"))
}

pub fn get_highest_running_root_accumulator(
pub fn get_highest_running_root_state_hash(
&self,
) -> IotaResult<Option<(CheckpointSequenceNumber, Accumulator)>> {
) -> IotaResult<Option<(CheckpointSequenceNumber, GlobalStateHash)>> {
Ok(self
.tables()?
.running_root_accumulators
.running_root_state_hash
.reversed_safe_iter_with_bounds(None, None)?
.next()
.transpose()?)
}

pub fn insert_running_root_accumulator(
pub fn insert_running_root_state_hash(
&self,
checkpoint: &CheckpointSequenceNumber,
acc: &Accumulator,
hash: &GlobalStateHash,
) -> IotaResult {
self.tables()?
.running_root_accumulators
.insert(checkpoint, acc)?;
self.running_root_notify_read.notify(checkpoint, acc);
.running_root_state_hash
.insert(checkpoint, hash)?;
self.running_root_notify_read.notify(checkpoint, hash);

Ok(())
}
Expand Down Expand Up @@ -1646,7 +1647,7 @@ impl AuthorityPerEpochStore {
&self,
from_checkpoint: CheckpointSequenceNumber,
to_checkpoint: CheckpointSequenceNumber,
) -> IotaResult<Vec<(CheckpointSequenceNumber, Accumulator)>> {
) -> IotaResult<Vec<(CheckpointSequenceNumber, GlobalStateHash)>> {
self.tables()?
.state_hash_by_checkpoint
.safe_range_iter(from_checkpoint..=to_checkpoint)
Expand All @@ -1656,10 +1657,10 @@ impl AuthorityPerEpochStore {

/// Returns future containing the state accumulator for the given epoch
/// once available.
pub async fn notify_read_checkpoint_state_accumulator(
pub async fn notify_read_checkpoint_state_hasher(
&self,
checkpoints: &[CheckpointSequenceNumber],
) -> IotaResult<Vec<Accumulator>> {
) -> IotaResult<Vec<GlobalStateHash>> {
let tables = self.tables()?;
self.checkpoint_state_notify_read
.read(checkpoints, |checkpoints| {
Expand All @@ -1674,9 +1675,9 @@ impl AuthorityPerEpochStore {
pub async fn notify_read_running_root(
&self,
checkpoint: CheckpointSequenceNumber,
) -> IotaResult<Accumulator> {
) -> IotaResult<GlobalStateHash> {
let registration = self.running_root_notify_read.register_one(&checkpoint);
let acc = self.tables()?.running_root_accumulators.get(&checkpoint)?;
let acc = self.tables()?.running_root_state_hash.get(&checkpoint)?;

let result = match acc {
Some(ready) => Either::Left(futures::future::ready(ready)),
Expand Down
35 changes: 20 additions & 15 deletions crates/iota-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use iota_config::{migration_tx_data::MigrationTxData, node::AuthorityStorePrunin
use iota_macros::fail_point_arg;
use iota_storage::mutex_table::{MutexGuard, MutexTable};
use iota_types::{
accumulator::Accumulator,
base_types::SequenceNumber,
digests::TransactionEventsDigest,
effects::{TransactionEffects, TransactionEvents},
error::UserInputError,
execution::TypeLayoutStore,
fp_bail, fp_ensure,
global_state_hash::GlobalStateHash,
iota_system_state::{
get_iota_system_state, iota_system_state_summary::IotaSystemStateSummaryV2,
},
Expand Down Expand Up @@ -51,8 +51,8 @@ use crate::{
authority_store_types::{StoreObject, StoreObjectWrapper, get_store_object},
epoch_start_configuration::{EpochFlag, EpochStartConfiguration},
},
global_state_hasher::GlobalStateHashStore,
grpc_indexes::GrpcIndexesStore,
state_accumulator::AccumulatorStore,
transaction_outputs::TransactionOutputs,
};

Expand Down Expand Up @@ -125,7 +125,8 @@ pub struct AuthorityStore {

pub(crate) perpetual_tables: Arc<AuthorityPerpetualTables>,

pub(crate) root_state_notify_read: NotifyRead<EpochId, (CheckpointSequenceNumber, Accumulator)>,
pub(crate) root_state_notify_read:
NotifyRead<EpochId, (CheckpointSequenceNumber, GlobalStateHash)>,

/// Whether to enable expensive IOTA conservation check at epoch boundaries.
enable_epoch_iota_conservation_check: bool,
Expand Down Expand Up @@ -243,8 +244,10 @@ impl AuthorityStore {
let store = Arc::new(Self {
mutex_table: MutexTable::new(NUM_SHARDS),
perpetual_tables,
root_state_notify_read:
NotifyRead::<EpochId, (CheckpointSequenceNumber, Accumulator)>::new(),
root_state_notify_read: NotifyRead::<
EpochId,
(CheckpointSequenceNumber, GlobalStateHash),
>::new(),
enable_epoch_iota_conservation_check,
metrics: AuthorityStoreMetrics::new(registry),
});
Expand Down Expand Up @@ -370,8 +373,10 @@ impl AuthorityStore {
let store = Arc::new(Self {
mutex_table: MutexTable::new(NUM_SHARDS),
perpetual_tables,
root_state_notify_read:
NotifyRead::<EpochId, (CheckpointSequenceNumber, Accumulator)>::new(),
root_state_notify_read: NotifyRead::<
EpochId,
(CheckpointSequenceNumber, GlobalStateHash),
>::new(),
enable_epoch_iota_conservation_check,
metrics: AuthorityStoreMetrics::new(registry),
});
Expand Down Expand Up @@ -536,7 +541,7 @@ impl AuthorityStore {
pub async fn notify_read_root_state_hash(
&self,
epoch: EpochId,
) -> IotaResult<(CheckpointSequenceNumber, Accumulator)> {
) -> IotaResult<(CheckpointSequenceNumber, GlobalStateHash)> {
// We need to register waiters _before_ reading from the database to avoid race
// conditions
let registration = self.root_state_notify_read.register_one(&epoch);
Expand Down Expand Up @@ -1717,20 +1722,20 @@ impl AuthorityStore {
}
}

impl AccumulatorStore for AuthorityStore {
fn get_root_state_accumulator_for_epoch(
impl GlobalStateHashStore for AuthorityStore {
fn get_root_state_hash_for_epoch(
&self,
epoch: EpochId,
) -> IotaResult<Option<(CheckpointSequenceNumber, Accumulator)>> {
) -> IotaResult<Option<(CheckpointSequenceNumber, GlobalStateHash)>> {
self.perpetual_tables
.root_state_hash_by_epoch
.get(&epoch)
.map_err(Into::into)
}

fn get_root_state_accumulator_for_highest_epoch(
fn get_root_state_hash_for_highest_epoch(
&self,
) -> IotaResult<Option<(EpochId, (CheckpointSequenceNumber, Accumulator))>> {
) -> IotaResult<Option<(EpochId, (CheckpointSequenceNumber, GlobalStateHash))>> {
Ok(self
.perpetual_tables
.root_state_hash_by_epoch
Expand All @@ -1739,11 +1744,11 @@ impl AccumulatorStore for AuthorityStore {
.transpose()?)
}

fn insert_state_accumulator_for_epoch(
fn insert_state_hash_for_epoch(
&self,
epoch: EpochId,
last_checkpoint_of_epoch: &CheckpointSequenceNumber,
acc: &Accumulator,
acc: &GlobalStateHash,
) -> IotaResult {
self.perpetual_tables
.root_state_hash_by_epoch
Expand Down
Loading
Loading