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