Fix (?) intermittent error in create-data script #4166
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #4150, I saw @mmioana had experienced one of my most hated things while trying to run the
create-data
script: an intermittent errorso I went hunting and think I've arrived at a simple fix.
Currently, when the script is run:
So far, so good.
Individual users are then paid out from each domain by calling
userPayments
with the threewalletUsers
(which are the first three ganache accounts) and a random contributor address.Users are paid out a random amount between 1 and 3 tokens... unless we are considering the first 'ganache' address, which gets 50 tokens, a fixed amount.
So, how does this result in a (rare) error when running the script? When paying out from a domain, the random contributor selected can be the first ganache address (if the domain is not the first in the colony to be considered). In that case, we will pay out to the first ganache address twice, resuling in somewhere between 102 and 106 tokens trying to leave the domain - but there is a chance that the domain only received as low as 100 tokens, and will not have enough to pay out.
In that scenario, the transaction will fail with the overflow message seen in the original error - but to occur, the domain must have received a sufficiently low number of tokens (less than 1% chance) and the first ganache account must have been randomly selected as a contributor (haven't properly understood how this is generated, but must be less than 33%), explaining why it is so rare to occur, anecdotally.
To fix the issue, the 'constant' amount we pay out to the first ganache address has been reduced to 30 tokens, which means that the most we can pay out from a domain is 66 tokens, which is less than the smallest amount that can be given to a domain.
For anyone paying particularly close attention, the last non-error log in the screenshot was paying out address
0x27fF0C145E191C22C75cD123C679C3e1F58a4469
, which isganacheAccounts[2]
, notganacheAccounts[0]
. However, the log occurs in the script after the payout succeeds, and so the error will have occurred when paying out the next address, which you can see in the failed transaction blob is0xb77D57F4959eAfA0339424b83FcFaf9c15407461
, as would be the case in the situation I've described here.I've checked with Raul and this 50 tokens isn't a magic value anywhere, so shouldn't break anything. Obviously the issue with an intermittent error is that it's tough to be sure that it's fixed, especially one with such a low recurrence rate, but I hope that the above case is compelling.
If/when this is merged, if you see a similar error in the future, please let me know - I really detest intermittent errors, which make it incredibly hard to debug actual issues, and try to extinguish them with extreme prejudice!