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
#![forbid(unsafe_code)]
use crate::{
execution_strategies::types::{Block, Executor, ExecutorResult, PartitionStrategy},
executor::FakeExecutor,
};
use diem_types::{transaction::SignedTransaction, vm_status::VMStatus};
#[derive(Debug, Clone)]
pub struct BasicStrategy;
impl PartitionStrategy for BasicStrategy {
type Txn = SignedTransaction;
fn partition(&mut self, block: Block<Self::Txn>) -> Vec<Block<SignedTransaction>> {
vec![block]
}
}
#[derive(Debug)]
pub struct BasicExecutor {
executor: FakeExecutor,
strategy: BasicStrategy,
}
impl Default for BasicExecutor {
fn default() -> Self {
Self::new()
}
}
impl BasicExecutor {
pub fn new() -> Self {
Self {
executor: FakeExecutor::from_genesis_file(),
strategy: BasicStrategy,
}
}
}
impl Executor for BasicExecutor {
type Txn = <BasicStrategy as PartitionStrategy>::Txn;
type BlockResult = VMStatus;
fn execute_block(&mut self, txns: Block<Self::Txn>) -> ExecutorResult<Self::BlockResult> {
let mut block = self.strategy.partition(txns);
let outputs = self.executor.execute_block(block.remove(0))?;
for output in &outputs {
self.executor.apply_write_set(output.write_set())
}
Ok(outputs)
}
}