Skip to content

Commit 858418a

Browse files
committed
trivial: extract StateComputeResult to separate file
1 parent 51c6917 commit 858418a

File tree

17 files changed

+166
-156
lines changed

17 files changed

+166
-156
lines changed

consensus/consensus-types/src/pipeline_execution_result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Aptos Foundation
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use aptos_executor_types::{ExecutorResult, StateComputeResult};
4+
use aptos_executor_types::{state_compute_result::StateComputeResult, ExecutorResult};
55
use aptos_types::transaction::SignedTransaction;
66
use derivative::Derivative;
77
use futures::future::BoxFuture;

consensus/consensus-types/src/pipelined_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
vote_proposal::VoteProposal,
1212
};
1313
use aptos_crypto::hash::{HashValue, ACCUMULATOR_PLACEHOLDER_HASH};
14-
use aptos_executor_types::{ExecutorResult, StateComputeResult};
14+
use aptos_executor_types::{state_compute_result::StateComputeResult, ExecutorResult};
1515
use aptos_infallible::Mutex;
1616
use aptos_logger::{error, warn};
1717
use aptos_types::{

consensus/src/block_storage/block_store.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use aptos_consensus_types::{
2929
wrapped_ledger_info::WrappedLedgerInfo,
3030
};
3131
use aptos_crypto::{hash::ACCUMULATOR_PLACEHOLDER_HASH, HashValue};
32-
use aptos_executor_types::StateComputeResult;
32+
use aptos_executor_types::state_compute_result::StateComputeResult;
3333
use aptos_infallible::{Mutex, RwLock};
3434
use aptos_logger::prelude::*;
3535
use aptos_types::{

consensus/src/dag/adapter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use aptos_consensus_types::{
2525
quorum_cert::QuorumCert,
2626
};
2727
use aptos_crypto::HashValue;
28-
use aptos_executor_types::StateComputeResult;
28+
use aptos_executor_types::state_compute_result::StateComputeResult;
2929
use aptos_infallible::RwLock;
3030
use aptos_logger::{error, info};
3131
use aptos_storage_interface::DbReader;

consensus/src/execution_pipeline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::{
1313
use aptos_consensus_types::{block::Block, pipeline_execution_result::PipelineExecutionResult};
1414
use aptos_crypto::HashValue;
1515
use aptos_executor_types::{
16-
state_checkpoint_output::StateCheckpointOutput, BlockExecutorTrait, ExecutorError,
17-
ExecutorResult, StateComputeResult,
16+
state_checkpoint_output::StateCheckpointOutput, state_compute_result::StateComputeResult,
17+
BlockExecutorTrait, ExecutorError, ExecutorResult,
1818
};
1919
use aptos_experimental_runtimes::thread_manager::optimal_min_len;
2020
use aptos_logger::{debug, warn};

consensus/src/pipeline/buffer_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ mod test {
464464
use super::*;
465465
use aptos_consensus_types::{block::Block, block_data::BlockData};
466466
use aptos_crypto::HashValue;
467-
use aptos_executor_types::StateComputeResult;
467+
use aptos_executor_types::state_compute_result::StateComputeResult;
468468
use aptos_types::{
469469
aggregate_signature::AggregateSignature,
470470
ledger_info::LedgerInfo,

consensus/src/pipeline/tests/execution_phase_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use aptos_consensus_types::{
2020
quorum_cert::QuorumCert,
2121
};
2222
use aptos_crypto::HashValue;
23-
use aptos_executor_types::{ExecutorError, StateComputeResult};
23+
use aptos_executor_types::{state_compute_result::StateComputeResult, ExecutorError};
2424
use aptos_types::{ledger_info::LedgerInfo, validator_verifier::random_validator_verifier};
2525
use async_trait::async_trait;
2626
use std::sync::{

consensus/src/pipeline/tests/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use aptos_consensus_types::{
1111
vote_proposal::VoteProposal,
1212
};
1313
use aptos_crypto::{hash::ACCUMULATOR_PLACEHOLDER_HASH, HashValue};
14-
use aptos_executor_types::StateComputeResult;
14+
use aptos_executor_types::state_compute_result::StateComputeResult;
1515
use aptos_infallible::Mutex;
1616
use aptos_safety_rules::{
1717
test_utils::{make_proposal_with_parent, make_proposal_with_qc},

consensus/src/rand/rand_gen/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use aptos_consensus_types::{
1313
quorum_cert::QuorumCert,
1414
};
1515
use aptos_crypto::HashValue;
16-
use aptos_executor_types::StateComputeResult;
16+
use aptos_executor_types::state_compute_result::StateComputeResult;
1717
use aptos_types::{
1818
aggregate_signature::AggregateSignature,
1919
ledger_info::{LedgerInfo, LedgerInfoWithSignatures},

consensus/src/state_computer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use aptos_consensus_types::{
2424
pipelined_block::PipelinedBlock,
2525
};
2626
use aptos_crypto::HashValue;
27-
use aptos_executor_types::{BlockExecutorTrait, ExecutorResult, StateComputeResult};
27+
use aptos_executor_types::{
28+
state_compute_result::StateComputeResult, BlockExecutorTrait, ExecutorResult,
29+
};
2830
use aptos_infallible::RwLock;
2931
use aptos_logger::prelude::*;
3032
use aptos_metrics_core::IntGauge;
@@ -462,9 +464,7 @@ async fn test_commit_sync_race() {
462464
};
463465
use aptos_config::config::transaction_filter_type::Filter;
464466
use aptos_consensus_notifications::Error;
465-
use aptos_executor_types::{
466-
state_checkpoint_output::StateCheckpointOutput, StateComputeResult,
467-
};
467+
use aptos_executor_types::state_checkpoint_output::StateCheckpointOutput;
468468
use aptos_infallible::Mutex;
469469
use aptos_types::{
470470
aggregate_signature::AggregateSignature,

consensus/src/state_computer_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use aptos_consensus_notifications::{ConsensusNotificationSender, Error};
1212
use aptos_consensus_types::{block::Block, block_data::BlockData};
1313
use aptos_crypto::HashValue;
1414
use aptos_executor_types::{
15-
state_checkpoint_output::StateCheckpointOutput, BlockExecutorTrait, ExecutorResult,
16-
StateComputeResult,
15+
state_checkpoint_output::StateCheckpointOutput, state_compute_result::StateComputeResult,
16+
BlockExecutorTrait, ExecutorResult,
1717
};
1818
use aptos_infallible::Mutex;
1919
use aptos_types::{

consensus/src/test_utils/mock_state_computer.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use aptos_consensus_types::{
1717
pipelined_block::PipelinedBlock,
1818
};
1919
use aptos_crypto::HashValue;
20-
use aptos_executor_types::{ExecutorError, ExecutorResult, StateComputeResult};
20+
use aptos_executor_types::{
21+
state_compute_result::StateComputeResult, ExecutorError, ExecutorResult,
22+
};
2123
use aptos_logger::debug;
2224
use aptos_types::{
2325
block_executor::config::BlockExecutorConfigFromOnchain, epoch_state::EpochState,

execution/executor-test-helpers/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use aptos_crypto::{
1010
HashValue,
1111
};
1212
use aptos_executor::db_bootstrapper::{generate_waypoint, maybe_bootstrap};
13-
use aptos_executor_types::StateComputeResult;
13+
use aptos_executor_types::state_compute_result::StateComputeResult;
1414
use aptos_storage_interface::DbReaderWriter;
1515
use aptos_types::{
1616
account_address::AccountAddress,

execution/executor-types/src/ledger_update_output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![forbid(unsafe_code)]
55

6-
use crate::StateComputeResult;
6+
use crate::state_compute_result::StateComputeResult;
77
use anyhow::{ensure, Result};
88
use aptos_crypto::HashValue;
99
use aptos_drop_helper::DropHelper;

execution/executor-types/src/lib.rs

+5-135
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,29 @@
55

66
use crate::state_checkpoint_output::StateCheckpointOutput;
77
use anyhow::Result;
8-
use aptos_crypto::{
9-
hash::{TransactionAccumulatorHasher, ACCUMULATOR_PLACEHOLDER_HASH},
10-
HashValue,
11-
};
8+
use aptos_crypto::HashValue;
129
use aptos_scratchpad::{ProofRead, SparseMerkleTree};
1310
use aptos_types::{
1411
account_config::NEW_EPOCH_EVENT_MOVE_TYPE_TAG,
1512
block_executor::{config::BlockExecutorConfigFromOnchain, partitioner::ExecutableBlock},
1613
contract_event::ContractEvent,
1714
dkg::DKG_START_EVENT_MOVE_TYPE_TAG,
18-
epoch_state::EpochState,
1915
jwks::OBSERVED_JWK_UPDATED_MOVE_TYPE_TAG,
2016
ledger_info::LedgerInfoWithSignatures,
21-
proof::{
22-
accumulator::InMemoryTransactionAccumulator, AccumulatorExtensionProof,
23-
SparseMerkleProofExt,
24-
},
17+
proof::SparseMerkleProofExt,
2518
state_store::{state_key::StateKey, state_value::StateValue},
2619
transaction::{
2720
Transaction, TransactionInfo, TransactionListWithProof, TransactionOutputListWithProof,
28-
TransactionStatus, Version,
21+
Version,
2922
},
3023
write_set::WriteSet,
3124
};
3225
pub use error::{ExecutorError, ExecutorResult};
3326
pub use ledger_update_output::LedgerUpdateOutput;
3427
pub use parsed_transaction_output::ParsedTransactionOutput;
28+
use state_compute_result::StateComputeResult;
3529
use std::{
36-
cmp::max,
3730
collections::{BTreeSet, HashMap},
38-
fmt::Debug,
3931
ops::Deref,
4032
sync::{
4133
atomic::{AtomicBool, Ordering},
@@ -47,6 +39,7 @@ mod error;
4739
mod ledger_update_output;
4840
pub mod parsed_transaction_output;
4941
pub mod state_checkpoint_output;
42+
pub mod state_compute_result;
5043

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

283-
/// A structure that summarizes the result of the execution needed for consensus to agree on.
284-
/// The execution is responsible for generating the ID of the new state, which is returned in the
285-
/// result.
286-
///
287-
/// Not every transaction in the payload succeeds: the returned vector keeps the boolean status
288-
/// of success / failure of the transactions.
289-
/// Note that the specific details of compute_status are opaque to StateMachineReplication,
290-
/// which is going to simply pass the results between StateComputer and PayloadClient.
291-
#[derive(Debug, Default, Clone)]
292-
pub struct StateComputeResult {
293-
ledger_update_output: LedgerUpdateOutput,
294-
/// If set, this is the new epoch info that should be changed to if this is committed.
295-
next_epoch_state: Option<EpochState>,
296-
}
297-
298-
impl StateComputeResult {
299-
pub fn new(
300-
ledger_update_output: LedgerUpdateOutput,
301-
next_epoch_state: Option<EpochState>,
302-
) -> Self {
303-
Self {
304-
ledger_update_output,
305-
next_epoch_state,
306-
}
307-
}
308-
309-
pub fn new_empty(transaction_accumulator: Arc<InMemoryTransactionAccumulator>) -> Self {
310-
Self {
311-
ledger_update_output: LedgerUpdateOutput::new_empty(transaction_accumulator),
312-
next_epoch_state: None,
313-
}
314-
}
315-
316-
/// generate a new dummy state compute result with a given root hash.
317-
/// this function is used in RandomComputeResultStateComputer to assert that the compute
318-
/// function is really called.
319-
pub fn new_dummy_with_root_hash(root_hash: HashValue) -> Self {
320-
Self {
321-
ledger_update_output: LedgerUpdateOutput::new_dummy_with_root_hash(root_hash),
322-
next_epoch_state: None,
323-
}
324-
}
325-
326-
/// generate a new dummy state compute result with ACCUMULATOR_PLACEHOLDER_HASH as the root hash.
327-
/// this function is used in ordering_state_computer as a dummy state compute result,
328-
/// where the real compute result is generated after ordering_state_computer.commit pushes
329-
/// the blocks and the finality proof to the execution phase.
330-
pub fn new_dummy() -> Self {
331-
StateComputeResult::new_dummy_with_root_hash(*ACCUMULATOR_PLACEHOLDER_HASH)
332-
}
333-
334-
#[cfg(any(test, feature = "fuzzing"))]
335-
pub fn new_dummy_with_input_txns(txns: Vec<Transaction>) -> Self {
336-
Self {
337-
ledger_update_output: LedgerUpdateOutput::new_dummy_with_input_txns(txns),
338-
next_epoch_state: None,
339-
}
340-
}
341-
342-
pub fn version(&self) -> Version {
343-
max(self.ledger_update_output.next_version(), 1)
344-
.checked_sub(1)
345-
.expect("Integer overflow occurred")
346-
}
347-
348-
pub fn root_hash(&self) -> HashValue {
349-
self.ledger_update_output.transaction_accumulator.root_hash
350-
}
351-
352-
pub fn compute_status_for_input_txns(&self) -> &Vec<TransactionStatus> {
353-
&self.ledger_update_output.statuses_for_input_txns
354-
}
355-
356-
pub fn transactions_to_commit_len(&self) -> usize {
357-
self.ledger_update_output.to_commit.len()
358-
}
359-
360-
/// On top of input transactions (which contain BlockMetadata and Validator txns),
361-
/// filter out those that should be committed, and add StateCheckpoint/BlockEpilogue if needed.
362-
pub fn transactions_to_commit(&self) -> Vec<Transaction> {
363-
self.ledger_update_output
364-
.to_commit
365-
.iter()
366-
.map(|t| t.transaction.clone())
367-
.collect()
368-
}
369-
370-
pub fn epoch_state(&self) -> &Option<EpochState> {
371-
&self.next_epoch_state
372-
}
373-
374-
pub fn extension_proof(&self) -> AccumulatorExtensionProof<TransactionAccumulatorHasher> {
375-
AccumulatorExtensionProof::new(
376-
self.ledger_update_output
377-
.transaction_accumulator
378-
.frozen_subtree_roots
379-
.clone(),
380-
self.ledger_update_output.transaction_accumulator.num_leaves,
381-
self.transaction_info_hashes().to_vec(),
382-
)
383-
}
384-
385-
pub fn transaction_info_hashes(&self) -> &Vec<HashValue> {
386-
&self.ledger_update_output.transaction_info_hashes
387-
}
388-
389-
pub fn num_leaves(&self) -> u64 {
390-
self.ledger_update_output.next_version()
391-
}
392-
393-
pub fn has_reconfiguration(&self) -> bool {
394-
self.next_epoch_state.is_some()
395-
}
396-
397-
pub fn subscribable_events(&self) -> &[ContractEvent] {
398-
&self.ledger_update_output.subscribable_events
399-
}
400-
401-
pub fn is_reconfiguration_suffix(&self) -> bool {
402-
self.has_reconfiguration() && self.compute_status_for_input_txns().is_empty()
403-
}
404-
}
405-
406276
pub struct ProofReader {
407277
proofs: HashMap<HashValue, SparseMerkleProofExt>,
408278
}

0 commit comments

Comments
 (0)