Skip to content

Commit

Permalink
ExecutedTrees -> LedgerSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse committed Dec 2, 2024
1 parent 5d87d94 commit a2b8c87
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 74 deletions.
10 changes: 5 additions & 5 deletions execution/executor/src/block_executor/block_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ impl BlockTree {
fn root_from_db(block_lookup: &Arc<BlockLookup>, db: &Arc<dyn DbReader>) -> Result<Arc<Block>> {
let ledger_info_with_sigs = db.get_latest_ledger_info()?;
let ledger_info = ledger_info_with_sigs.ledger_info();
let ledger_view = db.get_latest_executed_trees()?;
let ledger_summary = db.get_pre_committed_ledger_summary()?;

ensure!(
ledger_view.version() == Some(ledger_info.version()),
ledger_summary.version() == Some(ledger_info.version()),
"Missing ledger info at the end of the ledger. latest version {:?}, LI version {}",
ledger_view.version(),
ledger_summary.version(),
ledger_info.version(),
);

Expand All @@ -223,8 +223,8 @@ impl BlockTree {
};

let output = PartialStateComputeResult::new_empty(
ledger_view.state().clone(),
ledger_view.txn_accumulator().clone(),
ledger_summary.state().clone(),
ledger_summary.txn_accumulator().clone(),
);

block_lookup.fetch_or_add_block(id, output, None)
Expand Down
4 changes: 2 additions & 2 deletions execution/executor/src/block_executor/block_tree/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use aptos_crypto::{hash::PRE_GENESIS_BLOCK_ID, HashValue};
use aptos_infallible::Mutex;
use aptos_storage_interface::ExecutedTrees;
use aptos_storage_interface::LedgerSummary;
use aptos_types::{block_info::BlockInfo, epoch_state::EpochState, ledger_info::LedgerInfo};
use std::sync::Arc;

Expand Down Expand Up @@ -39,7 +39,7 @@ fn id(index: u64) -> HashValue {
}

fn empty_block() -> PartialStateComputeResult {
let result_view = ExecutedTrees::new_empty();
let result_view = LedgerSummary::new_empty();
PartialStateComputeResult::new_empty(
result_view.state().clone(),
result_view.transaction_accumulator.clone(),
Expand Down
6 changes: 3 additions & 3 deletions execution/executor/src/chunk_executor/chunk_commit_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
},
};
use anyhow::{anyhow, ensure, Result};
use aptos_storage_interface::{state_store::state_delta::StateDelta, DbReader, ExecutedTrees};
use aptos_storage_interface::{state_store::state_delta::StateDelta, DbReader, LedgerSummary};
use aptos_types::{proof::accumulator::InMemoryTransactionAccumulator, transaction::Version};
use std::{collections::VecDeque, sync::Arc};

Expand Down Expand Up @@ -41,10 +41,10 @@ pub struct ChunkCommitQueue {

impl ChunkCommitQueue {
pub(crate) fn new_from_db(db: &Arc<dyn DbReader>) -> Result<Self> {
let ExecutedTrees {
let LedgerSummary {
state,
transaction_accumulator,
} = db.get_latest_executed_trees()?;
} = db.get_pre_committed_ledger_summary()?;
Ok(Self {
latest_state: state,
latest_txn_accumulator: transaction_accumulator,
Expand Down
20 changes: 10 additions & 10 deletions execution/executor/src/db_bootstrapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use aptos_storage_interface::{
state_store::state_view::{
async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView,
},
DbReaderWriter, DbWriter, ExecutedTrees,
DbReaderWriter, DbWriter, LedgerSummary,
};
use aptos_types::{
account_config::CORE_CODE_ADDRESS,
Expand All @@ -39,9 +39,9 @@ pub fn generate_waypoint<V: VMBlockExecutor>(
db: &DbReaderWriter,
genesis_txn: &Transaction,
) -> Result<Waypoint> {
let executed_trees = db.reader.get_latest_executed_trees()?;
let ledger_summary = db.reader.get_pre_committed_ledger_summary()?;

let committer = calculate_genesis::<V>(db, executed_trees, genesis_txn)?;
let committer = calculate_genesis::<V>(db, ledger_summary, genesis_txn)?;
Ok(committer.waypoint)
}

Expand All @@ -53,15 +53,15 @@ pub fn maybe_bootstrap<V: VMBlockExecutor>(
genesis_txn: &Transaction,
waypoint: Waypoint,
) -> Result<Option<LedgerInfoWithSignatures>> {
let executed_trees = db.reader.get_latest_executed_trees()?;
let ledger_summary = db.reader.get_pre_committed_ledger_summary()?;
// if the waypoint is not targeted with the genesis txn, it may be either already bootstrapped, or
// aiming for state sync to catch up.
if executed_trees.version().map_or(0, |v| v + 1) != waypoint.version() {
if ledger_summary.version().map_or(0, |v| v + 1) != waypoint.version() {
info!(waypoint = %waypoint, "Skip genesis txn.");
return Ok(None);
}

let committer = calculate_genesis::<V>(db, executed_trees, genesis_txn)?;
let committer = calculate_genesis::<V>(db, ledger_summary, genesis_txn)?;
ensure!(
waypoint == committer.waypoint(),
"Waypoint verification failed. Expected {:?}, got {:?}.",
Expand Down Expand Up @@ -117,14 +117,14 @@ impl GenesisCommitter {

pub fn calculate_genesis<V: VMBlockExecutor>(
db: &DbReaderWriter,
executed_trees: ExecutedTrees,
ledger_summary: LedgerSummary,
genesis_txn: &Transaction,
) -> Result<GenesisCommitter> {
// DB bootstrapper works on either an empty transaction accumulator or an existing block chain.
// In the very extreme and sad situation of losing quorum among validators, we refer to the
// second use case said above.
let genesis_version = executed_trees.version().map_or(0, |v| v + 1);
let base_state_view = executed_trees.verified_state_view(
let genesis_version = ledger_summary.version().map_or(0, |v| v + 1);
let base_state_view = ledger_summary.verified_state_view(
StateViewId::Miscellaneous,
Arc::clone(&db.reader),
Arc::new(AsyncProofFetcher::new(db.reader.clone())),
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn calculate_genesis<V: VMBlockExecutor>(
"Genesis txn didn't output reconfig event."
);

let output = ApplyExecutionOutput::run(execution_output, &executed_trees)?;
let output = ApplyExecutionOutput::run(execution_output, &ledger_summary)?;
let timestamp_usecs = if genesis_version == 0 {
// TODO(aldenhu): fix existing tests before using real timestamp and check on-chain epoch.
GENESIS_TIMESTAMP_USECS
Expand Down
16 changes: 8 additions & 8 deletions execution/executor/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use aptos_executor_types::{
BlockExecutorTrait, ChunkExecutorTrait, TransactionReplayer, VerifyExecutionMode,
};
use aptos_storage_interface::{
state_store::state_view::async_proof_fetcher::AsyncProofFetcher, DbReaderWriter, ExecutedTrees,
state_store::state_view::async_proof_fetcher::AsyncProofFetcher, DbReaderWriter, LedgerSummary,
Result,
};
use aptos_types::{
Expand Down Expand Up @@ -457,7 +457,7 @@ fn apply_transaction_by_writeset(
db: &DbReaderWriter,
transactions_and_writesets: Vec<(Transaction, WriteSet)>,
) {
let ledger_view: ExecutedTrees = db.reader.get_latest_executed_trees().unwrap();
let ledger_summary: LedgerSummary = db.reader.get_pre_committed_ledger_summary().unwrap();

let (txns, txn_outs) = transactions_and_writesets
.iter()
Expand Down Expand Up @@ -485,7 +485,7 @@ fn apply_transaction_by_writeset(
)))
.unzip();

let state_view = ledger_view
let state_view = ledger_summary
.verified_state_view(
StateViewId::Miscellaneous,
Arc::clone(&db.reader),
Expand All @@ -496,7 +496,7 @@ fn apply_transaction_by_writeset(
let chunk_output =
DoGetExecutionOutput::by_transaction_output(txns, txn_outs, state_view).unwrap();

let output = ApplyExecutionOutput::run(chunk_output, &ledger_view).unwrap();
let output = ApplyExecutionOutput::run(chunk_output, &ledger_summary).unwrap();

db.writer
.save_transactions(
Expand Down Expand Up @@ -681,11 +681,11 @@ fn run_transactions_naive(
let db = &executor.db;

for txn in transactions {
let ledger_view: ExecutedTrees = db.reader.get_latest_executed_trees().unwrap();
let ledger_summary: LedgerSummary = db.reader.get_pre_committed_ledger_summary().unwrap();
let out = DoGetExecutionOutput::by_transaction_execution(
&MockVM::new(),
vec![txn].into(),
ledger_view
ledger_summary
.verified_state_view(
StateViewId::Miscellaneous,
Arc::clone(&db.reader),
Expand All @@ -696,7 +696,7 @@ fn run_transactions_naive(
TransactionSliceMetadata::unknown(),
)
.unwrap();
let output = ApplyExecutionOutput::run(out, &ledger_view).unwrap();
let output = ApplyExecutionOutput::run(out, &ledger_summary).unwrap();
db.writer
.save_transactions(
output.expect_complete_result().as_chunk_to_commit(),
Expand All @@ -706,7 +706,7 @@ fn run_transactions_naive(
.unwrap();
}
db.reader
.get_latest_executed_trees()
.get_pre_committed_ledger_summary()
.unwrap()
.transaction_accumulator
.root_hash()
Expand Down
4 changes: 2 additions & 2 deletions execution/executor/src/workflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::types::partial_state_compute_result::PartialStateComputeResult;
use anyhow::Result;
use aptos_executor_types::execution_output::ExecutionOutput;
use aptos_storage_interface::ExecutedTrees;
use aptos_storage_interface::LedgerSummary;
use do_ledger_update::DoLedgerUpdate;
use do_state_checkpoint::DoStateCheckpoint;

Expand All @@ -20,7 +20,7 @@ pub struct ApplyExecutionOutput;
impl ApplyExecutionOutput {
pub fn run(
execution_output: ExecutionOutput,
base_view: &ExecutedTrees,
base_view: &LedgerSummary,
) -> Result<PartialStateComputeResult> {
let state_checkpoint_output = DoStateCheckpoint::run(
&execution_output,
Expand Down
4 changes: 2 additions & 2 deletions peer-monitoring-service/server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use aptos_peer_monitoring_service_types::{
},
PeerMonitoringMetadata, PeerMonitoringServiceError, PeerMonitoringServiceMessage,
};
use aptos_storage_interface::{DbReader, ExecutedTrees, Order};
use aptos_storage_interface::{DbReader, LedgerSummary, Order};
use aptos_time_service::{MockTimeService, TimeService};
use aptos_types::{
account_address::AccountAddress,
Expand Down Expand Up @@ -718,7 +718,7 @@ mod database_mock {
version: Version,
) -> Result<(Option<StateValue>, SparseMerkleProof)>;

fn get_latest_executed_trees(&self) -> Result<ExecutedTrees>;
fn get_pre_committed_ledger_summary(&self) -> Result<LedgerSummary>;

fn get_epoch_ending_ledger_info(&self, known_version: u64) -> Result<LedgerInfoWithSignatures>;

Expand Down
4 changes: 2 additions & 2 deletions state-sync/state-sync-driver/src/tests/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use aptos_data_streaming_service::{
};
use aptos_executor_types::{ChunkCommitNotification, ChunkExecutorTrait};
use aptos_storage_interface::{
chunk_to_commit::ChunkToCommit, DbReader, DbReaderWriter, DbWriter, ExecutedTrees, Order,
chunk_to_commit::ChunkToCommit, DbReader, DbReaderWriter, DbWriter, LedgerSummary, Order,
Result, StateSnapshotReceiver,
};
use aptos_types::{
Expand Down Expand Up @@ -276,7 +276,7 @@ mock! {
version: Version,
) -> Result<(Option<StateValue>, SparseMerkleProof)>;

fn get_latest_executed_trees(&self) -> Result<ExecutedTrees>;
fn get_pre_committed_ledger_summary(&self) -> Result<LedgerSummary>;

fn get_epoch_ending_ledger_info(&self, known_version: u64) -> Result<LedgerInfoWithSignatures>;

Expand Down
4 changes: 2 additions & 2 deletions state-sync/storage-service/server/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use aptos_network::{
},
},
};
use aptos_storage_interface::{DbReader, ExecutedTrees, Order};
use aptos_storage_interface::{DbReader, LedgerSummary, Order};
use aptos_storage_service_notifications::StorageServiceNotifier;
use aptos_storage_service_types::{
requests::StorageServiceRequest, responses::StorageServiceResponse, StorageServiceError,
Expand Down Expand Up @@ -325,7 +325,7 @@ mock! {
version: Version,
) -> aptos_storage_interface::Result<(Option<StateValue>, SparseMerkleProof)>;

fn get_latest_executed_trees(&self) -> aptos_storage_interface::Result<ExecutedTrees>;
fn get_pre_committed_ledger_summary(&self) -> aptos_storage_interface::Result<LedgerSummary>;

fn get_epoch_ending_ledger_info(&self, known_version: u64) ->aptos_storage_interface::Result<LedgerInfoWithSignatures>;

Expand Down
10 changes: 5 additions & 5 deletions storage/aptosdb/src/db/aptosdb_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use aptos_config::config::{
DEFAULT_MAX_NUM_NODES_PER_LRU_CACHE_SHARD,
};
use aptos_crypto::{hash::CryptoHash, HashValue};
use aptos_storage_interface::{DbReader, ExecutedTrees, Order};
use aptos_storage_interface::{DbReader, LedgerSummary, Order};
use aptos_temppath::TempPath;
use aptos_types::{
ledger_info::LedgerInfoWithSignatures,
Expand Down Expand Up @@ -181,8 +181,8 @@ fn test_get_latest_executed_trees() {
let db = AptosDB::new_for_test(&tmp_dir);

// entirely empty db
let empty = db.get_latest_executed_trees().unwrap();
assert!(empty.is_same_view(&ExecutedTrees::new_empty()));
let empty = db.get_pre_committed_ledger_summary().unwrap();
assert!(empty.is_same_view(&LedgerSummary::new_empty()));

// bootstrapped db (any transaction info is in)
let key = StateKey::raw(b"test_key");
Expand All @@ -199,9 +199,9 @@ fn test_get_latest_executed_trees() {
);
put_transaction_infos(&db, 0, &[txn_info.clone()]);

let bootstrapped = db.get_latest_executed_trees().unwrap();
let bootstrapped = db.get_pre_committed_ledger_summary().unwrap();
assert!(
bootstrapped.is_same_view(&ExecutedTrees::new_at_state_checkpoint(
bootstrapped.is_same_view(&LedgerSummary::new_at_state_checkpoint(
txn_info.state_checkpoint_hash().unwrap(),
StateStorageUsage::new_untracked(),
vec![txn_info.hash()],
Expand Down
18 changes: 9 additions & 9 deletions storage/aptosdb/src/db/fake_aptosdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use aptos_storage_interface::{
sharded_state_updates::ShardedStateUpdates, state_delta::StateDelta,
state_view::cached_state_view::ShardedStateCache,
},
AptosDbError, DbReader, DbWriter, ExecutedTrees, MAX_REQUEST_LIMIT,
AptosDbError, DbReader, DbWriter, LedgerSummary, MAX_REQUEST_LIMIT,
};
use aptos_types::{
access_path::AccessPath,
Expand Down Expand Up @@ -200,7 +200,7 @@ impl FakeAptosDB {
first_version, /* num_existing_leaves */
&txn_hashes,
)?;
// Store the transaction hash by position to serve [DbReader::get_latest_executed_trees] calls
// Store the transaction hash by position to serve [DbReader::get_pre_committed_ledger_summary] calls
writes.iter().for_each(|(pos, hash)| {
self.txn_hash_by_position.insert(*pos, *hash);
});
Expand Down Expand Up @@ -833,16 +833,16 @@ impl DbReader for FakeAptosDB {
.get_state_value_with_proof_by_version_ext(state_key, version, root_depth)
}

fn get_latest_executed_trees(&self) -> Result<ExecutedTrees> {
fn get_pre_committed_ledger_summary(&self) -> Result<LedgerSummary> {
// If the genesis is not executed yet, we need to get the executed trees from the inner AptosDB
// This is because when we call save_transactions for the genesis block, we call [AptosDB::save_transactions]
// where there is an expectation that the root of the SMTs are the same pointers. Here,
// we get from the inner AptosDB which ensures that the pointers match when save_transactions is called.
if self.ensure_synced_version().unwrap_or_default() == 0 {
return self.inner.get_latest_executed_trees();
return self.inner.get_pre_committed_ledger_summary();
}

gauged_api("get_latest_executed_trees", || {
gauged_api("get_pre_committed_ledger_summary", || {
let buffered_state = self.buffered_state.lock();
let num_txns = buffered_state
.current_state()
Expand All @@ -852,11 +852,11 @@ impl DbReader for FakeAptosDB {
let frozen_subtrees = self.get_frozen_subtree_hashes(num_txns)?;
let transaction_accumulator =
Arc::new(InMemoryAccumulator::new(frozen_subtrees, num_txns)?);
let executed_trees = ExecutedTrees::new(
let ledger_summary = LedgerSummary::new(
buffered_state.current_state().clone(),
transaction_accumulator,
);
Ok(executed_trees)
Ok(ledger_summary)
})
}

Expand Down Expand Up @@ -946,7 +946,7 @@ impl DbReader for FakeAptosDB {
}
}

/// This is necessary for constructing the [ExecutedTrees] to serve [DbReader::get_latest_executed_trees]
/// This is necessary for constructing the [LedgerSummary] to serve [DbReader::get_pre_committed_ledger_summary]
/// requests.
impl HashReader for FakeAptosDB {
fn get(&self, position: Position) -> anyhow::Result<HashValue> {
Expand Down Expand Up @@ -999,7 +999,7 @@ mod tests {

let mut in_memory_state = db
.inner
.get_latest_executed_trees().state;
.get_pre_committed_ledger_summary().state;

let mut cur_ver: Version = 0;
for (txns_to_commit, ledger_info_with_sigs) in input.iter() {
Expand Down
Loading

0 comments on commit a2b8c87

Please sign in to comment.