Skip to content

Commit f4ad4e3

Browse files
author
Keyne
authored
feat: add IRegistrar and IValidatorManager interfaces (#5)
1 parent 430ff78 commit f4ad4e3

2 files changed

Lines changed: 157 additions & 0 deletions

File tree

src/interfaces/IRegistrar.sol

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity >=0.8.0 <0.9.0;
3+
4+
/// @title IRegistrar
5+
/// @notice Interface for the Registrar contract.
6+
interface IRegistrar {
7+
// =========================================================================
8+
// Types
9+
// =========================================================================
10+
11+
/// @notice Storage struct for key-value entries.
12+
struct Entry {
13+
bytes32 value;
14+
uint64 epochFrom; // 0 = genesis value
15+
}
16+
17+
// =========================================================================
18+
// Events
19+
// =========================================================================
20+
21+
/// @notice Emitted when a key-value pair is updated.
22+
/// @param key The key that was updated.
23+
/// @param value The new value associated with the key.
24+
/// @param epochFrom The epoch from which the new value is active.
25+
event Updated(bytes32 indexed key, bytes32 value, uint64 epochFrom);
26+
27+
// =========================================================================
28+
// Errors
29+
// =========================================================================
30+
31+
/// @notice Error when keys and values arrays have different lengths.
32+
error LengthMismatch();
33+
34+
// =========================================================================
35+
// Functions
36+
// =========================================================================
37+
38+
/// @notice Gets the value associated with a key at the current epoch.
39+
/// @param key The key to look up.
40+
/// @return value The value associated with the key.
41+
function get(bytes32 key) external view returns (bytes32 value);
42+
43+
/// @notice Gets the value associated with a key at the next epoch.
44+
/// @param key The key to look up.
45+
/// @return value The value associated with the key.
46+
function getNext(bytes32 key) external view returns (bytes32 value);
47+
48+
/// @notice Batch gets the values associated with keys at the current epoch.
49+
/// @param keys The keys to look up.
50+
/// @return values The values associated with the keys.
51+
function batchGet(bytes32[] calldata keys) external view returns (bytes32[] memory values);
52+
53+
/// @notice Batch gets the values associated with keys at the next epoch.
54+
/// @param keys The keys to look up.
55+
/// @return values The values associated with the keys.
56+
function batchGetNext(bytes32[] calldata keys) external view returns (bytes32[] memory values);
57+
58+
/// @notice Gets all historical entries for a key.
59+
/// @param key The key to look up.
60+
/// @return entries The entries associated with the key.
61+
function getEntries(bytes32 key) external view returns (Entry[] memory entries);
62+
63+
/// @notice Sets a key-value pair, applied from the next epoch.
64+
/// @param key The key to set.
65+
/// @param value The value to set.
66+
function set(bytes32 key, bytes32 value) external;
67+
68+
/// @notice Batch sets key-value pairs, applied from the next epoch.
69+
/// @param keys The keys to set.
70+
/// @param values The values to set.
71+
function batchSet(bytes32[] calldata keys, bytes32[] calldata values) external;
72+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity >=0.8.0 <0.9.0;
3+
4+
/// @title IValidatorManager
5+
/// @notice Interface for the Validator Manager contract.
6+
interface IValidatorManager {
7+
// =========================================================================
8+
// Types
9+
// =========================================================================
10+
11+
/// @notice Storage struct for validators.
12+
struct Validator {
13+
uint64 index;
14+
uint64 epochAdded; // 0 = genesis validator
15+
uint64 epochRemoved; // 0 = active validator
16+
uint32 ip;
17+
uint16 port;
18+
bytes32 publicKey;
19+
bytes32 name;
20+
}
21+
22+
/// @notice Return struct for view functions.
23+
struct ValidatorInfo {
24+
uint64 index;
25+
bytes32 publicKey;
26+
string name;
27+
string socketAddress;
28+
}
29+
30+
/// @notice Input struct for genesis validators.
31+
struct GenesisValidator {
32+
bytes32 publicKey;
33+
bytes32 name;
34+
uint32 ip;
35+
uint16 port;
36+
}
37+
38+
// =========================================================================
39+
// Events
40+
// =========================================================================
41+
42+
/// @notice Emitted when a validator is added.
43+
event ValidatorAdded(uint64 indexed index, bytes32 indexed publicKey, string name, uint64 epochAdded);
44+
45+
/// @notice Emitted when a validator is removed.
46+
event ValidatorRemoved(uint64 indexed index, bytes32 indexed publicKey, string name, uint64 epochRemoved);
47+
48+
// =========================================================================
49+
// Errors
50+
// =========================================================================
51+
52+
/// @notice Error when a validator is already added.
53+
error ValidatorAlreadyAdded(bytes32 publicKey);
54+
55+
/// @notice Error when a validator is already removed.
56+
error ValidatorAlreadyRemoved(bytes32 publicKey);
57+
58+
/// @notice Error when a validator does not exist.
59+
error ValidatorNotFound(bytes32 publicKey);
60+
61+
// =========================================================================
62+
// Functions
63+
// =========================================================================
64+
65+
/// @notice Adds a new validator to the set, applied from the next epoch.
66+
/// @param publicKey The validator's public key.
67+
/// @param name The validator's name.
68+
/// @param ip The validator's IPv4 address.
69+
/// @param port The validator's port.
70+
function addValidator(bytes32 publicKey, bytes32 name, uint32 ip, uint16 port) external;
71+
72+
/// @notice Removes a validator from the set, applied from the next epoch.
73+
/// @param publicKey The validator's public key.
74+
function removeValidator(bytes32 publicKey) external;
75+
76+
/// @notice Returns validators active in the current epoch.
77+
function getCurrentValidators() external view returns (ValidatorInfo[] memory);
78+
79+
/// @notice Returns validators that will be active in the next epoch.
80+
function getNextValidators() external view returns (ValidatorInfo[] memory);
81+
82+
/// @notice Returns validators active at a specific epoch.
83+
/// @param epoch The epoch number.
84+
function getValidatorsAtEpoch(uint64 epoch) external view returns (ValidatorInfo[] memory);
85+
}

0 commit comments

Comments
 (0)