Skip to content

Commit

Permalink
mask function related to applying weak checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Oct 17, 2024
1 parent b7d92f1 commit d13ab38
Showing 1 changed file with 50 additions and 54 deletions.
104 changes: 50 additions & 54 deletions crates/zkwasm/src/runtime/monitor/plugins/table/transaction/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,21 @@ impl Checkpoints {
}
}

// Only finalized checkpoint can be applied
// release 'n' weak transactions after 'from''
fn force_commit_weak_n(&mut self, tx: TransactionId, from: usize, n: usize) {
let have_started_new =
self.passive_release_weak_dependencies_for_checkpoint_from(tx, from, n);
// fn force_commit_weak_n(&mut self, tx: TransactionId, from: usize, n: usize) {
// let have_started_new =
// self.passive_release_weak_dependencies_for_checkpoint_from(tx, from, n);

if !have_started_new {
let desc = self.weak_committed.get_mut(&tx).unwrap();
desc.count -= n;
// if !have_started_new {
// let desc = self.weak_committed.get_mut(&tx).unwrap();
// desc.count = desc.count.checked_sub(n).unwrap();

if desc.count == 0 {
self.weak_committed.remove(&tx);
}
}
}
// if desc.count == 0 {
// self.weak_committed.remove(&tx);
// }
// }
// }

fn insert_checkpoint(&mut self, offset: usize) {
let weak_dependencies = self
Expand All @@ -242,34 +243,35 @@ impl Checkpoints {
});
}

// Only finalized checkpoint can be applied
// return value indicates whether a new id transaction have started
fn passive_release_weak_dependencies_for_checkpoint_from(
&mut self,
tx: TransactionId,
from: usize,
n: usize,
) -> bool {
assert!(n > 0);

for checkpoint in &mut self.checkpoints[from..] {
let desc = checkpoint.weak_dependencies.get_mut(&tx);

match desc {
Some(count) if *count >= n => {
*count -= n;
}
// force committed
Some(count) => {
assert_eq!(*count, 0);
return true;
}
// force committed
None => return true,
}
}

false
}
// fn passive_release_weak_dependencies_for_checkpoint_from(
// &mut self,
// tx: TransactionId,
// from: usize,
// n: usize,
// ) -> bool {
// assert!(n > 0);

// for checkpoint in &mut self.checkpoints[from..] {
// let desc = checkpoint.weak_dependencies.get_mut(&tx);

// match desc {
// Some(count) if *count >= n => {
// *count -= n;
// }
// // already finalized
// Some(count) => {
// assert_eq!(*count, 0);
// return true;
// }
// // already finalized
// None => return true,
// }
// }

// false
// }

// return value indicates whether a new id transaction have started
fn active_release_weak_dependencies_for_checkpoint_from(
Expand All @@ -290,14 +292,16 @@ impl Checkpoints {
let checkpoint = self.checkpoints[index].clone();

if checkpoint.has_dependencies() {
warn!(
"Create a slice with weak transactions: {:?}, this may fail host circuits",
checkpoint.weak_dependencies
);
unreachable!("only firnalized checkpoint can be applied due to filter function");

for (tx, n) in &checkpoint.weak_dependencies {
self.force_commit_weak_n(*tx, index, *n);
}
// warn!(
// "Create a slice with weak transactions: {:?}, this may fail host circuits",
// checkpoint.weak_dependencies
// );

// for (tx, n) in &checkpoint.weak_dependencies {
// self.force_commit_weak_n(*tx, index, *n);
// }
}

for (tx, n) in checkpoint.transactions_group_number {
Expand Down Expand Up @@ -375,15 +379,7 @@ impl Checkpoints {
// prefer checkpoint without weak dependencies
let index = self.find(
upper_bound,
|checkpoint| {
let no_weak_committed = checkpoint.weak_dependencies.is_empty()
|| checkpoint
.weak_dependencies
.iter()
.all(|checkpoint| *checkpoint.1 == 0);

no_weak_committed
},
|checkpoint| !checkpoint.has_dependencies(),
flush_strategy_controller,
);

Expand Down

0 comments on commit d13ab38

Please sign in to comment.