Skip to content

Commit

Permalink
Add doc + default impl for ResourceTracker trait (#1576)
Browse files Browse the repository at this point in the history
* Add doc + default impl for ResourceTracker trait

* Add changelog entry

---------

Co-authored-by: Juan Bono <[email protected]>
  • Loading branch information
fmoletta and juanbono authored Jan 22, 2024
1 parent b910403 commit 3b5be72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: Add doc + default impl for ResourceTracker trait [#1576] (https://github.com/lambdaclass/cairo-vm/pull/1576)

* feat: Add `air_private_input` flag to `cairo1-run` [#1559] (https://github.com/lambdaclass/cairo-vm/pull/1559)

* feat: Add `args` flag to `cairo1-run` [#15551] (https://github.com/lambdaclass/cairo-vm/pull/15551)
Expand Down
26 changes: 19 additions & 7 deletions vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,26 @@ pub struct RunResources {
n_steps: Option<usize>,
}

/// This trait is in charge of overseeing the VM's step usage in contexts where a limited amount of steps are available
/// for a single execution (which may or not involve other executions taking place in the duration of it ).
/// This is mostly used in the context of starknet, where contracts can call other contracts while sharing the same step limit.
/// For the general use case, the default implementation can be used, which ignores resource tracking altogether
/// For an example on how to implement this trait for its intended purpose check out [BuiltinHintProcessor](cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor)
pub trait ResourceTracker {
fn consumed(&self) -> bool;

fn consume_step(&mut self);

fn get_n_steps(&self) -> Option<usize>;

fn run_resources(&self) -> &RunResources;
/// Returns true if there are no more steps left to run
fn consumed(&self) -> bool {
false
}
/// Subtracts 1 step from the available steps
fn consume_step(&mut self) {}
/// Returns the available steps for the run
fn get_n_steps(&self) -> Option<usize> {
None
}
/// Returns a reference to the available resources
fn run_resources(&self) -> &RunResources {
&RunResources { n_steps: None }
}
}

impl RunResources {
Expand Down

0 comments on commit 3b5be72

Please sign in to comment.