mirror of
https://github.com/logos-storage/logos-storage-contracts-eth.git
synced 2026-01-07 07:43:08 +00:00
Related to nim-codex/457, nim-codex/458. To cover the entire SlotId (uint256) address space, each validator must validate a portion of the SlotId space. When a slot is filled, the SlotId will be put in to a bucket, based on the value of the SlotId and the number of buckets (validators) configured. Similar to `myRequests` and `mySlots`, a function called `validationSlots` can be used to retrieve the `SlotIds` being validated for a particular bucket (validator index). This facilitates loading actively filled slots in need of validation when a validator starts.
55 lines
1.8 KiB
Solidity
55 lines
1.8 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.23;
|
|
|
|
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
import "./Requests.sol";
|
|
|
|
contract StateRetrieval {
|
|
using EnumerableSet for EnumerableSet.Bytes32Set;
|
|
using Requests for bytes32[];
|
|
|
|
mapping(address => EnumerableSet.Bytes32Set) private _requestsPerClient;
|
|
mapping(address => EnumerableSet.Bytes32Set) private _slotsPerHost;
|
|
mapping(uint16 => EnumerableSet.Bytes32Set) private _slotsPerValidator;
|
|
|
|
function myRequests() public view returns (RequestId[] memory) {
|
|
return _requestsPerClient[msg.sender].values().toRequestIds();
|
|
}
|
|
|
|
function mySlots() public view returns (SlotId[] memory) {
|
|
return _slotsPerHost[msg.sender].values().toSlotIds();
|
|
}
|
|
|
|
function validationSlots(uint16 groupIdx) public view returns (SlotId[] memory) {
|
|
return _slotsPerValidator[groupIdx].values().toSlotIds();
|
|
}
|
|
|
|
function _hasSlots(address host) internal view returns (bool) {
|
|
return _slotsPerHost[host].length() > 0;
|
|
}
|
|
|
|
function _addToMyRequests(address client, RequestId requestId) internal {
|
|
_requestsPerClient[client].add(RequestId.unwrap(requestId));
|
|
}
|
|
|
|
function _addToMySlots(address host, SlotId slotId) internal {
|
|
_slotsPerHost[host].add(SlotId.unwrap(slotId));
|
|
}
|
|
|
|
function _addToValidationSlots(uint16 groupIdx, SlotId slotId) internal {
|
|
_slotsPerValidator[groupIdx].add(SlotId.unwrap(slotId));
|
|
}
|
|
|
|
function _removeFromMyRequests(address client, RequestId requestId) internal {
|
|
_requestsPerClient[client].remove(RequestId.unwrap(requestId));
|
|
}
|
|
|
|
function _removeFromMySlots(address host, SlotId slotId) internal {
|
|
_slotsPerHost[host].remove(SlotId.unwrap(slotId));
|
|
}
|
|
|
|
function _removeFromValidationSlots(uint16 groupIdx, SlotId slotId) internal {
|
|
_slotsPerValidator[groupIdx].remove(SlotId.unwrap(slotId));
|
|
}
|
|
}
|