Skip to main content

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