-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
There was a problem hiding this 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 :)
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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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);
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I overlooked that.
44591e8
to
51f9665
Compare
if ( | ||
shouldBeRemoved(expiredAttestation) && | ||
isNotIncludedYetOn(attestationsToRemove, expiredAttestation) | ||
) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 if
s then.
There was a problem hiding this comment.
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 if
s
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
#fixes #2982