dusk_node/
vm.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7use dusk_consensus::errors::VstError;
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    ) -> anyhow::Result<(
25        Vec<SpentTransaction>,
26        Vec<Transaction>,
27        VerificationOutput,
28    )>;
29
30    fn verify_state_transition(
31        &self,
32        prev_root: [u8; 32],
33        blk: &Block,
34        voters: &[Voter],
35    ) -> Result<VerificationOutput, VstError>;
36
37    fn accept(
38        &self,
39        prev_root: [u8; 32],
40        blk: &Block,
41        voters: &[Voter],
42    ) -> anyhow::Result<(
43        Vec<SpentTransaction>,
44        VerificationOutput,
45        Vec<ContractTxEvent>,
46    )>;
47
48    fn finalize_state(
49        &self,
50        commit: [u8; 32],
51        to_merge: Vec<[u8; 32]>,
52    ) -> anyhow::Result<()>;
53
54    fn preverify(
55        &self,
56        tx: &Transaction,
57    ) -> anyhow::Result<PreverificationResult>;
58
59    fn get_provisioners(
60        &self,
61        base_commit: [u8; 32],
62    ) -> anyhow::Result<Provisioners>;
63
64    fn get_changed_provisioners(
65        &self,
66        base_commit: [u8; 32],
67    ) -> anyhow::Result<Vec<(node_data::bls::PublicKey, Option<Stake>)>>;
68
69    fn get_provisioner(
70        &self,
71        pk: &BlsPublicKey,
72    ) -> anyhow::Result<Option<Stake>>;
73
74    fn get_state_root(&self) -> anyhow::Result<[u8; 32]>;
75
76    fn move_to_commit(&self, commit: [u8; 32]) -> anyhow::Result<()>;
77
78    /// Returns last finalized state root
79    fn get_finalized_state_root(&self) -> anyhow::Result<[u8; 32]>;
80
81    /// Returns block gas limit
82    fn get_block_gas_limit(&self) -> u64;
83
84    fn revert(&self, state_hash: [u8; 32]) -> anyhow::Result<[u8; 32]>;
85    fn revert_to_finalized(&self) -> anyhow::Result<[u8; 32]>;
86
87    fn gas_per_deploy_byte(&self) -> u64;
88    fn min_deployment_gas_price(&self) -> u64;
89    fn min_gas_limit(&self) -> u64;
90    fn min_deploy_points(&self) -> u64;
91}
92
93#[allow(clippy::large_enum_variant)]
94pub enum PreverificationResult {
95    Valid,
96    // Current account state, nonce used by tx
97    FutureNonce {
98        account: BlsPublicKey,
99        state: AccountData,
100        nonce_used: u64,
101    },
102}