Skip to content

Commit

Permalink
trivial: extract StateComputeResult to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse committed Oct 17, 2024
1 parent 51c6917 commit 858418a
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 156 deletions.
2 changes: 1 addition & 1 deletion consensus/consensus-types/src/pipeline_execution_result.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use aptos_executor_types::{ExecutorResult, StateComputeResult};
use aptos_executor_types::{state_compute_result::StateComputeResult, ExecutorResult};
use aptos_types::transaction::SignedTransaction;
use derivative::Derivative;
use futures::future::BoxFuture;
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus-types/src/pipelined_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
vote_proposal::VoteProposal,
};
use aptos_crypto::hash::{HashValue, ACCUMULATOR_PLACEHOLDER_HASH};
use aptos_executor_types::{ExecutorResult, StateComputeResult};
use aptos_executor_types::{state_compute_result::StateComputeResult, ExecutorResult};
use aptos_infallible::Mutex;
use aptos_logger::{error, warn};
use aptos_types::{
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/block_storage/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use aptos_consensus_types::{
wrapped_ledger_info::WrappedLedgerInfo,
};
use aptos_crypto::{hash::ACCUMULATOR_PLACEHOLDER_HASH, HashValue};
use aptos_executor_types::StateComputeResult;
use aptos_executor_types::state_compute_result::StateComputeResult;
use aptos_infallible::{Mutex, RwLock};
use aptos_logger::prelude::*;
use aptos_types::{
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/dag/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use aptos_consensus_types::{
quorum_cert::QuorumCert,
};
use aptos_crypto::HashValue;
use aptos_executor_types::StateComputeResult;
use aptos_executor_types::state_compute_result::StateComputeResult;
use aptos_infallible::RwLock;
use aptos_logger::{error, info};
use aptos_storage_interface::DbReader;
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/execution_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
use aptos_consensus_types::{block::Block, pipeline_execution_result::PipelineExecutionResult};
use aptos_crypto::HashValue;
use aptos_executor_types::{
state_checkpoint_output::StateCheckpointOutput, BlockExecutorTrait, ExecutorError,
ExecutorResult, StateComputeResult,
state_checkpoint_output::StateCheckpointOutput, state_compute_result::StateComputeResult,
BlockExecutorTrait, ExecutorError, ExecutorResult,
};
use aptos_experimental_runtimes::thread_manager::optimal_min_len;
use aptos_logger::{debug, warn};
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/pipeline/buffer_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ mod test {
use super::*;
use aptos_consensus_types::{block::Block, block_data::BlockData};
use aptos_crypto::HashValue;
use aptos_executor_types::StateComputeResult;
use aptos_executor_types::state_compute_result::StateComputeResult;
use aptos_types::{
aggregate_signature::AggregateSignature,
ledger_info::LedgerInfo,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/pipeline/tests/execution_phase_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use aptos_consensus_types::{
quorum_cert::QuorumCert,
};
use aptos_crypto::HashValue;
use aptos_executor_types::{ExecutorError, StateComputeResult};
use aptos_executor_types::{state_compute_result::StateComputeResult, ExecutorError};
use aptos_types::{ledger_info::LedgerInfo, validator_verifier::random_validator_verifier};
use async_trait::async_trait;
use std::sync::{
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/pipeline/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use aptos_consensus_types::{
vote_proposal::VoteProposal,
};
use aptos_crypto::{hash::ACCUMULATOR_PLACEHOLDER_HASH, HashValue};
use aptos_executor_types::StateComputeResult;
use aptos_executor_types::state_compute_result::StateComputeResult;
use aptos_infallible::Mutex;
use aptos_safety_rules::{
test_utils::{make_proposal_with_parent, make_proposal_with_qc},
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/rand/rand_gen/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use aptos_consensus_types::{
quorum_cert::QuorumCert,
};
use aptos_crypto::HashValue;
use aptos_executor_types::StateComputeResult;
use aptos_executor_types::state_compute_result::StateComputeResult;
use aptos_types::{
aggregate_signature::AggregateSignature,
ledger_info::{LedgerInfo, LedgerInfoWithSignatures},
Expand Down
8 changes: 4 additions & 4 deletions consensus/src/state_computer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use aptos_consensus_types::{
pipelined_block::PipelinedBlock,
};
use aptos_crypto::HashValue;
use aptos_executor_types::{BlockExecutorTrait, ExecutorResult, StateComputeResult};
use aptos_executor_types::{
state_compute_result::StateComputeResult, BlockExecutorTrait, ExecutorResult,
};
use aptos_infallible::RwLock;
use aptos_logger::prelude::*;
use aptos_metrics_core::IntGauge;
Expand Down Expand Up @@ -462,9 +464,7 @@ async fn test_commit_sync_race() {
};
use aptos_config::config::transaction_filter_type::Filter;
use aptos_consensus_notifications::Error;
use aptos_executor_types::{
state_checkpoint_output::StateCheckpointOutput, StateComputeResult,
};
use aptos_executor_types::state_checkpoint_output::StateCheckpointOutput;
use aptos_infallible::Mutex;
use aptos_types::{
aggregate_signature::AggregateSignature,
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/state_computer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use aptos_consensus_notifications::{ConsensusNotificationSender, Error};
use aptos_consensus_types::{block::Block, block_data::BlockData};
use aptos_crypto::HashValue;
use aptos_executor_types::{
state_checkpoint_output::StateCheckpointOutput, BlockExecutorTrait, ExecutorResult,
StateComputeResult,
state_checkpoint_output::StateCheckpointOutput, state_compute_result::StateComputeResult,
BlockExecutorTrait, ExecutorResult,
};
use aptos_infallible::Mutex;
use aptos_types::{
Expand Down
4 changes: 3 additions & 1 deletion consensus/src/test_utils/mock_state_computer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use aptos_consensus_types::{
pipelined_block::PipelinedBlock,
};
use aptos_crypto::HashValue;
use aptos_executor_types::{ExecutorError, ExecutorResult, StateComputeResult};
use aptos_executor_types::{
state_compute_result::StateComputeResult, ExecutorError, ExecutorResult,
};
use aptos_logger::debug;
use aptos_types::{
block_executor::config::BlockExecutorConfigFromOnchain, epoch_state::EpochState,
Expand Down
2 changes: 1 addition & 1 deletion execution/executor-test-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use aptos_crypto::{
HashValue,
};
use aptos_executor::db_bootstrapper::{generate_waypoint, maybe_bootstrap};
use aptos_executor_types::StateComputeResult;
use aptos_executor_types::state_compute_result::StateComputeResult;
use aptos_storage_interface::DbReaderWriter;
use aptos_types::{
account_address::AccountAddress,
Expand Down
2 changes: 1 addition & 1 deletion execution/executor-types/src/ledger_update_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![forbid(unsafe_code)]

use crate::StateComputeResult;
use crate::state_compute_result::StateComputeResult;
use anyhow::{ensure, Result};
use aptos_crypto::HashValue;
use aptos_drop_helper::DropHelper;
Expand Down
140 changes: 5 additions & 135 deletions execution/executor-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,29 @@

use crate::state_checkpoint_output::StateCheckpointOutput;
use anyhow::Result;
use aptos_crypto::{
hash::{TransactionAccumulatorHasher, ACCUMULATOR_PLACEHOLDER_HASH},
HashValue,
};
use aptos_crypto::HashValue;
use aptos_scratchpad::{ProofRead, SparseMerkleTree};
use aptos_types::{
account_config::NEW_EPOCH_EVENT_MOVE_TYPE_TAG,
block_executor::{config::BlockExecutorConfigFromOnchain, partitioner::ExecutableBlock},
contract_event::ContractEvent,
dkg::DKG_START_EVENT_MOVE_TYPE_TAG,
epoch_state::EpochState,
jwks::OBSERVED_JWK_UPDATED_MOVE_TYPE_TAG,
ledger_info::LedgerInfoWithSignatures,
proof::{
accumulator::InMemoryTransactionAccumulator, AccumulatorExtensionProof,
SparseMerkleProofExt,
},
proof::SparseMerkleProofExt,
state_store::{state_key::StateKey, state_value::StateValue},
transaction::{
Transaction, TransactionInfo, TransactionListWithProof, TransactionOutputListWithProof,
TransactionStatus, Version,
Version,
},
write_set::WriteSet,
};
pub use error::{ExecutorError, ExecutorResult};
pub use ledger_update_output::LedgerUpdateOutput;
pub use parsed_transaction_output::ParsedTransactionOutput;
use state_compute_result::StateComputeResult;
use std::{
cmp::max,
collections::{BTreeSet, HashMap},
fmt::Debug,
ops::Deref,
sync::{
atomic::{AtomicBool, Ordering},
Expand All @@ -47,6 +39,7 @@ mod error;
mod ledger_update_output;
pub mod parsed_transaction_output;
pub mod state_checkpoint_output;
pub mod state_compute_result;

pub trait ChunkExecutorTrait: Send + Sync {
/// Verifies the transactions based on the provided proofs and ledger info. If the transactions
Expand Down Expand Up @@ -280,129 +273,6 @@ pub struct ChunkCommitNotification {
pub reconfiguration_occurred: bool,
}

/// A structure that summarizes the result of the execution needed for consensus to agree on.
/// The execution is responsible for generating the ID of the new state, which is returned in the
/// result.
///
/// Not every transaction in the payload succeeds: the returned vector keeps the boolean status
/// of success / failure of the transactions.
/// Note that the specific details of compute_status are opaque to StateMachineReplication,
/// which is going to simply pass the results between StateComputer and PayloadClient.
#[derive(Debug, Default, Clone)]
pub struct StateComputeResult {
ledger_update_output: LedgerUpdateOutput,
/// If set, this is the new epoch info that should be changed to if this is committed.
next_epoch_state: Option<EpochState>,
}

impl StateComputeResult {
pub fn new(
ledger_update_output: LedgerUpdateOutput,
next_epoch_state: Option<EpochState>,
) -> Self {
Self {
ledger_update_output,
next_epoch_state,
}
}

pub fn new_empty(transaction_accumulator: Arc<InMemoryTransactionAccumulator>) -> Self {
Self {
ledger_update_output: LedgerUpdateOutput::new_empty(transaction_accumulator),
next_epoch_state: None,
}
}

/// generate a new dummy state compute result with a given root hash.
/// this function is used in RandomComputeResultStateComputer to assert that the compute
/// function is really called.
pub fn new_dummy_with_root_hash(root_hash: HashValue) -> Self {
Self {
ledger_update_output: LedgerUpdateOutput::new_dummy_with_root_hash(root_hash),
next_epoch_state: None,
}
}

/// generate a new dummy state compute result with ACCUMULATOR_PLACEHOLDER_HASH as the root hash.
/// this function is used in ordering_state_computer as a dummy state compute result,
/// where the real compute result is generated after ordering_state_computer.commit pushes
/// the blocks and the finality proof to the execution phase.
pub fn new_dummy() -> Self {
StateComputeResult::new_dummy_with_root_hash(*ACCUMULATOR_PLACEHOLDER_HASH)
}

#[cfg(any(test, feature = "fuzzing"))]
pub fn new_dummy_with_input_txns(txns: Vec<Transaction>) -> Self {
Self {
ledger_update_output: LedgerUpdateOutput::new_dummy_with_input_txns(txns),
next_epoch_state: None,
}
}

pub fn version(&self) -> Version {
max(self.ledger_update_output.next_version(), 1)
.checked_sub(1)
.expect("Integer overflow occurred")
}

pub fn root_hash(&self) -> HashValue {
self.ledger_update_output.transaction_accumulator.root_hash
}

pub fn compute_status_for_input_txns(&self) -> &Vec<TransactionStatus> {
&self.ledger_update_output.statuses_for_input_txns
}

pub fn transactions_to_commit_len(&self) -> usize {
self.ledger_update_output.to_commit.len()
}

/// On top of input transactions (which contain BlockMetadata and Validator txns),
/// filter out those that should be committed, and add StateCheckpoint/BlockEpilogue if needed.
pub fn transactions_to_commit(&self) -> Vec<Transaction> {
self.ledger_update_output
.to_commit
.iter()
.map(|t| t.transaction.clone())
.collect()
}

pub fn epoch_state(&self) -> &Option<EpochState> {
&self.next_epoch_state
}

pub fn extension_proof(&self) -> AccumulatorExtensionProof<TransactionAccumulatorHasher> {
AccumulatorExtensionProof::new(
self.ledger_update_output
.transaction_accumulator
.frozen_subtree_roots
.clone(),
self.ledger_update_output.transaction_accumulator.num_leaves,
self.transaction_info_hashes().to_vec(),
)
}

pub fn transaction_info_hashes(&self) -> &Vec<HashValue> {
&self.ledger_update_output.transaction_info_hashes
}

pub fn num_leaves(&self) -> u64 {
self.ledger_update_output.next_version()
}

pub fn has_reconfiguration(&self) -> bool {
self.next_epoch_state.is_some()
}

pub fn subscribable_events(&self) -> &[ContractEvent] {
&self.ledger_update_output.subscribable_events
}

pub fn is_reconfiguration_suffix(&self) -> bool {
self.has_reconfiguration() && self.compute_status_for_input_txns().is_empty()
}
}

pub struct ProofReader {
proofs: HashMap<HashValue, SparseMerkleProofExt>,
}
Expand Down
Loading

0 comments on commit 858418a

Please sign in to comment.