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

Simplify data flow for epoch queues #2548

Merged

Conversation

sveitser
Copy link
Collaborator

@sveitser sveitser commented Feb 6, 2025

Note this PR is from reviewing #2316 and into that branch.

  • Some renames to make it easier to read.
  • Mutate the state of the queue in place relying on EVM reverts to restore the state of the contract when the transactions revert.

Would have to still update abstract contract and tests, so mainly pushing this for discussion. We would also have a new function for clients to determine available epochs, if that's actually required.

I think for clients it might be fine if we just return the max of the registrationEpoch variable in the contract and currentEpoch() + 1. If the registration epoch gets bumped by one by the time their transaction is included that's just a race condition we can't avoid anyway. They can set a reasonable validUntilEpoch to avoid having to wait too long.

- Some renames to make it easier to read.
- Mutate the state of the queue in place relying on EVM reverts to
  restore the state of the contract when the transactions revert.

Would have to still update abstract contract and tests, so mainly
pushing this for discussion. We would also have a new function for
clients to determine available epochs, if that's actually required.

I think for clients it might be fine if we just return the max of the
registrationEpoch variable in the contract and currentEpoch() + 1. If
the registration epoch gets bumped by one by the time their transaction
is included that's just a race condition we can't avoid anyway. They can
set a reasonable `validUntilEpoch` to avoid having to wait too long.
@sveitser sveitser force-pushed the ma/2316-stake-table-epochs-refactor branch from 85ca13a to 229b454 Compare February 6, 2025 09:56
if (exitEpoch < currentEpoch() + 1) {
// The exit epoch is outdated.
exitEpoch = currentEpoch() + 1;
numPendingExitsInEpoch = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably better to call this queueIndex to make it clearer that it goes from 0 to N - 1.

} else if (numPending >= maxChurnRate) {
epoch = firstAvailableEpoch + 1;
queueSize = 0;
function pushToRegistrationQueue() internal override returns (uint64, uint64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

previously i merged these into one function nextAvailableEpoch(...) since the logic being performed was the same - just different queues (register and exit). pros of that are: smaller contract size, reusability and consistency, cons: reduced readability which can lead to errors if the function usage isn't clear.

Which do you think is best?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In order for them to be general to work for both queues we can't directly operate on the state I think, so I prefer to have them separate.

alysiahuggins and others added 3 commits February 6, 2025 16:38
…ridden again if need be, update parent contract
- Fix solhint.
- Add a test for an epoch lenght greater than one.
- Remove unnecessary return values from functions that push to queue.
@sveitser sveitser marked this pull request as ready for review February 7, 2025 08:29
@sveitser sveitser merged commit 1724050 into 2316-stake-table-epochs Feb 7, 2025
22 checks passed
@sveitser sveitser deleted the ma/2316-stake-table-epochs-refactor branch February 7, 2025 08:30
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