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::StateTransitionError;
8use dusk_consensus::operations::{
9    StateTransitionData, StateTransitionResult, Voter,
10};
11use dusk_consensus::user::provisioners::Provisioners;
12use dusk_consensus::user::stake::Stake;
13use dusk_core::signatures::bls::PublicKey as BlsPublicKey;
14use dusk_core::transfer::moonlight::AccountData;
15use node_data::events::contract::ContractTxEvent;
16use node_data::ledger::{Block, SpentTransaction, Transaction};
17
18#[derive(Default)]
19pub struct Config {}
20
21pub trait VMExecution: Send + Sync + 'static {
22    fn create_state_transition<I: Iterator<Item = Transaction>>(
23        &self,
24        transition_data: &StateTransitionData,
25        mempool_txs: I,
26    ) -> Result<
27        (
28            Vec<SpentTransaction>,
29            Vec<Transaction>,
30            StateTransitionResult,
31        ),
32        StateTransitionError,
33    >;
34
35    fn verify_state_transition(
36        &self,
37        prev_state: [u8; 32],
38        blk: &Block,
39        cert_voters: &[Voter],
40    ) -> Result<(), StateTransitionError>;
41
42    fn accept_state_transition(
43        &self,
44        prev_state: [u8; 32],
45        blk: &Block,
46        cert_voters: &[Voter],
47    ) -> Result<
48        (Vec<SpentTransaction>, Vec<ContractTxEvent>),
49        StateTransitionError,
50    >;
51
52    fn finalize_state(
53        &self,
54        commit: [u8; 32],
55        to_merge: Vec<[u8; 32]>,
56    ) -> anyhow::Result<()>;
57
58    fn preverify(
59        &self,
60        tx: &Transaction,
61    ) -> anyhow::Result<PreverificationResult>;
62
63    fn get_provisioners(
64        &self,
65        base_commit: [u8; 32],
66    ) -> anyhow::Result<Provisioners>;
67
68    fn get_changed_provisioners(
69        &self,
70        base_commit: [u8; 32],
71    ) -> anyhow::Result<Vec<(node_data::bls::PublicKey, Option<Stake>)>>;
72
73    fn get_provisioner(
74        &self,
75        pk: &BlsPublicKey,
76    ) -> anyhow::Result<Option<Stake>>;
77
78    fn get_state_root(&self) -> anyhow::Result<[u8; 32]>;
79
80    fn move_to_commit(&self, commit: [u8; 32]) -> anyhow::Result<()>;
81
82    /// Returns last finalized state root
83    fn get_finalized_state_root(&self) -> anyhow::Result<[u8; 32]>;
84
85    /// Returns block gas limit
86    fn get_block_gas_limit(&self) -> u64;
87
88    fn revert(&self, state_hash: [u8; 32]) -> anyhow::Result<[u8; 32]>;
89    fn revert_to_finalized(&self) -> anyhow::Result<[u8; 32]>;
90
91    fn gas_per_deploy_byte(&self) -> u64;
92    fn min_deployment_gas_price(&self) -> u64;
93    fn min_gas_limit(&self) -> u64;
94    fn min_deploy_points(&self) -> u64;
95
96    fn gas_per_blob(&self) -> u64;
97    fn blob_active(&self, block_height: u64) -> bool;
98    fn wasm64_disabled(&self, block_height: u64) -> bool;
99    fn wasm32_disabled(&self, block_height: u64) -> bool;
100    fn third_party_disabled(&self, block_height: u64) -> bool;
101}
102
103#[allow(clippy::large_enum_variant)]
104pub enum PreverificationResult {
105    Valid,
106    // Current account state, nonce used by tx
107    FutureNonce {
108        account: BlsPublicKey,
109        state: AccountData,
110        nonce_used: u64,
111    },
112}