pub trait BudgetStore: Send {
Show 24 methods
// Required methods
fn try_increment(
&mut self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
) -> Result<bool, BudgetStoreError>;
fn try_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
) -> Result<bool, BudgetStoreError>;
fn reverse_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>;
fn reduce_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>;
fn settle_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
) -> Result<(), BudgetStoreError>;
fn list_usages(
&self,
limit: usize,
capability_id: Option<&str>,
) -> Result<Vec<BudgetUsageRecord>, BudgetStoreError>;
fn get_usage(
&self,
capability_id: &str,
grant_index: usize,
) -> Result<Option<BudgetUsageRecord>, BudgetStoreError>;
// Provided methods
fn try_charge_cost_with_ids(
&mut self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<bool, BudgetStoreError> { ... }
fn try_charge_cost_with_ids_and_authority(
&mut self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<bool, BudgetStoreError> { ... }
fn reverse_charge_cost_with_ids(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<(), BudgetStoreError> { ... }
fn reverse_charge_cost_with_ids_and_authority(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<(), BudgetStoreError> { ... }
fn reduce_charge_cost_with_ids(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<(), BudgetStoreError> { ... }
fn reduce_charge_cost_with_ids_and_authority(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<(), BudgetStoreError> { ... }
fn settle_charge_cost_with_ids(
&mut self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<(), BudgetStoreError> { ... }
fn settle_charge_cost_with_ids_and_authority(
&mut self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<(), BudgetStoreError> { ... }
fn list_mutation_events(
&self,
_limit: usize,
_capability_id: Option<&str>,
_grant_index: Option<usize>,
) -> Result<Vec<BudgetMutationRecord>, BudgetStoreError> { ... }
fn budget_guarantee_level(&self) -> BudgetGuaranteeLevel { ... }
fn budget_authority_profile(&self) -> BudgetAuthorityProfile { ... }
fn budget_metering_profile(&self) -> BudgetMeteringProfile { ... }
fn authorize_budget_hold(
&mut self,
request: BudgetAuthorizeHoldRequest,
) -> Result<BudgetAuthorizeHoldDecision, BudgetStoreError> { ... }
fn reverse_budget_hold(
&mut self,
request: BudgetReverseHoldRequest,
) -> Result<BudgetReverseHoldDecision, BudgetStoreError> { ... }
fn release_budget_hold(
&mut self,
request: BudgetReleaseHoldRequest,
) -> Result<BudgetReleaseHoldDecision, BudgetStoreError> { ... }
fn reconcile_budget_hold(
&mut self,
request: BudgetReconcileHoldRequest,
) -> Result<BudgetReconcileHoldDecision, BudgetStoreError> { ... }
fn capture_budget_hold(
&mut self,
request: BudgetCaptureHoldRequest,
) -> Result<BudgetCaptureHoldDecision, BudgetStoreError> { ... }
}Required Methods§
fn try_increment( &mut self, capability_id: &str, grant_index: usize, max_invocations: Option<u32>, ) -> Result<bool, BudgetStoreError>
Sourcefn try_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
) -> Result<bool, BudgetStoreError>
fn try_charge_cost( &mut self, capability_id: &str, grant_index: usize, max_invocations: Option<u32>, cost_units: u64, max_cost_per_invocation: Option<u64>, max_total_cost_units: Option<u64>, ) -> Result<bool, BudgetStoreError>
Atomically check monetary budget limits and record provisional exposure if within bounds.
Checks:
invocation_count < max_invocations(if set)cost_units <= max_cost_per_invocation(if set)(total_cost_exposed + total_cost_realized_spend + cost_units) <= max_total_cost_units(if set)
On pass: increments invocation_count by 1 and total_cost_exposed by
cost_units, allocates a new replication seq, returns Ok(true).
On any limit exceeded: rolls back, returns Ok(false).
Sourcefn reverse_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>
fn reverse_charge_cost( &mut self, capability_id: &str, grant_index: usize, cost_units: u64, ) -> Result<(), BudgetStoreError>
Reverse a previously applied provisional exposure for a pre-execution denial path.
Sourcefn reduce_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>
fn reduce_charge_cost( &mut self, capability_id: &str, grant_index: usize, cost_units: u64, ) -> Result<(), BudgetStoreError>
Release a previously exposed monetary amount without changing invocation count.
This is used when the kernel needs to release provisional exposure without realizing any spend in the budget store itself.
Sourcefn settle_charge_cost(
&mut self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
) -> Result<(), BudgetStoreError>
fn settle_charge_cost( &mut self, capability_id: &str, grant_index: usize, exposed_cost_units: u64, realized_cost_units: u64, ) -> Result<(), BudgetStoreError>
Atomically release provisional exposure and record realized spend.
This removes exposed_cost_units from total_cost_exposed and adds
realized_cost_units to total_cost_realized_spend without changing
invocation count. realized_cost_units must not exceed
exposed_cost_units.