1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::{
error::StateSyncError, experimental::execution_phase::ExecutionRequest,
state_replication::StateComputer,
};
use anyhow::Result;
use channel::Sender;
use consensus_types::{block::Block, executed_block::ExecutedBlock};
use diem_crypto::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};
use crate::{
experimental::{buffer_manager::SyncAck, errors::Error},
state_replication::StateComputerCommitCallBackType,
};
use futures::channel::oneshot;
pub struct OrderingStateComputer {
executor_channel: Sender<ExecutionRequest>,
state_computer_for_sync: Arc<dyn StateComputer>,
reset_event_channel_tx: Sender<oneshot::Sender<SyncAck>>,
}
impl OrderingStateComputer {
pub fn new(
executor_channel: Sender<ExecutionRequest>,
state_computer_for_sync: Arc<dyn StateComputer>,
reset_event_channel_tx: Sender<oneshot::Sender<SyncAck>>,
) -> Self {
Self {
executor_channel,
state_computer_for_sync,
reset_event_channel_tx,
}
}
}
#[async_trait::async_trait]
impl StateComputer for OrderingStateComputer {
fn compute(
&self,
_block: &Block,
_parent_block_id: HashValue,
) -> Result<StateComputeResult, ExecutionError> {
Ok(StateComputeResult::new_dummy())
}
async fn commit(
&self,
blocks: &[Arc<ExecutedBlock>],
_finality_proof: LedgerInfoWithSignatures,
_callback: StateComputerCommitCallBackType,
) -> Result<(), ExecutionError> {
assert!(!blocks.is_empty());
Ok(())
}
async fn sync_to(&self, target: LedgerInfoWithSignatures) -> Result<(), StateSyncError> {
fail_point!("consensus::sync_to", |_| {
Err(anyhow::anyhow!("Injected error in sync_to").into())
});
self.state_computer_for_sync.sync_to(target).await?;
let (tx, rx) = oneshot::channel::<SyncAck>();
self.reset_event_channel_tx
.clone()
.send(tx)
.await
.map_err(|_| Error::ResetDropped)?;
rx.await.map_err(|_| Error::ResetDropped)?;
Ok(())
}
}