use fuel_types::bytes::WORD_SIZE;
use fuel_types::{AssetId, Bytes32};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct ConsensusParameters {
pub contract_max_size: u64,
pub max_inputs: u64,
pub max_outputs: u64,
pub max_witnesses: u64,
pub max_gas_per_tx: u64,
pub max_script_length: u64,
pub max_script_data_length: u64,
pub max_storage_slots: u64,
pub max_predicate_length: u64,
pub max_predicate_data_length: u64,
pub gas_price_factor: u64,
pub gas_per_byte: u64,
pub max_message_data_length: u64,
}
impl ConsensusParameters {
pub const DEFAULT: Self = Self {
contract_max_size: 16 * 1024 * 1024,
max_inputs: 255,
max_outputs: 255,
max_witnesses: 255,
max_gas_per_tx: 100_000_000,
max_script_length: 1024 * 1024,
max_script_data_length: 1024 * 1024,
max_storage_slots: 255,
max_predicate_length: 1024 * 1024,
max_predicate_data_length: 1024 * 1024,
gas_price_factor: 1_000_000_000,
gas_per_byte: 4,
max_message_data_length: 1024 * 1024,
};
pub const fn tx_offset(&self) -> usize {
Bytes32::LEN + WORD_SIZE + self.max_inputs as usize * (AssetId::LEN + WORD_SIZE)
}
pub const fn with_contract_max_size(self, contract_max_size: u64) -> Self {
let Self {
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_inputs(self, max_inputs: u64) -> Self {
let Self {
contract_max_size,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_outputs(self, max_outputs: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_witnesses(self, max_witnesses: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_gas_per_tx(self, max_gas_per_tx: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_script_length(self, max_script_length: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_script_data_length(self, max_script_data_length: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_storage_slots(self, max_storage_slots: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_predicate_length(self, max_predicate_length: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_predicate_data_length(self, max_predicate_data_length: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_gas_price_factor(self, gas_price_factor: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_per_byte,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_gas_per_byte(self, gas_per_byte: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
max_message_data_length,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
pub const fn with_max_message_data_length(self, max_message_data_length: u64) -> Self {
let Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
..
} = self;
Self {
contract_max_size,
max_inputs,
max_outputs,
max_witnesses,
max_gas_per_tx,
max_script_length,
max_script_data_length,
max_storage_slots,
max_predicate_length,
max_predicate_data_length,
gas_price_factor,
gas_per_byte,
max_message_data_length,
}
}
}
impl Default for ConsensusParameters {
fn default() -> Self {
Self::DEFAULT
}
}
#[deprecated(since = "0.12.2", note = "use `ConsensusParameters` instead.")]
pub mod default_parameters {
use super::ConsensusParameters;
pub const CONTRACT_MAX_SIZE: u64 = ConsensusParameters::DEFAULT.contract_max_size;
pub const MAX_INPUTS: u64 = ConsensusParameters::DEFAULT.max_inputs;
pub const MAX_OUTPUTS: u64 = ConsensusParameters::DEFAULT.max_outputs;
pub const MAX_WITNESSES: u64 = ConsensusParameters::DEFAULT.max_witnesses;
pub const MAX_GAS_PER_TX: u64 = ConsensusParameters::DEFAULT.max_gas_per_tx;
pub const MAX_SCRIPT_LENGTH: u64 = ConsensusParameters::DEFAULT.max_script_length;
pub const MAX_SCRIPT_DATA_LENGTH: u64 = ConsensusParameters::DEFAULT.max_script_data_length;
pub const MAX_STORAGE_SLOTS: u64 = ConsensusParameters::DEFAULT.max_storage_slots;
pub const MAX_PREDICATE_LENGTH: u64 = ConsensusParameters::DEFAULT.max_predicate_length;
pub const MAX_PREDICATE_DATA_LENGTH: u64 = ConsensusParameters::DEFAULT.max_predicate_data_length;
pub const GAS_PRICE_FACTOR: u64 = ConsensusParameters::DEFAULT.gas_price_factor;
pub const GAS_PER_BYTE: u64 = ConsensusParameters::DEFAULT.gas_per_byte;
pub const MAX_MESSAGE_DATA_LENGTH: u64 = ConsensusParameters::DEFAULT.max_message_data_length;
}