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

feat: priority queue #394

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

feat: priority queue #394

wants to merge 1 commit into from

Conversation

madlabman
Copy link
Contributor

No description provided.

@madlabman madlabman added the WIP label Feb 3, 2025
@@ -62,10 +62,12 @@ contract CSModule is
////////////////////////
// State variables below
////////////////////////
/// @dev DEPRECATED. Moved to CSParametersRegistry
uint256 internal _keyRemovalCharge;
mapping(uint256 queuePriority => QueueLib.Queue queue) queueByPriority;
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to nullify it in the init_v2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary, but the point is valid.

return 40; // Default priority, should be greater than LEGACY_QUEUE_PRIOIRITY.
}

function isEligibleForPriorityQueue(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it can be a single parameter maxKeysPerOperatorInPriorityQueue which tells that it's not eligible if no value is set for the curve

@@ -85,6 +87,9 @@ contract CSModule is
uint64 private _depositableValidatorsCount;
uint64 private _nodeOperatorsCount;

// TODO: Place instead of publicRelease.
Copy link
Contributor

Choose a reason for hiding this comment

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

We plan to keep public release since it also limits the number of keys per-operator

uint256 curveId = accounting.getBondCurveId(nodeOperatorId);
NodeOperator storage no = _nodeOperators[nodeOperatorId];

if (PARAMETERS_REGISTRY.isEligibleForPriorityQueue(curveId) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use priority. Ne need for a separate flag here

@@ -85,6 +87,9 @@ contract CSModule is
uint64 private _depositableValidatorsCount;
uint64 private _nodeOperatorsCount;

// TODO: Place instead of publicRelease.
uint256[] internal _depositPriorities;
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be public to be able to fetch the resulting queue off-chain

NodeOperator storage no = _nodeOperators[nodeOperatorId];

if (PARAMETERS_REGISTRY.isEligibleForPriorityQueue(curveId) &&
PARAMETERS_REGISTRY.maxKeysPerOperatorInPriorityQueue() > no.totalAddedKeys) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition seems off. I think we need to have {queuePriority, maxKeysInPriotiryQueue} and place up to maxKeysInPriotiryQueue to the queue with queuePriority the rest to the normal queue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I didn't get it. Can you give an example?

Copy link
Contributor

Choose a reason for hiding this comment

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

NO has 100 keys waiting to be placed in the queue. This is a new NO and they had never uploaded keys before. queuePriority = 5, maxKeysInPriotiryQueue = 20. We need to place 20 keys to the queue with queuePriority = 5 and the rest to the default queue

Copy link
Contributor

Choose a reason for hiding this comment

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

The other example. NO already has 10 keys added and enqueued in the past and 30 more waiting to be enqueued. queuePriority = 5, maxKeysInPriotiryQueue = 20. We need to add 10 keys to the queue with queuePriority = 5 and the rest to the default queue

/// @dev Legacy queue (priority=10), that we will probably may be able to remove in the future.
QueueLib.Queue public legacyQueue;

uint256 private constant LEGACY_QUEUE_PRIOIRITY = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not make it zero and put the others on top? In the current approach, you effectively limit the number of priority queues. It might work only if we want to have de-prioritized queues, but do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like for big NOs with even less priority to enter?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. But I think we want to keep the default one with the lowest priority. Hence, the proposal is to make it's priority = 0 and sort priorities in the descending orger

src/CSModule.sol Show resolved Hide resolved
Comment on lines +1083 to +1095
for (uint256 p; p < _depositPriorities.length; ++p) {
QueueLib.Queue storage q = _getQueue(_depositPriorities[p]);
uint128 qLen = q.length();

if (index >= qLen) {
index -= qLen;
continue;
}

return q.at(index);
}

return Batch.wrap(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I did not get this method. I also suggest having a queuePriority as a param here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gets a view to a queue linearly. E.g. we have 2 queues [...]*50 + [...]*50, and we query index 69, which is mapped to the second queue's 19th element. We can achieve the same result off-chain, just with different sets of getters. This one is more unified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still hard to digest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants