Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
0ad7f97 to
e9bc7f3
Compare
7f613a9 to
49ab911
Compare
49ab911 to
4321429
Compare
93afb33 to
1ecec4f
Compare
LHerskind
left a comment
There was a problem hiding this comment.
Think we can get rid of a bunch of the branching which should simplify a bunch of the tests. Also think we can get rid of the cheatcode for deposits (but would save that for a separate pr).
| onlyOwner | ||
| { | ||
| CheatLib.cheat__InitialiseValidatorSet(_args); | ||
| setupEpoch(); |
There was a problem hiding this comment.
This one was leftover from last? 👀
|
|
||
| // Set the sample seed for the next epoch if required | ||
| // function handles the case where it is already set | ||
| setSampleSeedForEpoch(_epochNumber + Epoch.wrap(1)); |
There was a problem hiding this comment.
It might be slightly nicer separation if this is moved upwards, e.g., then you have things altering seeds and then things using seeds. Since it should alter in the future don't seems like it should cause an issue.
| */ | ||
| function setupEpoch(StakingStorage storage _stakingStore) internal { | ||
| Epoch epochNumber = Timestamp.wrap(block.timestamp).epochFromTimestamp(); | ||
| function setupEpoch(StakingStorage storage _stakingStore, Epoch _epochNumber) internal { |
There was a problem hiding this comment.
Just a note for my sanity, we use the case where _epochNumber != currentEpoch when we mught wanna look at a historical and not setup epoch as the sampleValidators are using it.
| uint224 sampleSeed = getSampleSeed(_epochNumber); | ||
|
|
||
| // If no sample seed is set, we are in a genesis state, we set the sample seed to max and push it into the store | ||
| if (sampleSeed == 0) { |
There was a problem hiding this comment.
Should we just set it up at genesis instead? As part of the construction? I might be forgetting something, but would that not at least get rid of this special case in the function that we will continously call? 🤷
|
|
||
| // Emulate a sampling of the validators | ||
| uint256 sampleSeed = getSampleSeed(_epochNumber); | ||
| // Check if the latest checkpoint is for the next epoch |
There was a problem hiding this comment.
If we set the initial using the constructor as well it might simplify us slightly here as well as we won't have the case where the last checkpoint does not exists so one less branch to deal with.
| mapping(address => bool) internal _seenCommittee; | ||
|
|
||
| /** | ||
| * @notice Set up the contracts needed for the tests with time aligned to the provided block name |
There was a problem hiding this comment.
The comment seems copied over, not taking a name.
| testERC20.approve(address(rollup), TestConstants.AZTEC_MINIMUM_STAKE * _validatorCount); | ||
|
|
||
| if (_validatorCount > 0) { | ||
| rollup.cheat__InitialiseValidatorSet(initialValidators); |
There was a problem hiding this comment.
I think we could get rid of the cheat after this pr, but should be done fully separately, no need to grow this one as there is a bunch of node and test stuff that would change
| @@ -0,0 +1,19 @@ | |||
| SetupEpochTest | |||
| ├── when the rollup is in genesis state | |||
There was a problem hiding this comment.
Think we could get rid of a whole bunch of these by using the constructor to set some of these values 👀
| } | ||
|
|
||
| function testInitialCommitteeMatch() public setup(4) { | ||
| function testInitialCommitteeMatch() public setup(4) progressEpoch { |
There was a problem hiding this comment.
If we apply the progressEpoch to each one, whould it not make sense to apply it to the setup so there is one less thing to think about?
There was a problem hiding this comment.
Its also used in the setupEpoch test without progressEpoch applied. I know its a bit annoying in this file.
| function setupEpoch(StakingStorage storage _stakingStore, Epoch _epochNumber) internal { | ||
| ValidatorSelectionStorage storage store = getStorage(); | ||
|
|
||
| //################ Seeds ################ |
Following the seed snapshots pr #13577 there was a change that mean that `getCurrentProposer` can end up running the `setupEpoch` (reducing number of different flows etc). However, that meant that when we were running our benchmark test to get some gas numbers, we never end up including the gas spent to setup the epoch. To address, we are now explicitly calling `setupEpoch` such that we get some neat measurements for it, also making it clear when changes are made that impact the sampling. A nice side effect, is that it more simply allow us to do the proper amortized cost for sampling as the propose is for 360 tx, but sampling is for 11520 (32 * 360). This new setup makes it more simple to see the direct impact from the sampling on tx costs etc.

Overview
Snapshot the seeds across epochs.
How it currently works:
In cases where we are looking at the committee for a given block from the future, we may end up calculated a different committee, as we use the latest sample seed, which may have changed in the time since.
This PR builds ontop of validator snapshots ( where the validator set cannot change in size during an epoch ) to make sure that even when we are querying from the future, and the latest seed has changed, we do not end up with a different calculated committee.
How it should work:
Seeds are no longer stored for each epoch in EpochData, instead they are snapshotted.
fixes: #13559