mirror of
https://github.com/codex-storage/codex-contracts-eth.git
synced 2025-02-19 22:58:25 +00:00
rename all occurrences of 'group' to 'bucket'
This commit is contained in:
parent
6ab4849ac9
commit
c2a17a3a28
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user