Skip to content

Commit

Permalink
add k for flush strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Aug 13, 2024
1 parent cfbc626 commit f3f301c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl SetupArg {
let env = env_builder.create_env_without_value(self.k);
let mut monitor = TableMonitor::new(
self.k,
env_builder.create_flush_strategy(),
env_builder.create_flush_strategy(self.k),
&self.phantom_functions,
TraceBackend::Memory,
&env,
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Config {

let mut monitor = TableMonitor::new(
self.k,
env_builder.create_flush_strategy(),
env_builder.create_flush_strategy(self.k),
&self.phantom_functions,
table_backend,
&env,
Expand Down
9 changes: 7 additions & 2 deletions crates/host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ impl Default for StandardHostEnvBuilder {

#[derive(Default)]
struct StandardHostEnvFlushStrategy {
k: u32,
ops: HashMap<usize, usize>,
}

impl FlushStrategy for StandardHostEnvFlushStrategy {
#[allow(unreachable_code)]
fn notify(&mut self, op: Event) -> Command {
let _k = self.k;
match op {
Event::HostCall(op) => {
let count = self.ops.entry(op).or_insert(0);
Expand Down Expand Up @@ -140,7 +142,10 @@ impl HostEnvBuilder for StandardHostEnvBuilder {
env
}

fn create_flush_strategy(&self) -> Box<dyn FlushStrategy> {
Box::<StandardHostEnvFlushStrategy>::default()
fn create_flush_strategy(&self, k: u32) -> Box<dyn FlushStrategy> {
Box::new(StandardHostEnvFlushStrategy {
k,
ops: HashMap::new(),
})
}
}
2 changes: 1 addition & 1 deletion crates/zkwasm/src/runtime/host/default_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl HostEnvBuilder for DefaultHostEnvBuilder {
env
}

fn create_flush_strategy(&self) -> Box<dyn FlushStrategy> {
fn create_flush_strategy(&self, _k: u32) -> Box<dyn FlushStrategy> {
Box::new(DefaultFlushStrategy)
}
}
2 changes: 1 addition & 1 deletion crates/zkwasm/src/runtime/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ pub trait HostEnvBuilder {
/// Create an env with execution parameters, this is used by dry-run, run
fn create_env(&self, k: u32, env: ExecutionArg) -> HostEnv;
// Create a flush strategy to hint the monitor when to flush the table
fn create_flush_strategy(&self) -> Box<dyn FlushStrategy>;
fn create_flush_strategy(&self, k:u32) -> Box<dyn FlushStrategy>;
}

0 comments on commit f3f301c

Please sign in to comment.