tempo_contracts/precompiles/
validator_config.rs

1use alloy::sol;
2
3pub use IValidatorConfig::IValidatorConfigErrors as ValidatorConfigError;
4
5sol! {
6    /// Validator config interface for managing consensus validators.
7    ///
8    /// This precompile manages the set of validators that participate in consensus.
9    /// Validators can update their own information, rotate their identity to a new address,
10    /// and the owner can manage validator status.
11    #[derive(Debug, PartialEq, Eq)]
12    #[sol(rpc, abi)]
13    interface IValidatorConfig {
14        /// Validator information
15        struct Validator {
16            bytes32 publicKey;
17            bool active;
18            uint64 index;
19            address validatorAddress;
20            /// Address where other validators can connect to this validator.
21            /// Format: `<hostname|ip>:<port>`
22            string inboundAddress;
23            /// IP address for firewall whitelisting by other validators.
24            /// Format: `<ip>:<port>` - must be an IP address, not a hostname.
25            string outboundAddress;
26        }
27
28        /// Get the complete set of validators
29        /// @return validators Array of all validators with their information
30        function getValidators() external view returns (Validator[] memory validators);
31
32        /// Add a new validator (owner only)
33        /// @param newValidatorAddress The address of the new validator
34        /// @param publicKey The validator's communication public publicKey
35        /// @param inboundAddress The validator's inbound address `<hostname|ip>:<port>` for incoming connections
36        /// @param outboundAddress The validator's outbound IP address `<ip>:<port>` for firewall whitelisting (IP only, no hostnames)
37        function addValidator(address newValidatorAddress, bytes32 publicKey, bool active, string calldata inboundAddress, string calldata outboundAddress) external;
38
39        /// Update validator information (only validator)
40        /// @param newValidatorAddress The new address for this validator
41        /// @param publicKey The validator's new communication public publicKey
42        /// @param inboundAddress The validator's inbound address `<hostname|ip>:<port>` for incoming connections
43        /// @param outboundAddress The validator's outbound IP address `<ip>:<port>` for firewall whitelisting (IP only, no hostnames)
44        function updateValidator(address newValidatorAddress, bytes32 publicKey, string calldata inboundAddress, string calldata outboundAddress) external;
45
46        /// Change validator active status (owner only)
47        /// @param validator The validator address
48        /// @param active Whether the validator should be active
49        function changeValidatorStatus(address validator, bool active) external;
50
51        /// Get the owner of the precompile
52        /// @return owner The owner address
53        function owner() external view returns (address);
54
55        /// Change owner
56        /// @param newOwner The new owner address
57        function changeOwner(address newOwner) external;
58
59        // Errors
60        error Unauthorized();
61        error ValidatorAlreadyExists();
62        error ValidatorNotFound();
63
64        error NotHostPort(string field, string input, string backtrace);
65        error NotIpPort(string field, string input, string backtrace);
66    }
67}
68
69impl ValidatorConfigError {
70    /// Creates an error for unauthorized access.
71    pub const fn unauthorized() -> Self {
72        Self::Unauthorized(IValidatorConfig::Unauthorized {})
73    }
74
75    /// Creates an error when validator already exists.
76    pub const fn validator_already_exists() -> Self {
77        Self::ValidatorAlreadyExists(IValidatorConfig::ValidatorAlreadyExists {})
78    }
79
80    /// Creates an error when validator is not found.
81    pub const fn validator_not_found() -> Self {
82        Self::ValidatorNotFound(IValidatorConfig::ValidatorNotFound {})
83    }
84
85    pub fn not_host_port(field: String, input: String, backtrace: String) -> Self {
86        Self::NotHostPort(IValidatorConfig::NotHostPort {
87            field,
88            input,
89            backtrace,
90        })
91    }
92
93    pub fn not_ip_port(field: String, input: String, backtrace: String) -> Self {
94        Self::NotIpPort(IValidatorConfig::NotIpPort {
95            field,
96            input,
97            backtrace,
98        })
99    }
100}