From c2a17a3a28350b7b9b4e44bfa7d5ec7b91d47359 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:27:20 +1000 Subject: [PATCH] rename all occurrences of 'group' to 'bucket' --- contracts/Marketplace.sol | 20 ++++++++++---------- contracts/StateRetrieval.sol | 12 ++++++------ contracts/Validation.sol | 8 ++++---- test/Validation.test.js | 6 +++--- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index e406cd4..1b1d6ab 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -149,8 +149,8 @@ contract Marketplace is Proofs, Validation, StateRetrieval, Endian { slot.currentCollateral = collateralAmount; _addToMySlots(slot.host, slotId); - uint16 groupIdx = _getValidatorIndex(slotId); - _addToMyValidationSlots(groupIdx, slotId); + uint16 bucketIdx = _getValidatorIndex(slotId); + _addToMyValidationSlots(bucketIdx, slotId); emit SlotFilled(requestId, slotIndex); if (context.slotsFilled == request.ask.slots) { @@ -172,8 +172,8 @@ contract Marketplace is Proofs, Validation, StateRetrieval, Endian { _payoutCancelledSlot(slot.requestId, slotId); } else if (state == SlotState.Failed) { _removeFromMySlots(msg.sender, slotId); - uint16 groupIdx = _getValidatorIndex(slotId); - _removeFromMyValidationSlots(groupIdx, slotId); + uint16 bucketIdx = _getValidatorIndex(slotId); + _removeFromMyValidationSlots(bucketIdx, slotId); } else if (state == SlotState.Filled) { _forciblyFreeSlot(slotId); } @@ -241,8 +241,8 @@ contract Marketplace is Proofs, Validation, StateRetrieval, Endian { RequestContext storage context = _requestContexts[requestId]; _removeFromMySlots(slot.host, slotId); - uint16 groupIdx = _getValidatorIndex(slotId); - _removeFromMyValidationSlots(groupIdx, slotId); + uint16 bucketIdx = _getValidatorIndex(slotId); + _removeFromMyValidationSlots(bucketIdx, slotId); uint256 slotIndex = slot.slotIndex; delete _slots[slotId]; @@ -275,8 +275,8 @@ contract Marketplace is Proofs, Validation, StateRetrieval, Endian { Slot storage slot = _slots[slotId]; _removeFromMySlots(slot.host, slotId); - uint16 groupIdx = _getValidatorIndex(slotId); - _removeFromMyValidationSlots(groupIdx, slotId); + uint16 bucketIdx = _getValidatorIndex(slotId); + _removeFromMyValidationSlots(bucketIdx, slotId); uint256 amount = _requests[requestId].pricePerSlot() + slot.currentCollateral; @@ -291,8 +291,8 @@ contract Marketplace is Proofs, Validation, StateRetrieval, Endian { ) private requestIsKnown(requestId) { Slot storage slot = _slots[slotId]; _removeFromMySlots(slot.host, slotId); - uint16 groupIdx = _getValidatorIndex(slotId); - _removeFromMyValidationSlots(groupIdx, slotId); + uint16 bucketIdx = _getValidatorIndex(slotId); + _removeFromMyValidationSlots(bucketIdx, slotId); uint256 amount = _expiryPayoutAmount(requestId, slot.filledAt) + slot.currentCollateral; diff --git a/contracts/StateRetrieval.sol b/contracts/StateRetrieval.sol index cecb7c5..a0ea9ca 100644 --- a/contracts/StateRetrieval.sol +++ b/contracts/StateRetrieval.sol @@ -21,9 +21,9 @@ contract StateRetrieval { } function myValidationSlots( - uint16 groupIdx + uint16 bucketIdx ) public view returns (SlotId[] memory) { - return _slotsPerValidator[groupIdx].values().toSlotIds(); + return _slotsPerValidator[bucketIdx].values().toSlotIds(); } function _hasSlots(address host) internal view returns (bool) { @@ -38,8 +38,8 @@ contract StateRetrieval { _slotsPerHost[host].add(SlotId.unwrap(slotId)); } - function _addToMyValidationSlots(uint16 groupIdx, SlotId slotId) internal { - _slotsPerValidator[groupIdx].add(SlotId.unwrap(slotId)); + function _addToMyValidationSlots(uint16 bucketIdx, SlotId slotId) internal { + _slotsPerValidator[bucketIdx].add(SlotId.unwrap(slotId)); } function _removeFromMyRequests(address client, RequestId requestId) internal { @@ -51,9 +51,9 @@ contract StateRetrieval { } function _removeFromMyValidationSlots( - uint16 groupIdx, + uint16 bucketIdx, SlotId slotId ) internal { - _slotsPerValidator[groupIdx].remove(SlotId.unwrap(slotId)); + _slotsPerValidator[bucketIdx].remove(SlotId.unwrap(slotId)); } } diff --git a/contracts/Validation.sol b/contracts/Validation.sol index 7052651..ded9426 100644 --- a/contracts/Validation.sol +++ b/contracts/Validation.sol @@ -12,7 +12,7 @@ import "hardhat/console.sol"; */ abstract contract Validation { ValidationConfig private _config; - uint256 private _idsPerValidator; // number of uint256's in each group of the 2^256 bit space + uint256 private _idsPerValidator; // number of uint256's in each bucket of the 2^256 bit space /** * Creates a new Validation contract. @@ -27,7 +27,7 @@ abstract contract Validation { // To find the number of SlotIds per validator, we could do // 2^256/validators, except that would overflow. Instead, we use // floor(2^256-1 / validators) + 1. For example, if we used a 4-bit space - // (2^4=16) with 2 validators, we'd expect 8 per group: floor(2^4-1 / 2) + 1 + // (2^4=16) with 2 validators, we'd expect 8 per bucket: floor(2^4-1 / 2) + 1 // = 8 if (config.validators == 1) { // max(uint256) + 1 would overflow, so assign 0 and handle as special case @@ -41,9 +41,9 @@ abstract contract Validation { } /** - * Determines which validator group (0-based index) a SlotId belongs to, based + * Determines which validator bucket (0-based index) a SlotId belongs to, based on the number of total validators in the config. - * @param slotId SlotID for which to determine the validator group index. + * @param slotId SlotID for which to determine the validator bucket index. */ function _getValidatorIndex(SlotId slotId) internal view returns (uint16) { uint256 slotIdInt = uint256(SlotId.unwrap(slotId)); diff --git a/test/Validation.test.js b/test/Validation.test.js index 11ed203..bb5334b 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -46,19 +46,19 @@ describe("Validation", function () { it("tests SlotId bucket boundaries are assigned to the correct validator index", async function () { let validators = 2 ** 16 - 1 // max value of uint16 - let idsPerGroup = high.div(validators).add(1) // as in the contract + let idsPerBucket = high.div(validators).add(1) // as in the contract let validation = await Validation.deploy({ validators }) // Returns the minimum SlotId of all allowed SlotIds of the validator // (given its index) function minIdFor(validatorIdx) { - return BigNumber.from(validatorIdx).mul(idsPerGroup) + return BigNumber.from(validatorIdx).mul(idsPerBucket) } // Returns the maximum SlotId of all allowed SlotIds of the validator // (given its index) function maxIdFor(validatorIdx) { const max = BigNumber.from(validatorIdx + 1) - .mul(idsPerGroup) + .mul(idsPerBucket) .sub(1) // Never return more than max value of uint256 because it would // overflow. BigNumber.js lets us do MaxUint256+1 without overflows.