5
5
6
6
use crate :: state_checkpoint_output:: StateCheckpointOutput ;
7
7
use anyhow:: Result ;
8
- use aptos_crypto:: {
9
- hash:: { TransactionAccumulatorHasher , ACCUMULATOR_PLACEHOLDER_HASH } ,
10
- HashValue ,
11
- } ;
8
+ use aptos_crypto:: HashValue ;
12
9
use aptos_scratchpad:: { ProofRead , SparseMerkleTree } ;
13
10
use aptos_types:: {
14
11
account_config:: NEW_EPOCH_EVENT_MOVE_TYPE_TAG ,
15
12
block_executor:: { config:: BlockExecutorConfigFromOnchain , partitioner:: ExecutableBlock } ,
16
13
contract_event:: ContractEvent ,
17
14
dkg:: DKG_START_EVENT_MOVE_TYPE_TAG ,
18
- epoch_state:: EpochState ,
19
15
jwks:: OBSERVED_JWK_UPDATED_MOVE_TYPE_TAG ,
20
16
ledger_info:: LedgerInfoWithSignatures ,
21
- proof:: {
22
- accumulator:: InMemoryTransactionAccumulator , AccumulatorExtensionProof ,
23
- SparseMerkleProofExt ,
24
- } ,
17
+ proof:: SparseMerkleProofExt ,
25
18
state_store:: { state_key:: StateKey , state_value:: StateValue } ,
26
19
transaction:: {
27
20
Transaction , TransactionInfo , TransactionListWithProof , TransactionOutputListWithProof ,
28
- TransactionStatus , Version ,
21
+ Version ,
29
22
} ,
30
23
write_set:: WriteSet ,
31
24
} ;
32
25
pub use error:: { ExecutorError , ExecutorResult } ;
33
26
pub use ledger_update_output:: LedgerUpdateOutput ;
34
27
pub use parsed_transaction_output:: ParsedTransactionOutput ;
28
+ use state_compute_result:: StateComputeResult ;
35
29
use std:: {
36
- cmp:: max,
37
30
collections:: { BTreeSet , HashMap } ,
38
- fmt:: Debug ,
39
31
ops:: Deref ,
40
32
sync:: {
41
33
atomic:: { AtomicBool , Ordering } ,
@@ -47,6 +39,7 @@ mod error;
47
39
mod ledger_update_output;
48
40
pub mod parsed_transaction_output;
49
41
pub mod state_checkpoint_output;
42
+ pub mod state_compute_result;
50
43
51
44
pub trait ChunkExecutorTrait : Send + Sync {
52
45
/// Verifies the transactions based on the provided proofs and ledger info. If the transactions
@@ -280,129 +273,6 @@ pub struct ChunkCommitNotification {
280
273
pub reconfiguration_occurred : bool ,
281
274
}
282
275
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
-
406
276
pub struct ProofReader {
407
277
proofs : HashMap < HashValue , SparseMerkleProofExt > ,
408
278
}
0 commit comments