pub struct Budget(/* private fields */);
Implementations§
Source§impl Budget
impl Budget
pub fn reset_models(&self) -> Result<(), HostError>
pub fn get_wasm_mem_alloc(&self) -> Result<u64, HostError>
pub fn reset_unlimited(&self) -> Result<(), HostError>
pub fn reset_unlimited_cpu(&self) -> Result<(), HostError>
pub fn reset_unlimited_mem(&self) -> Result<(), HostError>
pub fn cpu_limit_exceeded(&self) -> Result<bool, HostError>
pub fn mem_limit_exceeded(&self) -> Result<bool, HostError>
pub fn reset_tracker(&self) -> Result<(), HostError>
pub fn reset(&self) -> Result<(), HostError>
pub fn reset_cpu_limit(&self, cpu: u64) -> Result<(), HostError>
pub fn reset_limits(&self, cpu: u64, mem: u64) -> Result<(), HostError>
Sourcepub fn reset_fuel_config(&self) -> Result<(), HostError>
pub fn reset_fuel_config(&self) -> Result<(), HostError>
Resets the FuelConfig
we pass into Wasmi before running calibration.
Wasmi instruction calibration requires running the same Wasmi insn
a fixed number of times, record their actual cpu and mem consumption, then
divide those numbers by the number of iterations, which is the fuel count.
Fuel count is kept tracked on the Wasmi side, based on the FuelConfig
of a specific fuel category. In order to get the correct, unscaled fuel
count, we have to preset all the FuelConfig
entries to 1.
pub fn get_shadow_cpu_insns_consumed(&self) -> Result<u64, HostError>
pub fn get_shadow_mem_bytes_consumed(&self) -> Result<u64, HostError>
pub fn shadow_cpu_limit_exceeded(&self) -> Result<bool, HostError>
pub fn shadow_mem_limit_exceeded(&self) -> Result<bool, HostError>
Source§impl Budget
impl Budget
Sourcepub fn try_from_configs(
cpu_limit: u64,
mem_limit: u64,
cpu_cost_params: ContractCostParams,
mem_cost_params: ContractCostParams,
) -> Result<Self, HostError>
pub fn try_from_configs( cpu_limit: u64, mem_limit: u64, cpu_cost_params: ContractCostParams, mem_cost_params: ContractCostParams, ) -> Result<Self, HostError>
Initializes the budget from network configuration settings.
Sourcepub fn bulk_charge(
&self,
ty: ContractCostType,
iterations: u64,
input: Option<u64>,
) -> Result<(), HostError>
pub fn bulk_charge( &self, ty: ContractCostType, iterations: u64, input: Option<u64>, ) -> Result<(), HostError>
Performs a bulk charge to the budget under the specified [CostType
].
The iterations
is the batch size. The caller needs to ensure:
- the batched charges have identical costs (having the same
[
CostType
] andinput
) - The input passed in (Some/None) is consistent with the [
CostModel
] underneath the [CostType
] (linear/constant).
Sourcepub fn charge(
&self,
ty: ContractCostType,
input: Option<u64>,
) -> Result<(), HostError>
pub fn charge( &self, ty: ContractCostType, input: Option<u64>, ) -> Result<(), HostError>
Charges the budget under the specified [CostType
]. The actual amount
charged is determined by the underlying [CostModel
] and may depend on
the input. If the input is None
, the model is assumed to be constant.
Otherwise it is a linear model. The caller needs to ensure the input
passed is consistent with the inherent model underneath.
pub fn get_tracker( &self, ty: ContractCostType, ) -> Result<CostTracker, HostError>
pub fn get_time(&self, ty: ContractCostType) -> Result<u64, HostError>
pub fn track_time( &self, ty: ContractCostType, duration: u64, ) -> Result<(), HostError>
pub fn get_cpu_insns_consumed(&self) -> Result<u64, HostError>
pub fn get_mem_bytes_consumed(&self) -> Result<u64, HostError>
pub fn get_cpu_insns_remaining(&self) -> Result<u64, HostError>
pub fn get_mem_bytes_remaining(&self) -> Result<u64, HostError>
pub fn reset_default(&self) -> Result<(), HostError>
Trait Implementations§
Source§impl Compare<ContractDataDurability> for Budget
impl Compare<ContractDataDurability> for Budget
Source§impl Compare<ContractExecutable> for Budget
impl Compare<ContractExecutable> for Budget
Source§impl Compare<CreateContractArgs> for Budget
impl Compare<CreateContractArgs> for Budget
Source§impl Compare<CreateContractArgsV2> for Budget
impl Compare<CreateContractArgsV2> for Budget
Source§impl Compare<Int128Parts> for Budget
impl Compare<Int128Parts> for Budget
Source§impl Compare<Int256Parts> for Budget
impl Compare<Int256Parts> for Budget
Source§impl Compare<LedgerKeyAccount> for Budget
impl Compare<LedgerKeyAccount> for Budget
Source§impl Compare<LedgerKeyContractCode> for Budget
impl Compare<LedgerKeyContractCode> for Budget
Source§impl Compare<LedgerKeyContractData> for Budget
impl Compare<LedgerKeyContractData> for Budget
Source§impl Compare<LedgerKeyTrustLine> for Budget
impl Compare<LedgerKeyTrustLine> for Budget
Source§impl<Elt: MeteredClone> Compare<MeteredVector<Elt>> for Budget
impl<Elt: MeteredClone> Compare<MeteredVector<Elt>> for Budget
Source§impl Compare<ScContractInstance> for Budget
impl Compare<ScContractInstance> for Budget
Source§impl Compare<ScMapEntry> for Budget
impl Compare<ScMapEntry> for Budget
Source§impl Compare<ScNonceKey> for Budget
impl Compare<ScNonceKey> for Budget
Source§impl Compare<TrustLineAsset> for Budget
impl Compare<TrustLineAsset> for Budget
Source§impl Compare<UInt128Parts> for Budget
impl Compare<UInt128Parts> for Budget
Source§impl Compare<UInt256Parts> for Budget
impl Compare<UInt256Parts> for Budget
Auto Trait Implementations§
impl Freeze for Budget
impl !RefUnwindSafe for Budget
impl !Send for Budget
impl !Sync for Budget
impl Unpin for Budget
impl !UnwindSafe for Budget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.