Skip to content

Commit

Permalink
Add infraction type enum for granular punishment
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Aug 8, 2024
1 parent c64c0d3 commit 904b811
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 15 additions & 4 deletions contracts/contracts/coordination/InfractionCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ contract InfractionCollector is OwnableUpgradeable {
// Reference to the TACoChildApplication contract
ITACoChildApplication public tacoChildApplication;

// infraction types
enum InfractionType {
MISSING_TRANSCRIPT
}

// Mapping to keep track of reported infractions
mapping(uint32 => mapping(address => bool)) public infractions;
mapping(uint32 => mapping(address => mapping(InfractionType => bool))) public infractions;

function initialize(
Coordinator _coordinator,
Expand All @@ -36,15 +41,21 @@ contract InfractionCollector is OwnableUpgradeable {

for (uint256 i = 0; i < stakingProviders.length; i++) {
// Check if the infraction has already been reported
require(!infractions[ritualId][stakingProviders[i]], "Infraction already reported");
require(
!infractions[ritualId][stakingProviders[i]][InfractionType.MISSING_TRANSCRIPT],
"Infraction already reported"
);
Coordinator.Participant memory participant = coordinator.getParticipantFromProvider(
ritualId,
stakingProviders[i]
);
if (participant.transcript.length == 0) { // Transcript TX wasn't posted
if (participant.transcript.length == 0) {
// Transcript TX wasn't posted
// Penalize the staking provider
tacoChildApplication.penalize(stakingProviders[i]);
infractions[ritualId][stakingProviders[i]] = true;
infractions[ritualId][stakingProviders[i]][
InfractionType.MISSING_TRANSCRIPT
] = true;
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions tests/test_infraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

import ape
import pytest
from eth_account import Account
from eth_account.messages import encode_defunct
from hexbytes import HexBytes
from web3 import Web3

TIMEOUT = 1000
MAX_DKG_SIZE = 31
Expand Down Expand Up @@ -156,7 +152,7 @@ def test_report_infractions(erc20, nodes, initiator, global_allow_list, infracti
chain.pending_timestamp += TIMEOUT * 2
infraction_collector.reportMissingTranscript(0, nodes, sender=initiator)
for node in nodes:
assert infraction_collector.infractions(0, node) == True
assert infraction_collector.infractions(0, node, 0) == True

def test_cant_report_infractions_twice(erc20, nodes, initiator, global_allow_list, infraction_collector, coordinator, chain):
for node in nodes:
Expand Down

0 comments on commit 904b811

Please sign in to comment.