1use dusk_consensus::errors::StateTransitionError;
8use dusk_consensus::operations::{CallParams, VerificationOutput, Voter};
9use dusk_consensus::user::provisioners::Provisioners;
10use dusk_consensus::user::stake::Stake;
11use dusk_core::signatures::bls::PublicKey as BlsPublicKey;
12use dusk_core::transfer::moonlight::AccountData;
13use node_data::events::contract::ContractTxEvent;
14use node_data::ledger::{Block, SpentTransaction, Transaction};
15
16#[derive(Default)]
17pub struct Config {}
18
19pub trait VMExecution: Send + Sync + 'static {
20 fn execute_state_transition<I: Iterator<Item = Transaction>>(
21 &self,
22 params: &CallParams,
23 txs: I,
24 ) -> Result<
25 (Vec<SpentTransaction>, Vec<Transaction>, VerificationOutput),
26 StateTransitionError,
27 >;
28
29 fn verify_state_transition(
30 &self,
31 prev_root: [u8; 32],
32 blk: &Block,
33 voters: &[Voter],
34 ) -> Result<VerificationOutput, StateTransitionError>;
35
36 fn accept(
37 &self,
38 prev_root: [u8; 32],
39 blk: &Block,
40 voters: &[Voter],
41 ) -> anyhow::Result<(
42 Vec<SpentTransaction>,
43 VerificationOutput,
44 Vec<ContractTxEvent>,
45 )>;
46
47 fn finalize_state(
48 &self,
49 commit: [u8; 32],
50 to_merge: Vec<[u8; 32]>,
51 ) -> anyhow::Result<()>;
52
53 fn preverify(
54 &self,
55 tx: &Transaction,
56 ) -> anyhow::Result<PreverificationResult>;
57
58 fn get_provisioners(
59 &self,
60 base_commit: [u8; 32],
61 ) -> anyhow::Result<Provisioners>;
62
63 fn get_changed_provisioners(
64 &self,
65 base_commit: [u8; 32],
66 ) -> anyhow::Result<Vec<(node_data::bls::PublicKey, Option<Stake>)>>;
67
68 fn get_provisioner(
69 &self,
70 pk: &BlsPublicKey,
71 ) -> anyhow::Result<Option<Stake>>;
72
73 fn get_state_root(&self) -> anyhow::Result<[u8; 32]>;
74
75 fn move_to_commit(&self, commit: [u8; 32]) -> anyhow::Result<()>;
76
77 fn get_finalized_state_root(&self) -> anyhow::Result<[u8; 32]>;
79
80 fn get_block_gas_limit(&self) -> u64;
82
83 fn revert(&self, state_hash: [u8; 32]) -> anyhow::Result<[u8; 32]>;
84 fn revert_to_finalized(&self) -> anyhow::Result<[u8; 32]>;
85
86 fn gas_per_deploy_byte(&self) -> u64;
87 fn min_deployment_gas_price(&self) -> u64;
88 fn min_gas_limit(&self) -> u64;
89 fn min_deploy_points(&self) -> u64;
90}
91
92#[allow(clippy::large_enum_variant)]
93pub enum PreverificationResult {
94 Valid,
95 FutureNonce {
97 account: BlsPublicKey,
98 state: AccountData,
99 nonce_used: u64,
100 },
101}