-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[FUN-1332] Allowlist optimisation #12588
Conversation
I see you updated files related to
|
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.
The general approach seems valid to me. Justs add some tests and I think we can give this another review.
42994fc
to
7a96c97
Compare
7a96c97
to
a234f13
Compare
5f1edc5
to
c2cbd78
Compare
fda542a
to
7170ee0
Compare
f440ada
to
d2d6bd1
Compare
d2d6bd1
to
476651c
Compare
idxEnd := idxStart + uint64(a.config.OnchainAllowlistBatchSize) | ||
if idxEnd >= count { | ||
idxEnd = count - 1 | ||
idxStart := uint64(i) - uint64(a.config.OnchainAllowlistBatchSize) |
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.
What if count is less than batch size?
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.
good catch, I was expecting uint to handle this if the subtraction was less than 0. TIL 🙇🏼
idxEnd = count - 1 | ||
idxStart := uint64(i) - uint64(a.config.OnchainAllowlistBatchSize) | ||
idxEnd := uint64(i) - 1 | ||
if idxEnd >= currentAllowedSenderCount { |
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.
Is this possible?
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.
no, its a leftover, thanks!
} | ||
|
||
if updatedAllowedSenderCount > currentAllowedSenderCount { | ||
lastBatchIdxStart := updatedAllowedSenderCount - (updatedAllowedSenderCount - currentAllowedSenderCount) |
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.
this is equal to currentAllowedSenderCount
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.
true! I placed it as I thought it, but indeed:
b - (b - a) = a
} | ||
|
||
// allowlistSize defines how big the mocked allowlist will be | ||
allowlistSize := 50 |
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.
Can you add a test case where this is smaller than batch size please?
e1246fe
to
528d283
Compare
Quality Gate passedIssues Measures |
* feat: update allowlist in batches giving priority to latest allowed addresses * fix: adjust iteration and add tests on updateAllowedSendersInBatches * fix: make a deep copy of the map to avoid race conditions * feat: extra step to fetch latest added addresses while batching * fix: check allowlist size is bigger than the batchsize * chore: remove leftover and add modify tests to be closer to a real scenario * chore: simplify lastBatchIdxStart * chore: remove newlines to pass sonarqube check
Description
this pr introduces an optimization for allowlist by updating it in batches giving priority to latest allowed addresses and adding an extra step on the batching process in which we check for the length of the allowlist and if it changed (new addresses were added) we fetch these before continuing the loop
What changed
We are adding an extra step that will fetch the latest addresses added IF the length of the allowlist was increased.
We were already fetching the allowlist from the contract in batches, but we were updating the node representation only when the full list was fetched. This represented a delay for users when a new address was added, which would grow proportional to the increase of the allowlist length.
In order to mitigate this, we are updating the nodes representation with every batch we fetch.
Because the nodes representation uses a
atomic.Pointer[map[common.Address]struct{}]
we only have aStore
method to replace completely the current list.So we what we are doing is:
a.allowlist.Load()
by doing this the user should be able to see the new added addresses faster than waiting until the full list is fetched.
miro diagram here
How is this tested
This is tested with white box unit tests that mock the onchain part and allows to validate the correct fetching order