Skip to content

Commit

Permalink
Add support for subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
susruth committed Jun 9, 2022
1 parent 0ae6103 commit 49a28c9
Show file tree
Hide file tree
Showing 4 changed files with 1,000 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ coverage.json
scTopics
allFiredEvents
in_complete_tests
build/development
build
local_*
bindings.go
types
62 changes: 9 additions & 53 deletions contracts/DarknodeRegistry/DarknodeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import "./DarknodeRegistryStore.sol";
import "../Governance/Claimable.sol";
import "../libraries/CanReclaimTokens.sol";
import "./DarknodeRegistryV1.sol";
import "./DarknodeRegistryV2.sol";

contract DarknodeRegistryStateV2 {
contract DarknodeRegistryStateV3 {
// RenVM can have a maximum of 256 subnets, and a darknodes inclusion or
// exclusion is set using the ith bit of the below subnet
mapping (address=>uint256) public subnets;
Expand All @@ -22,11 +23,12 @@ contract DarknodeRegistryStateV2 {

/// @notice DarknodeRegistry is responsible for the registration and
/// deregistration of Darknodes.
contract DarknodeRegistryLogicV2 is
contract DarknodeRegistryLogicV3 is
Claimable,
CanReclaimTokens,
DarknodeRegistryStateV1,
DarknodeRegistryStateV2
DarknodeRegistryStateV2,
DarknodeRegistryStateV3
{
using SafeMath for uint256;

Expand Down Expand Up @@ -66,6 +68,7 @@ contract DarknodeRegistryLogicV2 is
address indexed _darknodeOperator,
address indexed _darknodeID,
address indexed _challenger,
uint8 _subnetID,
uint256 _percentage
);

Expand Down Expand Up @@ -157,6 +160,7 @@ contract DarknodeRegistryLogicV2 is
_;
}

/// @notice Restrict a function to nodes on the specific subnet.
modifier onSubnet(address _darknodeID, uint8 _subnetID) {
require(
subnets[_darknodeID] & 2**uint256(_subnetID) == 2**uint256(_subnetID),
Expand Down Expand Up @@ -564,50 +568,6 @@ contract DarknodeRegistryLogicV2 is
/// @param _challenger The challenger who should receive a portion of the bond as reward.
/// @param _percentage The total percentage of bond to be slashed.
function slash(
address _guilty,
address _challenger,
uint256 _percentage
) external onlySlasher onlyDarknode(_guilty) {
require(_percentage <= 100, "DarknodeRegistry: invalid percent");

// If the darknode has not been deregistered then deregister it
if (isDeregisterable(_guilty)) {
deregisterDarknode(_guilty);
}

uint256 totalBond = store.darknodeBond(_guilty);
uint256 penalty = totalBond.div(100).mul(_percentage);
uint256 challengerReward = penalty.div(2);
uint256 slasherPortion = penalty.sub(challengerReward);
if (challengerReward > 0) {
// Slash the bond of the failed prover
store.updateDarknodeBond(_guilty, totalBond.sub(penalty));

// Forward the remaining amount to be handled by the slasher.
require(
ren.transfer(msg.sender, slasherPortion),
"DarknodeRegistry: reward transfer to slasher failed"
);
require(
ren.transfer(_challenger, challengerReward),
"DarknodeRegistry: reward transfer to challenger failed"
);
}

emit LogDarknodeSlashed(
store.darknodeOperator(_guilty),
_guilty,
_challenger,
_percentage
);
}

/// @notice Allow the DarknodeSlasher contract to slash a portion of darknode's
/// bond and deregister it.
/// @param _guilty The guilty prover whose bond is being slashed.
/// @param _challenger The challenger who should receive a portion of the bond as reward.
/// @param _percentage The total percentage of bond to be slashed.
function slashSubnet(
uint8 _subnetID,
address _guilty,
address _challenger,
Expand Down Expand Up @@ -643,6 +603,7 @@ contract DarknodeRegistryLogicV2 is
store.darknodeOperator(_guilty),
_guilty,
_challenger,
_subnetID,
_percentage
);
}
Expand Down Expand Up @@ -1097,9 +1058,4 @@ contract DarknodeRegistryLogicV2 is
}
return (nPreviousEpoch, nCurrentEpoch, nNextEpoch);
}
}

/* solium-disable-next-line no-empty-blocks */
contract DarknodeRegistryProxy is InitializableAdminUpgradeabilityProxy {

}
}

0 comments on commit 49a28c9

Please sign in to comment.