Skip to content

Commit

Permalink
EVM/Add setter and tests for per-chain thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley committed Sep 16, 2024
1 parent 3ddcb5d commit 964a4de
Show file tree
Hide file tree
Showing 3 changed files with 619 additions and 1 deletion.
20 changes: 19 additions & 1 deletion evm/src/NttManager/ManagerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,21 @@ abstract contract ManagerBase is

emit ThresholdChanged(oldThreshold, threshold);
}

/// @inheritdoc IManagerBase
function setThresholdPerChain(uint16 forChainId, uint8 threshold) external onlyOwner {
if (threshold == 0) {
revert ZeroThreshold();
}

mapping(uint16 => _Threshold) storage _threshold = _getThresholdStoragePerChain();
uint8 oldThreshold = _threshold[forChainId].num;

_threshold[forChainId].num = threshold;
_checkThresholdInvariants(_threshold[forChainId].num);

emit PerChainThresholdChanged(forChainId, oldThreshold, threshold);
}

// =============== Internal ==============================================================

Expand Down Expand Up @@ -515,7 +530,10 @@ abstract contract ManagerBase is
}

function _checkThresholdInvariants() internal view {
uint8 threshold = _getThresholdStorage().num;
_checkThresholdInvariants(_getThresholdStorage().num);
}

function _checkThresholdInvariants(uint8 threshold) internal pure {
_NumTransceivers memory numTransceivers = _getNumTransceiversStorage();

// invariant: threshold <= enabledTransceivers.length
Expand Down
18 changes: 18 additions & 0 deletions evm/src/interfaces/IManagerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ interface IManagerBase {
/// @param oldThreshold The old threshold.
/// @param threshold The new threshold.
event ThresholdChanged(uint8 oldThreshold, uint8 threshold);

/// @notice Emmitted when the per-chain threshold required transceivers is changed.
/// @dev Topic0
/// 0x2a855b929b9a53c6fb5b5ed248b27e502b709c088e036a5aa17620c8fc5085a9.
/// @param chainId The chain to which the threshold applies
/// @param oldThreshold The old threshold.
/// @param threshold The new threshold.
event PerChainThresholdChanged(uint16 chainId, uint8 oldThreshold, uint8 threshold);

/// @notice Emitted when an transceiver is removed from the nttManager.
/// @dev Topic0
Expand Down Expand Up @@ -128,6 +136,16 @@ interface IManagerBase {
function setThreshold(
uint8 threshold
) external;

/// @notice Sets the per-chain threshold for the number of attestations required for a message
/// to be considered valid. Note that if a threshold is not specified for a chain, the default applies.
/// @param chainId The chain for which the threshold applies
/// @param threshold The new threshold.
/// @dev This method can only be executed by the `owner`.
function setThresholdPerChain(
uint16 chainId,
uint8 threshold
) external;

/// @notice Sets the transceiver for the given chain.
/// @param transceiver The address of the transceiver.
Expand Down
Loading

0 comments on commit 964a4de

Please sign in to comment.