Skip to content

Commit

Permalink
Revert "do not block finality for spam disputes"
Browse files Browse the repository at this point in the history
This reverts commit f02add4.
  • Loading branch information
ordian committed Feb 16, 2024
1 parent f02add4 commit 6d3d3c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
8 changes: 2 additions & 6 deletions polkadot/node/core/dispute-coordinator/src/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,11 +1292,7 @@ impl Initialized {
session,
"New dispute initiated for candidate.",
);
if potential_spam {
DisputeStatus::potential_spam()
} else {
DisputeStatus::active()
}
DisputeStatus::active()
});

*status = *new_status;
Expand Down Expand Up @@ -1626,7 +1622,7 @@ fn determine_undisputed_chain(
let is_possibly_invalid = |session, candidate_hash| {
recent_disputes
.get(&(session, candidate_hash))
.map_or(false, |status| status.is_possibly_invalid() && !status.is_potential_spam())
.map_or(false, |status| status.is_possibly_invalid())
};

for (i, BlockDescription { session, candidates, .. }) in block_descriptions.iter().enumerate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl TestDisputes {
onchain_votes_count: usize,
) {
let concluded_at = match dispute.2 {
DisputeStatus::Active | DisputeStatus::Confirmed | DisputeStatus::PotentialSpam => None,
DisputeStatus::Active | DisputeStatus::Confirmed => None,
DisputeStatus::ConcludedAgainst(_) | DisputeStatus::ConcludedFor(_) => Some(1),
};
self.onchain_disputes.insert(
Expand Down
38 changes: 9 additions & 29 deletions polkadot/node/primitives/src/disputes/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ pub enum DisputeStatus {
/// we have seen the candidate included already/participated successfully ourselves).
#[codec(index = 3)]
Confirmed,
/// The dispute is not confirmed and potentially a spam.
#[codec(index = 4)]
PotentialSpam,
}

impl DisputeStatus {
Expand All @@ -58,43 +55,36 @@ impl DisputeStatus {
DisputeStatus::Active
}

/// Initialize the status to the potentially spam state.
pub fn potential_spam() -> DisputeStatus {
DisputeStatus::PotentialSpam
}

/// Move status to confirmed status, if not yet concluded/confirmed already.
pub fn confirm(self) -> DisputeStatus {
match self {
DisputeStatus::Active => DisputeStatus::Confirmed,
DisputeStatus::Confirmed => DisputeStatus::Confirmed,
DisputeStatus::PotentialSpam => DisputeStatus::Confirmed,
DisputeStatus::ConcludedFor(_) | DisputeStatus::ConcludedAgainst(_) => self,
}
}

/// Check whether the dispute has been confirmed or concluded.
/// Check whether the dispute is not a spam dispute.
pub fn is_confirmed_concluded(&self) -> bool {
match self {
DisputeStatus::Confirmed |
DisputeStatus::ConcludedFor(_) |
&DisputeStatus::Confirmed |
&DisputeStatus::ConcludedFor(_) |
DisputeStatus::ConcludedAgainst(_) => true,
DisputeStatus::Active => false,
DisputeStatus::PotentialSpam => false,
&DisputeStatus::Active => false,
}
}

/// Concluded valid?
pub fn has_concluded_for(&self) -> bool {
match self {
DisputeStatus::ConcludedFor(_) => true,
&DisputeStatus::ConcludedFor(_) => true,
_ => false,
}
}
/// Concluded invalid?
pub fn has_concluded_against(&self) -> bool {
match self {
DisputeStatus::ConcludedAgainst(_) => true,
&DisputeStatus::ConcludedAgainst(_) => true,
_ => false,
}
}
Expand All @@ -103,8 +93,7 @@ impl DisputeStatus {
/// candidate. This may be a no-op if the status was already concluded.
pub fn conclude_for(self, now: Timestamp) -> DisputeStatus {
match self {
DisputeStatus::Active | DisputeStatus::Confirmed | DisputeStatus::PotentialSpam =>
DisputeStatus::ConcludedFor(now),
DisputeStatus::Active | DisputeStatus::Confirmed => DisputeStatus::ConcludedFor(now),
DisputeStatus::ConcludedFor(at) => DisputeStatus::ConcludedFor(std::cmp::min(at, now)),
against => against,
}
Expand All @@ -114,7 +103,7 @@ impl DisputeStatus {
/// candidate. This may be a no-op if the status was already concluded.
pub fn conclude_against(self, now: Timestamp) -> DisputeStatus {
match self {
DisputeStatus::Active | DisputeStatus::Confirmed | DisputeStatus::PotentialSpam =>
DisputeStatus::Active | DisputeStatus::Confirmed =>
DisputeStatus::ConcludedAgainst(now),
DisputeStatus::ConcludedFor(at) =>
DisputeStatus::ConcludedAgainst(std::cmp::min(at, now)),
Expand All @@ -127,25 +116,16 @@ impl DisputeStatus {
pub fn is_possibly_invalid(&self) -> bool {
match self {
DisputeStatus::Active |
DisputeStatus::PotentialSpam |
DisputeStatus::Confirmed |
DisputeStatus::ConcludedAgainst(_) => true,
DisputeStatus::ConcludedFor(_) => false,
}
}

/// Whether the disputed candidate is potential spam.
pub fn is_potential_spam(&self) -> bool {
match self {
DisputeStatus::PotentialSpam => true,
_ => false,
}
}

/// Yields the timestamp this dispute concluded at, if any.
pub fn concluded_at(&self) -> Option<Timestamp> {
match self {
DisputeStatus::Active | DisputeStatus::Confirmed | DisputeStatus::PotentialSpam => None,
DisputeStatus::Active | DisputeStatus::Confirmed => None,
DisputeStatus::ConcludedFor(at) | DisputeStatus::ConcludedAgainst(at) => Some(*at),
}
}
Expand Down

0 comments on commit 6d3d3c2

Please sign in to comment.