Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivial: move a few data structures off executor-types #14902

Merged
merged 3 commits into from
Oct 9, 2024
Merged
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion execution/executor-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ rust-version = { workspace = true }
[dependencies]
anyhow = { workspace = true }
aptos-crypto = { workspace = true }
aptos-drop-helper = { workspace = true }
aptos-scratchpad = { workspace = true }
aptos-secure-net = { workspace = true }
aptos-storage-interface = { workspace = true }
Expand Down
5 changes: 1 addition & 4 deletions execution/executor-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use aptos_types::{
write_set::WriteSet,
};
pub use error::{ExecutorError, ExecutorResult};
pub use executed_chunk::ExecutedChunk;
pub use ledger_update_output::LedgerUpdateOutput;
pub use parsed_transaction_output::ParsedTransactionOutput;
use serde::{Deserialize, Serialize};
Expand All @@ -44,8 +43,6 @@ use std::{
};

mod error;
mod executed_chunk;
pub mod execution_output;
mod ledger_update_output;
pub mod parsed_transaction_output;
pub mod state_checkpoint_output;
Expand Down Expand Up @@ -271,7 +268,7 @@ pub trait TransactionReplayer: Send {
verify_execution_mode: &VerifyExecutionMode,
) -> Result<()>;

fn commit(&self) -> Result<ExecutedChunk>;
fn commit(&self) -> Result<Version>;
}

/// A structure that holds relevant information about a chunk that was committed.
Expand Down
10 changes: 6 additions & 4 deletions execution/executor/src/block_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use crate::{
components::{
apply_chunk_output::ApplyChunkOutput, block_tree::BlockTree, chunk_output::ChunkOutput,
apply_chunk_output::ApplyChunkOutput,
block_tree::{block_output::BlockOutput, BlockTree},
chunk_output::ChunkOutput,
},
logging::{LogEntry, LogSchema},
metrics::{
Expand All @@ -17,8 +19,8 @@ use crate::{
use anyhow::Result;
use aptos_crypto::HashValue;
use aptos_executor_types::{
execution_output::ExecutionOutput, state_checkpoint_output::StateCheckpointOutput,
BlockExecutorTrait, ExecutorError, ExecutorResult, StateComputeResult,
state_checkpoint_output::StateCheckpointOutput, BlockExecutorTrait, ExecutorError,
ExecutorResult, StateComputeResult,
};
use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER;
use aptos_infallible::RwLock;
Expand Down Expand Up @@ -277,7 +279,7 @@ where
let _ = self.block_tree.add_block(
parent_block_id,
block_id,
ExecutionOutput::new(state, epoch_state),
BlockOutput::new(state, epoch_state),
)?;
Ok(state_checkpoint_output)
}
Expand Down
15 changes: 10 additions & 5 deletions execution/executor/src/chunk_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
apply_chunk_output::{ensure_no_discard, ensure_no_retry, ApplyChunkOutput},
chunk_commit_queue::{ChunkCommitQueue, ChunkToUpdateLedger},
chunk_output::ChunkOutput,
executed_chunk::ExecutedChunk,
transaction_chunk::TransactionChunkWithProof,
},
logging::{LogEntry, LogSchema},
Expand All @@ -18,8 +19,8 @@ use anyhow::{ensure, Result};
use aptos_crypto::HashValue;
use aptos_drop_helper::DEFAULT_DROPPER;
use aptos_executor_types::{
ChunkCommitNotification, ChunkExecutorTrait, ExecutedChunk, ParsedTransactionOutput,
TransactionReplayer, VerifyExecutionMode,
ChunkCommitNotification, ChunkExecutorTrait, ParsedTransactionOutput, TransactionReplayer,
VerifyExecutionMode,
};
use aptos_experimental_runtimes::thread_manager::THREAD_MANAGER;
use aptos_infallible::{Mutex, RwLock};
Expand Down Expand Up @@ -418,7 +419,7 @@ impl<V: VMExecutor> TransactionReplayer for ChunkExecutor<V> {
)
}

fn commit(&self) -> Result<ExecutedChunk> {
fn commit(&self) -> Result<Version> {
let _guard = CONCURRENCY_GAUGE.concurrency_with(&["replayer", "commit"]);

self.inner.read().as_ref().expect("not reset").commit()
Expand Down Expand Up @@ -484,7 +485,7 @@ impl<V: VMExecutor> TransactionReplayer for ChunkExecutorInner<V> {
Ok(())
}

fn commit(&self) -> Result<ExecutedChunk> {
fn commit(&self) -> Result<Version> {
let started = Instant::now();

let chunk = self.commit_chunk_impl()?;
Expand All @@ -495,7 +496,11 @@ impl<V: VMExecutor> TransactionReplayer for ChunkExecutorInner<V> {
tps = num_committed as f64 / started.elapsed().as_secs_f64(),
"TransactionReplayer::commit() OK"
);
Ok(chunk)

Ok(chunk
.result_state
.current_version
.expect("Version must exist after commit."))
}
}

Expand Down
3 changes: 2 additions & 1 deletion execution/executor/src/components/apply_chunk_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::{
components::{
chunk_output::{update_counters_for_processed_chunk, ChunkOutput},
executed_chunk::ExecutedChunk,
in_memory_state_calculator_v2::InMemoryStateCalculatorV2,
},
metrics::{EXECUTOR_ERRORS, OTHER_TIMERS},
Expand All @@ -17,7 +18,7 @@ use aptos_executor_types::{
parsed_transaction_output::TransactionsWithParsedOutput,
should_forward_to_subscription_service,
state_checkpoint_output::{StateCheckpointOutput, TransactionsByStatus},
ExecutedChunk, LedgerUpdateOutput, ParsedTransactionOutput,
LedgerUpdateOutput, ParsedTransactionOutput,
};
use aptos_experimental_runtimes::thread_manager::optimal_min_len;
use aptos_logger::error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

#![forbid(unsafe_code)]

use crate::LedgerUpdateOutput;
use aptos_executor_types::LedgerUpdateOutput;
use aptos_storage_interface::state_delta::StateDelta;
use aptos_types::epoch_state::EpochState;
use once_cell::sync::OnceCell;

pub struct ExecutionOutput {
pub struct BlockOutput {
state: StateDelta,
/// If set, this is the new epoch info that should be changed to if this is committed.
next_epoch_state: Option<EpochState>,
ledger_update_output: OnceCell<LedgerUpdateOutput>,
}

impl ExecutionOutput {
impl BlockOutput {
pub fn new(state: StateDelta, next_epoch_state: Option<EpochState>) -> Self {
Self {
state,
Expand Down
16 changes: 9 additions & 7 deletions execution/executor/src/components/block_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![forbid(unsafe_code)]

pub mod block_output;
#[cfg(test)]
mod test;

Expand All @@ -12,19 +13,20 @@ use anyhow::{anyhow, ensure, Result};
use aptos_consensus_types::block::Block as ConsensusBlock;
use aptos_crypto::HashValue;
use aptos_drop_helper::DEFAULT_DROPPER;
use aptos_executor_types::{execution_output::ExecutionOutput, ExecutorError, LedgerUpdateOutput};
use aptos_executor_types::{ExecutorError, LedgerUpdateOutput};
use aptos_infallible::Mutex;
use aptos_logger::{debug, info};
use aptos_storage_interface::DbReader;
use aptos_types::{ledger_info::LedgerInfo, proof::definition::LeafCount};
use block_output::BlockOutput;
use std::{
collections::{hash_map::Entry, HashMap},
sync::{mpsc::Receiver, Arc, Weak},
};

pub struct Block {
pub id: HashValue,
pub output: ExecutionOutput,
pub output: BlockOutput,
children: Mutex<Vec<Arc<Block>>>,
block_lookup: Arc<BlockLookup>,
}
Expand Down Expand Up @@ -92,7 +94,7 @@ impl BlockLookupInner {
fn fetch_or_add_block(
&mut self,
id: HashValue,
output: ExecutionOutput,
output: BlockOutput,
parent_id: Option<HashValue>,
block_lookup: &Arc<BlockLookup>,
) -> Result<(Arc<Block>, bool, Option<Arc<Block>>)> {
Expand Down Expand Up @@ -148,7 +150,7 @@ impl BlockLookup {
fn fetch_or_add_block(
self: &Arc<Self>,
id: HashValue,
output: ExecutionOutput,
output: BlockOutput,
parent_id: Option<HashValue>,
) -> Result<Arc<Block>> {
let (block, existing, parent_block) = self
Expand Down Expand Up @@ -224,7 +226,7 @@ impl BlockTree {
ledger_info.consensus_block_id()
};

let output = ExecutionOutput::new_with_ledger_update(
let output = BlockOutput::new_with_ledger_update(
ledger_view.state().clone(),
None,
LedgerUpdateOutput::new_empty(ledger_view.txn_accumulator().clone()),
Expand All @@ -250,7 +252,7 @@ impl BlockTree {
.original_reconfiguration_block_id(committed_block_id),
"Updated with a new root block as a virtual block of reconfiguration block"
);
let output = ExecutionOutput::new_with_ledger_update(
let output = BlockOutput::new_with_ledger_update(
last_committed_block.output.state().clone(),
None,
LedgerUpdateOutput::new_empty(
Expand Down Expand Up @@ -289,7 +291,7 @@ impl BlockTree {
&self,
parent_block_id: HashValue,
id: HashValue,
output: ExecutionOutput,
output: BlockOutput,
) -> Result<Arc<Block>> {
self.block_lookup
.fetch_or_add_block(id, output, Some(parent_block_id))
Expand Down
10 changes: 6 additions & 4 deletions execution/executor/src/components/block_tree/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Parts of the project are originally copyright © Meta Platforms, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::components::block_tree::{epoch_genesis_block_id, BlockLookup, BlockTree};
use crate::components::block_tree::{
block_output::BlockOutput, epoch_genesis_block_id, BlockLookup, BlockTree,
};
use aptos_crypto::{hash::PRE_GENESIS_BLOCK_ID, HashValue};
use aptos_executor_types::{execution_output::ExecutionOutput, LedgerUpdateOutput};
use aptos_executor_types::LedgerUpdateOutput;
use aptos_infallible::Mutex;
use aptos_storage_interface::ExecutedTrees;
use aptos_types::{block_info::BlockInfo, epoch_state::EpochState, ledger_info::LedgerInfo};
Expand Down Expand Up @@ -36,9 +38,9 @@ fn id(index: u64) -> HashValue {
HashValue::new(buf)
}

fn empty_block() -> ExecutionOutput {
fn empty_block() -> BlockOutput {
let result_view = ExecutedTrees::new_empty();
ExecutionOutput::new_with_ledger_update(
BlockOutput::new_with_ledger_update(
result_view.state().clone(),
None,
LedgerUpdateOutput::new_empty(ExecutedTrees::new_empty().txn_accumulator().clone()),
Expand Down
3 changes: 2 additions & 1 deletion execution/executor/src/components/chunk_commit_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#![forbid(unsafe_code)]

use crate::components::executed_chunk::ExecutedChunk;
use anyhow::{anyhow, ensure, Result};
use aptos_executor_types::{state_checkpoint_output::StateCheckpointOutput, ExecutedChunk};
use aptos_executor_types::state_checkpoint_output::StateCheckpointOutput;
use aptos_storage_interface::{state_delta::StateDelta, DbReader, ExecutedTrees};
use aptos_types::{
epoch_state::EpochState,
Expand Down
7 changes: 5 additions & 2 deletions execution/executor/src/components/chunk_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

#![forbid(unsafe_code)]

use crate::{components::apply_chunk_output::ApplyChunkOutput, metrics};
use crate::{
components::{apply_chunk_output::ApplyChunkOutput, executed_chunk::ExecutedChunk},
metrics,
};
use anyhow::Result;
use aptos_crypto::HashValue;
use aptos_executor_service::{
local_executor_helper::SHARDED_BLOCK_EXECUTOR,
remote_executor_client::{get_remote_addresses, REMOTE_SHARDED_BLOCK_EXECUTOR},
};
use aptos_executor_types::{state_checkpoint_output::StateCheckpointOutput, ExecutedChunk};
use aptos_executor_types::state_checkpoint_output::StateCheckpointOutput;
use aptos_logger::{sample, sample::SampleRate, warn};
use aptos_storage_interface::{
cached_state_view::{CachedStateView, StateCache},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#![forbid(unsafe_code)]

use crate::{should_forward_to_subscription_service, ChunkCommitNotification, LedgerUpdateOutput};
use aptos_drop_helper::DEFAULT_DROPPER;
use aptos_executor_types::{
should_forward_to_subscription_service, ChunkCommitNotification, LedgerUpdateOutput,
};
use aptos_storage_interface::{state_delta::StateDelta, ExecutedTrees};
#[cfg(test)]
use aptos_types::account_config::NewEpochEvent;
Expand Down
1 change: 1 addition & 0 deletions execution/executor/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub mod chunk_commit_queue;
pub mod chunk_output;
pub mod in_memory_state_calculator_v2;

pub mod executed_chunk;
pub mod transaction_chunk;
3 changes: 1 addition & 2 deletions execution/executor/src/db_bootstrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

#![forbid(unsafe_code)]

use crate::components::chunk_output::ChunkOutput;
use crate::components::{chunk_output::ChunkOutput, executed_chunk::ExecutedChunk};
use anyhow::{anyhow, ensure, format_err, Result};
use aptos_crypto::HashValue;
use aptos_executor_types::ExecutedChunk;
use aptos_logger::prelude::*;
use aptos_storage_interface::{
async_proof_fetcher::AsyncProofFetcher, cached_state_view::CachedStateView, DbReaderWriter,
Expand Down
4 changes: 2 additions & 2 deletions execution/executor/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::{
block_executor::BlockExecutor,
components::chunk_output::ChunkOutput,
components::{chunk_output::ChunkOutput, executed_chunk::ExecutedChunk},
db_bootstrapper::{generate_waypoint, maybe_bootstrap},
mock_vm::{
encode_mint_transaction, encode_reconfiguration_transaction, encode_transfer_transaction,
Expand All @@ -14,7 +14,7 @@ use crate::{
use aptos_crypto::{ed25519::Ed25519PrivateKey, HashValue, PrivateKey, SigningKey, Uniform};
use aptos_db::AptosDB;
use aptos_executor_types::{
BlockExecutorTrait, ExecutedChunk, LedgerUpdateOutput, TransactionReplayer, VerifyExecutionMode,
BlockExecutorTrait, LedgerUpdateOutput, TransactionReplayer, VerifyExecutionMode,
};
use aptos_storage_interface::{
async_proof_fetcher::AsyncProofFetcher, DbReaderWriter, ExecutedTrees, Result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ impl TransactionRestoreBatchController {
.with_label_values(&["commit_txn_chunk"])
.start_timer();
tokio::task::spawn_blocking(move || {
let committed_chunk = chunk_replayer.commit()?;
let v = committed_chunk.result_state.current_version.unwrap_or(0);
let v = chunk_replayer.commit()?;
let total_replayed = v - first_version + 1;
TRANSACTION_REPLAY_VERSION.set(v as i64);
info!(
Expand Down
Loading