-
Notifications
You must be signed in to change notification settings - Fork 14
Draft implementation of ChannelConfigStore.addChannelDefinitions #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kaleofduty
wants to merge
3
commits into
develop
Choose a base branch
from
channel-adder
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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( | ||
| 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"; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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_channelDefinitionVersionsexists for particulardonIdi.e. we've calledsetChannelDefinitionsat least once?