Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid revocation overload #1706

Merged
merged 12 commits into from
Oct 19, 2023
Merged

fix: avoid revocation overload #1706

merged 12 commits into from
Oct 19, 2023

Conversation

kilted-andres
Copy link
Contributor

#fixes #2982

@kilted-andres kilted-andres requested a review from lukeg90 October 18, 2023 19:51
Copy link
Contributor

@arty-name arty-name left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think increasing the interval or decreasing the batch size would have any positive effect, but at least the critical change is in place :)

src/backend/revoker/expiredInventory.ts Outdated Show resolved Hide resolved
src/backend/revoker/expiredInventory.ts Outdated Show resolved Hide resolved
src/backend/revoker/expiredInventory.ts Show resolved Hide resolved
Comment on lines 28 to 46
for await (const expiredAttestation of getExpiredAttestations()) {
if (shouldBeRemoved(expiredAttestation)) {
// decides in which list to put and makes sure that is not included yet
if (
shouldBeRemoved(expiredAttestation) &&
isNotIncludedYetOn(attestationsToRemove, expiredAttestation)
) {
attestationsToRemove.push(expiredAttestation);
} else {
if (expiredAttestation.revoked === false) {
if (
expiredAttestation.revoked === false &&
isNotIncludedYetOn(attestationsToRevoke, expiredAttestation)
) {
attestationsToRevoke.push(expiredAttestation);
}
attestationsToRemoveLater.push(expiredAttestation);
if (isNotIncludedYetOn(attestationsToRemoveLater, expiredAttestation)) {
attestationsToRemoveLater.push(expiredAttestation);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of all the if/else statements. What do you think of this?

for await (const expiredAttestation of getExpiredAttestations()) {
    // decides in which list to put and makes sure that is not included yet
    const targetList = shouldBeRemoved(expiredAttestation)
      ? attestationsToRemove
      : expiredAttestation.revoked === false
      ? attestationsToRevoke
      : attestationsToRemoveLater;

    if (isNotIncludedYetOn(targetList, expiredAttestation)) {
      targetList.push(expiredAttestation);
    }
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some attestations need to be pushed in both attestationsToRemoveLater and attestationsToRevoke, so this approach won’t work. I think the code duplication could be reduced by creating a function addIfMissing() to do the conditional pushes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I overlooked that.

@kilted-andres kilted-andres force-pushed the xw--revocation-chiller branch from 44591e8 to 51f9665 Compare October 19, 2023 13:56
Comment on lines 28 to 31
if (
shouldBeRemoved(expiredAttestation) &&
isNotIncludedYetOn(attestationsToRemove, expiredAttestation)
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we combine two checks inside this if, some attestations that should be removed will instead be handled in the else branch, as if they were to revoke.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make similar mistakes occasionally, and I don’t know of a good way to avoid them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you are right. Nice catch! Thanks.

It needs nested ifs then.

Copy link
Contributor Author

@kilted-andres kilted-andres Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it like this:

isNotIncludedYetOn(attestationsToRemove, expiredAttestation) && attestationsToRemove.push(expiredAttestation);

inside of the ifs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code duplication could be reduced by creating a function addIfMissing() to do the conditional pushes.

What do you think of this suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done.

Yeah, ok. I'll do it.

@kilted-andres kilted-andres merged commit 30c56c6 into main Oct 19, 2023
1 check passed
@kilted-andres kilted-andres deleted the xw--revocation-chiller branch October 19, 2023 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants