Skip to content

Commit

Permalink
Refactor deposit assignments and add views for queue lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
kanewallmann committed Feb 10, 2025
1 parent f107ad3 commit 783ee13
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 150 deletions.
304 changes: 169 additions & 135 deletions contracts/contract/deposit/RocketDepositPool.sol

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contracts/contract/node/RocketNodeDeposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ contract RocketNodeDeposit is RocketBase, RocketNodeDepositInterface, RocketVaul
// Send node operator's bond to the deposit pool
RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(getContractAddress("rocketDepositPool"));
rocketDepositPool.nodeDeposit{value: _value}(_bondAmount);
// Attempt to assign 1 megapool
rocketDepositPool.maybeAssignOneDeposit();
// Attempt to assign 1 minipool/megapool
rocketDepositPool.maybeAssignDeposits(1);
}

/// @notice Called by minipools during bond reduction to increase the amount of ETH the node operator has
Expand Down
10 changes: 6 additions & 4 deletions contracts/interface/deposit/RocketDepositPoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ interface RocketDepositPoolInterface {
function recycleDissolvedDeposit() external payable;
function recycleExcessCollateral() external payable;
function recycleLiquidatedStake() external payable;
function assignDeposits() external;
function maybeAssignOneDeposit() external;
function maybeAssignDeposits() external returns (bool);
function maybeAssignDeposits(uint256 _max) external;
function assignDeposits(uint256 _max) external;
function withdrawExcessBalance(uint256 _amount) external;
function requestFunds(uint256 _bondAmount, uint32 _validatorId, uint256 _amount, bool _useExpressTicket) external;
function exitQueue(uint32 _validatorId, bool _expressQueue) external;
function withdrawCredit(uint256 _amount) external;
function getQueueTop() external view returns (address receiver, bool assignmentPossible, uint256 headMovedBlock);
function assignMegapools(uint256 _count) external;
function getQueueIndex() external view returns (uint256);
function getMinipoolQueueLength() external view returns (uint256);
function getExpressQueueLength() external view returns (uint256);
function getStandardQueueLength() external view returns (uint256);
function getTotalQueueLength() external view returns (uint256);
}
16 changes: 14 additions & 2 deletions test/_helpers/megapool.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ export async function nodeDeposit(node, bondAmount = '4'.ether, useExpressTicket
rocketMegapoolFactory.getMegapoolDeployed(node.address),
rocketNodeManager.getExpressTicketCount(node.address),
rocketMegapoolManager.getValidatorCount(),
rocketDepositPool.getExpressQueueLength(),
rocketDepositPool.getStandardQueueLength(),
]).then(
([ deployed, numExpressTickets, numGlobalValidators]) =>
({ deployed, numExpressTickets, numGlobalValidators, numValidators: 0n, assignedValue: 0n, nodeCapital: 0n, userCapital: 0n }),
([ deployed, numExpressTickets, numGlobalValidators, expressQueueLength, standardQueueLength]) =>
({ deployed, numExpressTickets, numGlobalValidators, expressQueueLength, standardQueueLength, numValidators: 0n, assignedValue: 0n, nodeCapital: 0n, userCapital: 0n }),
);

if (data.deployed) {
Expand Down Expand Up @@ -125,14 +127,24 @@ export async function nodeDeposit(node, bondAmount = '4'.ether, useExpressTicket
const assignedValueDelta = data2.assignedValue - data1.assignedValue;
const nodeCapitalDelta = data2.nodeCapital - data1.nodeCapital;
const userCapitalDelta = data2.userCapital - data1.userCapital;
const expressQueueLengthDelta = data2.expressQueueLength - data1.expressQueueLength;
const standardQueueLengthDelta = data2.standardQueueLength - data1.standardQueueLength;

assertBN.equal(numValidatorsDelta, 1n, "Number of validators did not increase by 1");
assertBN.equal(numGlobalValidatorsDelta, 1n, "Number of global validators did not increase by 1");

if (useExpressTicket) {
assertBN.equal(numExpressTicketsDelta, -1n, "Did not consume express ticket");
if (!expectAssignment) {
assertBN.equal(expressQueueLengthDelta, 1n, "Express queue did not grow by 1");
assertBN.equal(standardQueueLengthDelta, 0n, "Standard queue grew");
}
} else {
assertBN.equal(numExpressTicketsDelta, 0n, "Express ticket count incorrect");
if (!expectAssignment) {
assertBN.equal(expressQueueLengthDelta, 0n, "Express queue grew");
assertBN.equal(standardQueueLengthDelta, 1n, "Standard queue did not grow by 1");
}
}

// Confirm state of new validator
Expand Down
6 changes: 3 additions & 3 deletions test/deposit/deposit-pool-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default function() {

it(printTitle('random address', 'can assign deposits'), async () => {
// Assign deposits with no assignable deposits
await assignDeposits({
await assignDeposits(1n, {
from: staker,
});
// Disable deposit assignment
Expand All @@ -150,7 +150,7 @@ export default function() {
await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsDeposit, 'deposit.assign.maximum', 3, { from: owner });
await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsDeposit, 'deposit.assign.socialised.maximum', 3, { from: owner });
// Assign deposits with assignable deposits
await assignDeposits({
await assignDeposits(1n, {
from: staker,
});
});
Expand All @@ -160,7 +160,7 @@ export default function() {
await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsDeposit, 'deposit.assign.enabled', false, { from: owner });

// Attempt to assign deposits
await shouldRevert(assignDeposits({
await shouldRevert(assignDeposits(1n, {
from: staker,
}), 'Assigned deposits while deposit assignment is disabled');
});
Expand Down
16 changes: 13 additions & 3 deletions test/deposit/scenario-assign-deposits.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { RocketDepositPool } from '../_utils/artifacts';
import { assertBN } from '../_helpers/bn';

// Assign deposits to minipools
export async function assignDeposits(txOptions) {
export async function assignDeposits(max = 1n, txOptions) {
const [
rocketDepositPool,
] = await Promise.all([
RocketDepositPool.deployed(),
]);

await rocketDepositPool.connect(txOptions.from).assignDeposits();
const queueLengthBefore = await rocketDepositPool.getTotalQueueLength();

// TODO: Check pre and post conditions on assigning deposits
await rocketDepositPool.connect(txOptions.from).assignDeposits(max);

const queueLengthAfter = await rocketDepositPool.getTotalQueueLength();

if (queueLengthBefore <= max) {
assertBN.equal(queueLengthAfter, 0n);
} else {
const queueLengthDelta = queueLengthAfter - queueLengthBefore;
assertBN.equal(queueLengthDelta, -max);
}
}
2 changes: 1 addition & 1 deletion test/megapool/megapool-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export default function() {
const topAfter = await rocketDepositPool.getQueueTop();
assert.equal(topAfter[1], true);
// Assign the validator from random user
await rocketDepositPool.connect(random).assignMegapools(1);
await rocketDepositPool.connect(random).assignDeposits(1);
// Check the validator is now assigned
const validatorInfoAfter = await megapool.getValidatorInfo(0);
assert.equal(validatorInfoAfter.inQueue, false);
Expand Down

0 comments on commit 783ee13

Please sign in to comment.