Skip to content

Commit

Permalink
Remove active_work field from ZKP malicious context
Browse files Browse the repository at this point in the history
We don't need it because active work is supplied by base context
  • Loading branch information
akoshelev committed Sep 27, 2024
1 parent bd13038 commit e8ad98f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
10 changes: 6 additions & 4 deletions ipa-core/src/protocol/context/dzkp_malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use crate::{
pub struct DZKPUpgraded<'a> {
validator_inner: Weak<MaliciousDZKPValidatorInner<'a>>,
base_ctx: MaliciousContext<'a>,
active_work: NonZeroUsize,
}

impl<'a> DZKPUpgraded<'a> {
Expand Down Expand Up @@ -59,8 +58,11 @@ impl<'a> DZKPUpgraded<'a> {
};
Self {
validator_inner: Arc::downgrade(validator_inner),
base_ctx,
active_work,
// This overrides the active work for this context and all children
// created from it by using narrow, clone, etc.
// This allows all steps participating in malicious validation
// to use the same active work window and prevent deadlocks
base_ctx: base_ctx.set_active_work(active_work),
}
}

Expand Down Expand Up @@ -152,7 +154,7 @@ impl<'a> super::Context for DZKPUpgraded<'a> {

impl<'a> SeqJoin for DZKPUpgraded<'a> {
fn active_work(&self) -> NonZeroUsize {
self.active_work
self.base_ctx.active_work()
}
}

Expand Down
7 changes: 7 additions & 0 deletions ipa-core/src/protocol/context/malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ impl<'a> Context<'a> {
..self.inner
}
}

#[must_use]
pub fn set_active_work(self, new_active_work: NonZeroUsize) -> Self {
Self {
inner: self.inner.set_active_work(new_active_work),
}
}
}

impl<'a> super::Context for Context<'a> {
Expand Down
26 changes: 8 additions & 18 deletions ipa-core/src/protocol/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,30 +177,20 @@ impl<'a, B: ShardBinding> Base<'a, B> {
total_records: TotalRecords,
sharding: B,
) -> Self {
Self::new_with_active_work(
participant,
gateway,
Self {
inner: Inner::new(participant, gateway),
gate,
total_records,
gateway.config().active_work(),
active_work: gateway.config().active_work(),
sharding,
)
}
}

fn new_with_active_work(
participant: &'a PrssEndpoint,
gateway: &'a Gateway,
gate: Gate,
total_records: TotalRecords,
active_work: NonZeroUsize,
sharding: B,
) -> Self {
#[must_use]
pub fn set_active_work(self, new_active_work: NonZeroUsize) -> Self {
Self {
inner: Inner::new(participant, gateway),
gate,
total_records,
active_work,
sharding,
active_work: new_active_work,
..self.clone()
}
}
}
Expand Down

0 comments on commit e8ad98f

Please sign in to comment.