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

Change how dynamic captcha stores data #2660

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

lmuntaner
Copy link
Collaborator

@lmuntaner lmuntaner commented Oct 18, 2024

Motivation

We realized that when the config changes, the stored data still takes into account the old config because it was stored by expiration date which took into account the config.

In this PR, the PR is stored with the create timestamp and pruned taking into account the config intervals.

There is a new test to check that the old config doesn't affect the new rates (given enough time to prune the old data).


🟡 Some screens were changed

@lmuntaner lmuntaner force-pushed the lm-change-dynamic-captcha-storage branch from 0fce48f to c9d1e5a Compare October 18, 2024 10:21
@lmuntaner lmuntaner marked this pull request as ready for review October 18, 2024 10:28
@lmuntaner lmuntaner requested a review from a team as a code owner October 18, 2024 10:28
@lmuntaner
Copy link
Collaborator Author

@frederikrothenberger please review

// calculate the time window length with respect to the current time
.map(|ts| now - ts)
// the value _could_ be 0 if the oldest timestamp was added in the same execution round
// -> filter to avoid division by 0
// There could be negative values if they haven't been pruned yet.
Copy link
Contributor

Choose a reason for hiding this comment

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

The values are u64 so the cannot be negative. But also ts is never bigger than now so the minimum value is 0, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, sorry, yes. I did some changes here and I didn't realize that it doesn't make sense this anymore.

registration_rates.registration_rates().unwrap(),
NormalizedRegistrationRates {
current_rate_per_second: 2.0,
reference_rate_per_second: 2.0, // increases too, but more slowly
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
reference_rate_per_second: 2.0, // increases too, but more slowly
reference_rate_per_second: 2.0, // equal to current rate because window lenght is the same

registration_rates.new_registration();
TIME.with_borrow_mut(|t| *t += Duration::from_secs(1).as_nanos() as u64);
}
assert_eq!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change it to assert equality between current_rate_per_second and reference_rate_per_second? Because that is the important property of the test, not the actual resulting values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point, done!

// Needed to prune the data after new config
// It prunes 100 for each new registration
// we added 1100 before. Remove them with 110, plus 2 to remove the new 110 added.
for _ in 0..112 {
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 confused by this. It only takes 11 registrations to prune 1100 entries if every entry prunes 100 elements.

But also, the whole block is not necessary as the subsequent setup of the new rates will more than prune all of the existing ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, yes, true. Removed.

@lmuntaner
Copy link
Collaborator Author

@frederikrothenberger ready for another review

@@ -112,8 +112,6 @@ fn calculate_registration_rate<M: Memory>(now: u64, data: &MinHeap<Timestamp, M>
.peek()
// calculate the time window length with respect to the current time
.map(|ts| now - ts)
// There could be negative values if they haven't been pruned yet.
.filter(|val| *val != 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

No,no you still need the 0 check. It's just the comment that was wrong. I.e. it should say filter out 0 rather than talk about negative values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops, yes. Good that there was a test for it

Copy link
Contributor

@frederikrothenberger frederikrothenberger left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM! 👍

@lmuntaner lmuntaner enabled auto-merge October 18, 2024 13:15
@lmuntaner lmuntaner force-pushed the lm-change-dynamic-captcha-storage branch from c8d4743 to 11b5552 Compare October 18, 2024 13:28
@lmuntaner lmuntaner added this pull request to the merge queue Oct 18, 2024
Merged via the queue into main with commit 974f972 Oct 18, 2024
66 checks passed
@lmuntaner lmuntaner deleted the lm-change-dynamic-captcha-storage branch October 18, 2024 13:41
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.

2 participants