Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,121 @@
pragma solidity ^0.8.19;

import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol";
import {EnumerableSet} from "@openzeppelin/[email protected]/utils/structs/EnumerableSet.sol";

import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol";
import {IChannelConfigStore} from "./interfaces/IChannelConfigStore.sol";

contract ChannelConfigStore is ConfirmedOwner, IChannelConfigStore, ITypeAndVersion {
using EnumerableSet for EnumerableSet.UintSet;

event NewChannelDefinition(uint256 indexed donId, uint32 version, string url, bytes32 sha);
event ChannelDefinitionAdded(uint256 indexed donId, uint32 indexed channelAdderId, string url, bytes32 sha);
event ChannelAdderSet(uint256 indexed donId, uint32 indexed channelAdderId, bool allowed);
event ChannelAdderAddressSet(uint32 indexed channelAdderId, address adderAddress);

error UnauthorizedChannelAdder();

constructor() ConfirmedOwner(msg.sender) {}

/// @notice The version of a channel definition keyed by DON ID
// Increments by 1 on every update
mapping(uint256 => uint256) internal s_channelDefinitionVersions;

function setChannelDefinitions(uint32 donId, string calldata url, bytes32 sha) external onlyOwner {
/// @notice Mapping from channel adder ID to its corresponding address
mapping(uint32 => address) internal s_channelAdderAddresses;

/// @notice Mapping from DON ID to the set of allowed channel adder IDs
mapping(uint256 => EnumerableSet.UintSet) internal s_allowedChannelAdders;

function setChannelDefinitions(
uint32 donId,
string calldata url,
bytes32 sha
) external onlyOwner {
uint32 newVersion = uint32(++s_channelDefinitionVersions[uint256(donId)]);
emit NewChannelDefinition(donId, newVersion, url, sha);
}

/// @notice Allows a channel adder to add channel definitions to the specified DON.
/// The DON enforces (in its consensus rules), that the channel definitions provided
/// by the channel adder are well-formed, purely additive, and do not overlaod the DON.
/// @param donId The DON ID
/// @param channelAdderId The channel adder ID
/// @param url The URL of the channel definition
/// @param sha The SHA hash of the channel definition
function addChannelDefinitions(
Copy link
Contributor

@akuzni2 akuzni2 Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function check that a s_channelDefinitionVersions exists for particular donId i.e. we've called setChannelDefinitions at least once?

uint256 donId,
uint32 channelAdderId,
string calldata url,
bytes32 sha
) external {
if (msg.sender != s_channelAdderAddresses[channelAdderId]) {
revert UnauthorizedChannelAdder();
}
if (!s_allowedChannelAdders[donId].contains(channelAdderId)) {
revert UnauthorizedChannelAdder();
}
emit ChannelDefinitionAdded(donId, channelAdderId, url, sha);
}

/// @notice Sets the address for a channel adder ID
/// @param channelAdderId The channel adder ID
/// @param adderAddress The address to associate with the channel adder ID
function setChannelAdderAddress(
uint32 channelAdderId,
address adderAddress
) external onlyOwner {
s_channelAdderAddresses[channelAdderId] = adderAddress;
emit ChannelAdderAddressSet(channelAdderId, adderAddress);
}

/// @notice Sets whether a channel adder ID is allowed for a DON
/// @param donId The DON ID
/// @param channelAdderId The channel adder ID
/// @param allowed Whether the channel adder should be allowed or removed
function setChannelAdder(
uint256 donId,
uint32 channelAdderId,
bool allowed
) external onlyOwner {
if (allowed) {
s_allowedChannelAdders[donId].add(channelAdderId);
} else {
s_allowedChannelAdders[donId].remove(channelAdderId);
}
emit ChannelAdderSet(donId, channelAdderId, allowed);
}

/// @notice Gets the address associated with a channel adder ID
/// @param channelAdderId The channel adder ID
/// @return The address associated with the channel adder ID
function getChannelAdderAddress(
uint32 channelAdderId
) external view returns (address) {
return s_channelAdderAddresses[channelAdderId];
}

/// @notice Checks if a channel adder is allowed for a DON
/// @param donId The DON ID
/// @param channelAdderId The channel adder ID
/// @return True if the channel adder is allowed for the DON
function isChannelAdderAllowed(
uint256 donId,
uint32 channelAdderId
) external view returns (bool) {
return s_allowedChannelAdders[donId].contains(channelAdderId);
}

/// @notice Gets all allowed channel adder IDs for a DON
/// @param donId The DON ID
/// @return An array of allowed channel adder IDs
function getAllowedChannelAdders(
uint256 donId
) external view returns (uint256[] memory) {
return s_allowedChannelAdders[donId].values();
}

function typeAndVersion() external pure override returns (string memory) {
return "ChannelConfigStore 0.0.1";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,34 @@ pragma solidity 0.8.19;
import {IERC165} from "@openzeppelin/[email protected]/interfaces/IERC165.sol";

interface IChannelConfigStore is IERC165 {
function setChannelDefinitions(uint32 donId, string calldata url, bytes32 sha) external;
function setChannelDefinitions(
uint32 donId,
string calldata url,
bytes32 sha
) external;
function addChannelDefinitions(
uint256 donId,
uint32 channelAdderId,
string calldata url,
bytes32 sha
) external;
function setChannelAdderAddress(
uint32 channelAdderId,
address adderAddress
) external;
function setChannelAdder(
uint256 donId,
uint32 channelAdderId,
bool allowed
) external;
function getChannelAdderAddress(
uint32 channelAdderId
) external view returns (address);
function isChannelAdderAllowed(
uint256 donId,
uint32 channelAdderId
) external view returns (bool);
function getAllowedChannelAdders(
uint256 donId
) external view returns (uint256[] memory);
}
Loading
Loading