pub struct L2PricingState<D> {
pub backing_storage: Storage<D>,
pub arbos_version: u64,
/* private fields */
}Expand description
L2 pricing state manages gas pricing for L2 execution.
Fields§
§backing_storage: Storage<D>§arbos_version: u64Implementations§
Source§impl<D: Database> L2PricingState<D>
impl<D: Database> L2PricingState<D>
Sourcepub fn gas_model_to_use(&self) -> Result<GasModel, ()>
pub fn gas_model_to_use(&self) -> Result<GasModel, ()>
Determine which gas model to use based on ArbOS version and stored constraints.
Sourcepub fn grow_backlog(
&self,
used_gas: u64,
used_multi_gas: MultiGas,
) -> Result<(), ()>
pub fn grow_backlog( &self, used_gas: u64, used_multi_gas: MultiGas, ) -> Result<(), ()>
Grow the gas backlog for the active pricing model.
Sourcepub fn shrink_backlog(
&self,
used_gas: u64,
used_multi_gas: MultiGas,
) -> Result<(), ()>
pub fn shrink_backlog( &self, used_gas: u64, used_multi_gas: MultiGas, ) -> Result<(), ()>
Shrink the gas backlog for the active pricing model.
Sourcepub fn update_pricing_model(
&self,
time_passed: u64,
arbos_version: u64,
) -> Result<(), ()>
pub fn update_pricing_model( &self, time_passed: u64, arbos_version: u64, ) -> Result<(), ()>
Update the pricing model for a new block.
Sourcepub fn calc_multi_gas_constraints_exponents(&self) -> Result<[u64; 8], ()>
pub fn calc_multi_gas_constraints_exponents(&self) -> Result<[u64; 8], ()>
Calculate exponent (in basis points) per resource kind across all constraints.
Aggregates weighted backlog contributions from each constraint into a per-resource-kind exponent array.
Uses signed saturation arithmetic with Bips (int64) computation: dividend = NaturalToBips(SaturatingCast]int64](SaturatingUMul(backlog, weight))) divisor = SaturatingCastToBips(SaturatingUMul(window, SaturatingUMul(target, maxWeight))) exp = dividend / divisor (signed int64 division)
Sourcepub fn calc_base_fee_from_exponent(
&self,
exponent_bips: u64,
) -> Result<U256, ()>
pub fn calc_base_fee_from_exponent( &self, exponent_bips: u64, ) -> Result<U256, ()>
Calculate base fee from an exponent in basis points. base_fee = min_base_fee * exp(exponent_bips / 10000)
Sourcepub fn get_multi_gas_base_fee_per_resource(&self) -> Result<[U256; 8], ()>
pub fn get_multi_gas_base_fee_per_resource(&self) -> Result<[U256; 8], ()>
Get multi-gas current-block base fee per resource kind.
L1Calldata kind is always forced to the global base fee, and any zero fee is replaced with the global base fee.
Sourcepub fn commit_multi_gas_fees(&self) -> Result<(), ()>
pub fn commit_multi_gas_fees(&self) -> Result<(), ()>
Rotate next-block multi-gas fees into current-block fees.
Called at block start before executing transactions.
Sourcepub fn backlog_update_cost(&self) -> Result<u64, ()>
pub fn backlog_update_cost(&self) -> Result<u64, ()>
Calculate the cost for a backlog update operation.
Version-gated cost accounting:
- v60+: static cost (StorageReadCost + StorageWriteCost)
- v51+: overhead for single-gas constraint traversal
- v50+: base overhead for GasModelToUse() read
- legacy: read + write for backlog
Sourcepub fn set_gas_constraints_from_legacy(&self) -> Result<(), ()>
pub fn set_gas_constraints_from_legacy(&self) -> Result<(), ()>
Set gas constraints from legacy parameters (for upgrades).
Sourcepub fn set_multi_gas_constraints_from_single_gas_constraints(
&self,
) -> Result<(), ()>
pub fn set_multi_gas_constraints_from_single_gas_constraints( &self, ) -> Result<(), ()>
Convert single-gas constraints to multi-gas constraints (for upgrades).
Iterates existing single-gas constraints, reads their target/window/backlog, and creates corresponding multi-gas constraints with equal weights across all resource dimensions.
Sourcepub fn multi_dimensional_price_for_refund(
&self,
gas_used: MultiGas,
) -> Result<U256, ()>
pub fn multi_dimensional_price_for_refund( &self, gas_used: MultiGas, ) -> Result<U256, ()>
Compute total cost for a multi-gas usage, for refund calculations.
Returns sum(gas_used[kind] * base_fee[kind]) across all resource kinds.
Source§impl<D: Database> L2PricingState<D>
impl<D: Database> L2PricingState<D>
pub fn open(sto: Storage<D>, arbos_version: u64) -> Self
pub fn initialize(sto: &Storage<D>)
pub fn base_fee_wei(&self) -> Result<U256, ()>
pub fn set_base_fee_wei(&self, val: U256) -> Result<(), ()>
pub fn min_base_fee_wei(&self) -> Result<U256, ()>
pub fn set_min_base_fee_wei(&self, val: U256) -> Result<(), ()>
pub fn speed_limit_per_second(&self) -> Result<u64, ()>
pub fn set_speed_limit_per_second(&self, limit: u64) -> Result<(), ()>
pub fn per_block_gas_limit(&self) -> Result<u64, ()>
pub fn set_max_per_block_gas_limit(&self, limit: u64) -> Result<(), ()>
pub fn per_tx_gas_limit(&self) -> Result<u64, ()>
pub fn set_max_per_tx_gas_limit(&self, limit: u64) -> Result<(), ()>
pub fn gas_backlog(&self) -> Result<u64, ()>
pub fn set_gas_backlog(&self, backlog: u64) -> Result<(), ()>
pub fn pricing_inertia(&self) -> Result<u64, ()>
pub fn set_pricing_inertia(&self, val: u64) -> Result<(), ()>
pub fn backlog_tolerance(&self) -> Result<u64, ()>
pub fn set_backlog_tolerance(&self, val: u64) -> Result<(), ()>
pub fn gas_constraints_length(&self) -> Result<u64, ()>
pub fn open_gas_constraint_at(&self, index: u64) -> GasConstraint<D>
pub fn add_gas_constraint( &self, target: u64, adjustment_window: u64, backlog: u64, ) -> Result<(), ()>
pub fn clear_gas_constraints(&self) -> Result<(), ()>
pub fn multi_gas_constraints_length(&self) -> Result<u64, ()>
pub fn open_multi_gas_constraint_at(&self, index: u64) -> MultiGasConstraint<D>
pub fn add_multi_gas_constraint( &self, target: u64, adjustment_window: u32, backlog: u64, weights: &[u64; 8], ) -> Result<(), ()>
pub fn clear_multi_gas_constraints(&self) -> Result<(), ()>
pub fn restrict(&self, _err: ())
Auto Trait Implementations§
impl<D> Freeze for L2PricingState<D>
impl<D> RefUnwindSafe for L2PricingState<D>where
D: RefUnwindSafe,
impl<D> Send for L2PricingState<D>where
D: Send,
impl<D> Sync for L2PricingState<D>where
D: Sync,
impl<D> Unpin for L2PricingState<D>
impl<D> UnwindSafe for L2PricingState<D>where
D: RefUnwindSafe,
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<TxEnv, T> FromRecoveredTx<&T> for TxEnvwhere
TxEnv: FromRecoveredTx<T>,
impl<TxEnv, T> FromRecoveredTx<&T> for TxEnvwhere
TxEnv: FromRecoveredTx<T>,
§fn from_recovered_tx(tx: &&T, sender: Address) -> TxEnv
fn from_recovered_tx(tx: &&T, sender: Address) -> TxEnv
TxEnv] from a transaction and a sender address.§impl<TxEnv, T> FromTxWithEncoded<&T> for TxEnvwhere
TxEnv: FromTxWithEncoded<T>,
impl<TxEnv, T> FromTxWithEncoded<&T> for TxEnvwhere
TxEnv: FromTxWithEncoded<T>,
§fn from_encoded_tx(tx: &&T, sender: Address, encoded: Bytes) -> TxEnv
fn from_encoded_tx(tx: &&T, sender: Address, encoded: Bytes) -> TxEnv
TxEnv] from a transaction, its sender, and encoded transaction bytes.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.