-
Notifications
You must be signed in to change notification settings - Fork 2
Fix: random() reverts once every 3 blocks #458
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
Conversation
Deploying happychain with
|
| Latest commit: |
4ffb47a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8f0f84df.happychain.pages.dev |
| Branch Preview URL: | https://gabriel-delay-post-drand.happychain.pages.dev |
52ba575 to
caa054f
Compare
4803de4 to
7906e19
Compare
7906e19 to
ac39d24
Compare
b6ad880 to
0d63755
Compare
apps/randomness/src/DrandService.ts
Outdated
| } | ||
| const maxRetries = 10 | ||
| const retryIntervalMs = 100 | ||
| let retryCount = 0 |
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.
Do we really need to retry? Since handleNewDrandBeacons is called every 3s, and the timeout is 2s, this will be called the next time, right? At most it could make sense to retry once with a lower timeout of 1s.
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.
Yes, I think you are right; retrying is not necessary since it will be retried in a few seconds. However, the timeout has to be 2000ms because sometimes when we request a drand, if we request it too early, the query gets delayed by around 1600ms. If we limit the timeout to 1 second, it will fail. That was the reason we were failing to obtain the drand on time in some blocks
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 also modified the fetch so that it doesn't stop an already fired fetch and has an absolute timeout. I think this is exactly what we want because, otherwise, for example, we were making two attempts with a 2000-millisecond timeout, meaning we could wait up to 4 seconds. But what happens if the request arrives after 2100 milliseconds? I think it's better to establish a short timeout period to trigger another fetch without canceling the previous one. So now, we retry after one second, but if the previous fetch completes after 1500 milliseconds, we handle it correctly as well
0d63755 to
50f228b
Compare
norswap
left a comment
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.
Nice, this is very neat!

Description
This PR aims to solve the issue that Aodhgan found in the randomness service, where every 3 blocks, for one of them, the random() function reverts. This occurs in the testnet but not locally, making it quite difficult to determine what is happening.
The error occurs because the drand value is not found. This happens every 3 blocks because, in every 3-block cycle, one of them has a lower margin of error. Specifically, the time we have to include the drand value is only about 2.3 seconds from its generation, whereas for the other drands, it is 3.3 and 4.3 seconds, respectively. This makes the 2.3-second case the most problematic.
2.3 seconds should be more than enough time to include the drand value. However, I have detected that when a drand value is requested immediately after being emitted, the drand network can take up to 1.6 seconds to return it. This would cause us to exceed the time limit, given that the current timeout is set to 1 second. For this reason, I have increased the timeout to 2 seconds.
Toggle Checklist
Checklist
Basics
norswap/build-system-caching).Reminder: PR review guidelines
Correctness
testnet, mainnet, standalone wallet, ...).
< INDICATE BROWSER, DEMO APP & OTHER ENV DETAILS USED FOR TESTING HERE >
< INDICATE TESTED SCENARIOS (USER INTERFACE INTERACTION, CODE FLOWS) HERE >
and have updated the code & comments accordingly.
Architecture & Documentation
(2) commenting these boundaries correctly, (3) adding inline comments for context when needed.
comments.
in a Markdown document.
pacakges/coreandpackages/react), see here for more info.