forked from nucypher/nucypher-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first draft of InfractionCollector
Fixes nucypher#266
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol"; | ||
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 { | ||
Check failure on line 18 in contracts/contracts/coordination/InfractionCollector.sol GitHub Actions / linting
|
||
__Ownable_init(); | ||
|
||
coordinator = _coordinator; | ||
tacoChildApplication = _tacoChildApplication; | ||
} | ||
|
||
function reportMissingTranscript(bytes32 ritualId, address[] calldata stakingProviders) external { | ||
// Ritual must have failed | ||
require(coordinator.getRitualState(ritualId) == Coordinator.RitualState.DKG_TIMEOUT, "Ritual must have failed"); | ||
Check failure on line 27 in contracts/contracts/coordination/InfractionCollector.sol GitHub Actions / linting
|
||
|
||
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]); | ||
if (participant.transcript.length == 0) { | ||
// Penalize the staking provider | ||
tacoChildApplication.penalize(stakingProviders[i]); | ||
infractions[ritualId][stakingProviders[i]] = true; | ||
} | ||
} | ||
} | ||
} | ||