Skip to content

Commit

Permalink
Merge pull request #13220 from smartcontractkit/KSI-128/remove-DON
Browse files Browse the repository at this point in the history
KS-128: Implement remove DONs in capability registry
  • Loading branch information
cds95 authored May 17, 2024
2 parents 97b84d0 + 6d8a253 commit 2e698a0
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-horses-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal implement remove DONs in capability registry
5 changes: 5 additions & 0 deletions contracts/.changeset/long-beans-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts": patch
---

implement remove DONs in capability registry
22 changes: 22 additions & 0 deletions contracts/src/v0.8/keystone/CapabilityRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ contract CapabilityRegistry is OwnerIsCreator, TypeAndVersionInterface {
/// @param isPublic True if the newly created DON is public
event DONAdded(uint256 donId, bool isPublic);

/// @notice This event is emitted when a DON is removed
/// @param donId The ID of the removed DON
event DONRemoved(uint32 donId);

/// @notice This error is emitted when a DON does not exist
/// @param donId The ID of the nonexistent DON
error DONDoesNotExist(uint32 donId);

/// @notice This error is thrown when trying to set the node's
/// signer address to zero
error InvalidNodeSigner();
Expand Down Expand Up @@ -559,6 +567,20 @@ contract CapabilityRegistry is OwnerIsCreator, TypeAndVersionInterface {
emit DONAdded(id, isPublic);
}

/// @notice Removes DONs from the Capability Registry
/// @param donIds The IDs of the DON to be removed
function removeDONs(uint32[] calldata donIds) external onlyOwner {
for (uint256 i; i < donIds.length; ++i) {
uint32 donId = donIds[i];
DON storage don = s_dons[donId];

// DON config count starts at index 1
if (don.configCount == 0) revert DONDoesNotExist(donId);
delete s_dons[donId];
emit DONRemoved(donId);
}
}

/// @notice Gets DON's data
/// @param donId The DON ID
/// @return uint32 The DON ID
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {BaseTest} from "./BaseTest.t.sol";

import {CapabilityRegistry} from "../CapabilityRegistry.sol";

contract CapabilityRegistry_RemoveDONsTest is BaseTest {
event DONRemoved(uint32 donId);

uint32 private constant DON_ID = 1;
uint32 private constant TEST_NODE_OPERATOR_ONE_ID = 0;
uint256 private constant TEST_NODE_OPERATOR_TWO_ID = 1;
bytes32 private constant INVALID_P2P_ID = bytes32("fake-p2p");
bytes private constant CONFIG = bytes("onchain-config");

function setUp() public override {
BaseTest.setUp();

s_capabilityRegistry.addNodeOperators(_getNodeOperators());
s_capabilityRegistry.addCapability(s_basicCapability);
s_capabilityRegistry.addCapability(s_capabilityWithConfigurationContract);

CapabilityRegistry.NodeParams[] memory nodes = new CapabilityRegistry.NodeParams[](2);
bytes32[] memory capabilityIds = new bytes32[](2);
capabilityIds[0] = s_basicHashedCapabilityId;
capabilityIds[1] = s_capabilityWithConfigurationContractId;

nodes[0] = CapabilityRegistry.NodeParams({
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID,
p2pId: P2P_ID,
signer: NODE_OPERATOR_ONE_SIGNER_ADDRESS,
hashedCapabilityIds: capabilityIds
});

bytes32[] memory nodeTwoCapabilityIds = new bytes32[](1);
nodeTwoCapabilityIds[0] = s_basicHashedCapabilityId;

nodes[1] = CapabilityRegistry.NodeParams({
nodeOperatorId: TEST_NODE_OPERATOR_ONE_ID,
p2pId: P2P_ID_TWO,
signer: NODE_OPERATOR_TWO_SIGNER_ADDRESS,
hashedCapabilityIds: nodeTwoCapabilityIds
});

changePrank(NODE_OPERATOR_ONE_ADMIN);
s_capabilityRegistry.addNodes(nodes);

CapabilityRegistry.CapabilityConfiguration[]
memory capabilityConfigs = new CapabilityRegistry.CapabilityConfiguration[](1);
capabilityConfigs[0] = CapabilityRegistry.CapabilityConfiguration({
capabilityId: s_basicHashedCapabilityId,
config: CONFIG
});

bytes32[] memory nodeIds = new bytes32[](2);
nodeIds[0] = P2P_ID;
nodeIds[1] = P2P_ID_TWO;

changePrank(ADMIN);
s_capabilityRegistry.addDON(nodeIds, capabilityConfigs, true);
}

function test_RevertWhen_CalledByNonAdmin() public {
uint32[] memory donIDs = new uint32[](1);
donIDs[0] = 1;
changePrank(STRANGER);
vm.expectRevert("Only callable by owner");
s_capabilityRegistry.removeDONs(donIDs);
}

function test_RevertWhen_DONDoesNotExist() public {
uint32 invalidDONId = 10;
uint32[] memory donIDs = new uint32[](1);
donIDs[0] = invalidDONId;
vm.expectRevert(abi.encodeWithSelector(CapabilityRegistry.DONDoesNotExist.selector, invalidDONId));
s_capabilityRegistry.removeDONs(donIDs);
}

function test_RemovesDON() public {
uint32[] memory donIDs = new uint32[](1);
donIDs[0] = DON_ID;
vm.expectEmit(true, true, true, true, address(s_capabilityRegistry));
emit DONRemoved(DON_ID);
s_capabilityRegistry.removeDONs(donIDs);

(
uint32 id,
bool isPublic,
bytes32[] memory donNodes,
CapabilityRegistry.CapabilityConfiguration[] memory donCapabilityConfigs
) = s_capabilityRegistry.getDON(DON_ID);
assertEq(id, 0);
assertEq(isPublic, false);
assertEq(donCapabilityConfigs.length, 0);
assertEq(s_capabilityRegistry.getDONCapabilityConfig(DON_ID, s_basicHashedCapabilityId), bytes(""));
assertEq(donNodes.length, 0);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GETH_VERSION: 1.13.8
forwarder: ../../../contracts/solc/v0.8.19/KeystoneForwarder/KeystoneForwarder.abi ../../../contracts/solc/v0.8.19/KeystoneForwarder/KeystoneForwarder.bin b4c900aae9e022f01abbac7993d41f93912247613ac6270b0c4da4ef6f2016e3
keystone_capability_registry: ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.abi ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.bin efa84b7cae3ce74a85bccd04544ce8176c33cbaf83af24370c0f6e52b2fde0c6
keystone_capability_registry: ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.abi ../../../contracts/solc/v0.8.19/CapabilityRegistry/CapabilityRegistry.bin f44b8bf19bb83bb51c2291fc1967b5c6084b19b7fd6aa5ab3352d0f0c1bd3754
ocr3_capability: ../../../contracts/solc/v0.8.19/OCR3Capability/OCR3Capability.abi ../../../contracts/solc/v0.8.19/OCR3Capability/OCR3Capability.bin 9dcbdf55bd5729ba266148da3f17733eb592c871c2108ccca546618628fd9ad2

0 comments on commit 2e698a0

Please sign in to comment.