From 77040386ae5bc81c732be77adfd0cd75607dd16d Mon Sep 17 00:00:00 2001 From: James Campbell Date: Wed, 15 May 2024 14:34:40 +0200 Subject: [PATCH] Replace reference to `adjudicator` in `TACoChildApplication` with `infractionCollector` Fix formatting errors and tests Include Participant struct Fix types Fix test reversion message --- .../coordination/InfractionCollector.sol | 28 +++++++++++++------ .../coordination/TACoChildApplication.sol | 18 ++++++++---- tests/test_child_application.py | 2 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/contracts/contracts/coordination/InfractionCollector.sol b/contracts/contracts/coordination/InfractionCollector.sol index 1c1d7e0d..6c9a43af 100644 --- a/contracts/contracts/coordination/InfractionCollector.sol +++ b/contracts/contracts/coordination/InfractionCollector.sol @@ -6,30 +6,40 @@ import "./Coordinator.sol"; import "./TACoChildApplication.sol"; contract InfractionCollector is OwnableUpgradeable { - // Reference to the Coordinator contract Coordinator private coordinator; // Reference to the TACoChildApplication contract TACoChildApplication private tacoChildApplication; // Mapping to keep track of reported infractions - mapping(bytes32 => mapping(address => bool)) private infractions; - - function initialize(Coordinator _coordinator, TACoChildApplication _tacoChildApplication) public initializer { - __Ownable_init(); + mapping(uint32 => mapping(address => bool)) private infractions; + function initialize( + Coordinator _coordinator, + TACoChildApplication _tacoChildApplication + ) public initializer { + __Ownable_init(msg.sender); coordinator = _coordinator; tacoChildApplication = _tacoChildApplication; } - function reportMissingTranscript(bytes32 ritualId, address[] calldata stakingProviders) external { + function reportMissingTranscript( + uint32 ritualId, + address[] calldata stakingProviders + ) external { // Ritual must have failed - require(coordinator.getRitualState(ritualId) == Coordinator.RitualState.DKG_TIMEOUT, "Ritual must have failed"); + require( + coordinator.getRitualState(ritualId) == Coordinator.RitualState.DKG_TIMEOUT, + "Ritual must have failed" + ); for (uint256 i = 0; i < stakingProviders.length; i++) { // Check if the infraction has already been reported require(!infractions[ritualId][stakingProviders[i]], "Infraction already reported"); - participant = coordinator.getParticipantFromProvider(ritualId, stakingProviders[i]); + Coordinator.Participant memory participant = coordinator.getParticipantFromProvider( + ritualId, + stakingProviders[i] + ); if (participant.transcript.length == 0) { // Penalize the staking provider tacoChildApplication.penalize(stakingProviders[i]); @@ -37,4 +47,4 @@ contract InfractionCollector is OwnableUpgradeable { } } } -} \ No newline at end of file +} diff --git a/contracts/contracts/coordination/TACoChildApplication.sol b/contracts/contracts/coordination/TACoChildApplication.sol index e829ddd0..d4f699a2 100644 --- a/contracts/contracts/coordination/TACoChildApplication.sol +++ b/contracts/contracts/coordination/TACoChildApplication.sol @@ -31,7 +31,7 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia ITACoChildToRoot public immutable rootApplication; address public coordinator; - address public adjudicator; + address public infractionCollector; uint96 public immutable minimumAuthorization; @@ -61,10 +61,13 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia /** * @notice Initialize function for using with OpenZeppelin proxy */ - function initialize(address _coordinator, address _adjudicator) external initializer { - require(coordinator == address(0) || adjudicator == address(0), "Contracts already set"); + function initialize(address _coordinator, address _infractionCollector) external initializer { require( - _coordinator != address(0) && _adjudicator != address(0), + coordinator == address(0) || infractionCollector == address(0), + "Contracts already set" + ); + require( + _coordinator != address(0) && _infractionCollector != address(0), "Contracts must be specified" ); require( @@ -72,7 +75,7 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia "Invalid coordinator" ); coordinator = _coordinator; - adjudicator = _adjudicator; + infractionCollector = _infractionCollector; } function authorizedStake(address _stakingProvider) external view returns (uint96) { @@ -200,7 +203,10 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia * @param _stakingProvider Staking provider address */ function penalize(address _stakingProvider) external override { - require(msg.sender == address(adjudicator), "Only adjudicator allowed to penalize"); + require( + msg.sender == address(infractionCollector), + "Only infractionCollector allowed to penalize" + ); rootApplication.penalize(_stakingProvider); emit Penalized(_stakingProvider); } diff --git a/tests/test_child_application.py b/tests/test_child_application.py index f5e52b20..8194fe3c 100644 --- a/tests/test_child_application.py +++ b/tests/test_child_application.py @@ -331,7 +331,7 @@ def test_penalize(accounts, root_application, child_application, coordinator): ) = accounts[0:] # Penalize can be done only from adjudicator address - with ape.reverts("Only adjudicator allowed to penalize"): + with ape.reverts("Only infractionCollector allowed to penalize"): child_application.penalize(staking_provider, sender=staking_provider) tx = child_application.penalize(staking_provider, sender=creator)