multiversx_chain_vm/blockchain/
vm_config.rs1use std::{ops::Deref, sync::Arc};
2
3use crate::{builtin_functions::BuiltinFunctionContainer, schedule::GasSchedule};
4
5#[derive(Default)]
6pub struct VMConfig {
7 pub builtin_functions: BuiltinFunctionContainer,
8 pub gas_schedule: GasSchedule,
9 pub insert_ghost_accounts: bool,
10}
11
12#[derive(Clone, Default)]
13pub struct VMConfigRef(Arc<VMConfig>);
14
15impl VMConfig {
16 pub fn new() -> Self {
17 Self::default()
18 }
19}
20
21impl VMConfigRef {
22 pub fn new() -> Self {
23 VMConfigRef(Arc::new(VMConfig::new()))
24 }
25
26 pub fn change_gas_schedule(&mut self, gas_schedule: GasSchedule) {
27 let vm_config =
28 Arc::get_mut(&mut self.0).expect("cannot change gas schedule during execution");
29 vm_config.gas_schedule = gas_schedule;
30 }
31
32 pub fn set_insert_ghost_accounts(&mut self, insert_ghost_accounts: bool) {
33 let vm_config = Arc::get_mut(&mut self.0).expect("cannot configure VM during execution");
34 vm_config.insert_ghost_accounts = insert_ghost_accounts;
35 }
36}
37
38impl Deref for VMConfigRef {
39 type Target = VMConfig;
40
41 fn deref(&self) -> &Self::Target {
42 self.0.deref()
43 }
44}