forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[decoupled-execution] We added a new struct OrderingStateComputer to …
…bypass the execution and commit in the state computer; We added two fields in ConsensusConfig: + consensus.decoupled: the global switch to turn on and off the decoupled execution feature. + consensus.channel_size: the size of the channel used to pass the blocks from ordering state computer to the next phase. Related unit tests will be added later after we finish integration. Closes: aptos-labs#8616
- Loading branch information
1 parent
53ed41a
commit 7574d45
Showing
5 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod ordering_state_computer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::{error::StateSyncError, state_replication::StateComputer}; | ||
use anyhow::Result; | ||
use channel::Sender; | ||
use consensus_types::{block::Block, executed_block::ExecutedBlock}; | ||
use diem_crypto::{hash::ACCUMULATOR_PLACEHOLDER_HASH, HashValue}; | ||
use diem_types::ledger_info::LedgerInfoWithSignatures; | ||
use executor_types::{Error as ExecutionError, StateComputeResult}; | ||
use fail::fail_point; | ||
use futures::SinkExt; | ||
use std::{boxed::Box, sync::Arc}; | ||
|
||
/// Ordering-only execution proxy | ||
/// implements StateComputer traits. | ||
/// Used only when node_config.validator.consensus.decoupled = true. | ||
pub struct OrderingStateComputer { | ||
// the channel to pour vectors of blocks into | ||
// the real execution phase (will be handled in ExecutionPhase). | ||
executor_channel: Sender<(Vec<Block>, LedgerInfoWithSignatures)>, | ||
} | ||
|
||
impl OrderingStateComputer { | ||
pub fn new(executor_channel: Sender<(Vec<Block>, LedgerInfoWithSignatures)>) -> Self { | ||
Self { executor_channel } | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl StateComputer for OrderingStateComputer { | ||
fn compute( | ||
&self, | ||
// The block to be executed. | ||
_block: &Block, | ||
// The parent block id. | ||
_parent_block_id: HashValue, | ||
) -> Result<StateComputeResult, ExecutionError> { | ||
// Return dummy block and bypass the execution phase. | ||
// This will break the e2e smoke test (for now because | ||
// no one is actually handling the next phase) if the | ||
// decoupled execution feature is turned on. | ||
Ok(StateComputeResult::new( | ||
*ACCUMULATOR_PLACEHOLDER_HASH, | ||
vec![], | ||
0, | ||
vec![], | ||
0, | ||
None, | ||
vec![], | ||
vec![], | ||
vec![], | ||
)) | ||
} | ||
|
||
/// Send ordered blocks to the real execution phase through the channel. | ||
/// A future is fulfilled right away when the blocks are sent into the channel. | ||
async fn commit( | ||
&self, | ||
blocks: &[Arc<ExecutedBlock>], | ||
finality_proof: LedgerInfoWithSignatures, | ||
) -> Result<(), ExecutionError> { | ||
let ordered_block = blocks.iter().map(|b| b.block().clone()).collect(); | ||
|
||
self.executor_channel | ||
.clone() | ||
.send((ordered_block, finality_proof)) | ||
.await | ||
.map_err(|e| ExecutionError::InternalError { | ||
error: e.to_string(), | ||
})?; | ||
Ok(()) | ||
} | ||
|
||
/// Synchronize to a commit that not present locally. | ||
async fn sync_to(&self, _target: LedgerInfoWithSignatures) -> Result<(), StateSyncError> { | ||
fail_point!("consensus::sync_to", |_| { | ||
Err(anyhow::anyhow!("Injected error in sync_to").into()) | ||
}); | ||
unimplemented!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters