Skip to content

Commit 10fdf5d

Browse files
committed
Chaosnet support
This is a beta staker program for stakers willing to go the extra mile with monitoring, share their logs with the dev team, and allow to more carefully monitor the bootstrapping network. As the network matures, the beta program will be ended.
1 parent cb05e6e commit 10fdf5d

3 files changed

Lines changed: 324 additions & 17 deletions

File tree

contracts/Chaosnet.sol

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
pragma solidity 0.8.9;
2+
3+
/// @title Chaosnet
4+
/// @notice This is a beta staker program for stakers willing to go the extra
5+
/// mile with monitoring, share their logs with the dev team, and allow to more
6+
/// carefully monitor the bootstrapping network. As the network matures, the
7+
/// beta program will be ended.
8+
contract Chaosnet {
9+
/// @notice Indicates if the chaosnet is active. The chaosnet is active
10+
/// after the contract deployment and can be ended with a call to
11+
/// `deactivateChaosnet()`. Once deactivated chaosnet can not be activated
12+
/// again.
13+
bool public isChaosnetActive;
14+
15+
/// @notice Indicates if the given operator is a beta operator for chaosnet.
16+
mapping(address => bool) public isBetaOperator;
17+
18+
/// @notice Address controlling chaosnet status and beta operator addresses.
19+
address public chaosnetMaestro;
20+
21+
event BetaOperatorsAdded(address[] operators);
22+
23+
event ChaosnetMaestroRoleTransferred(
24+
address oldChaosnetMaestro,
25+
address newChaosnetMaestro
26+
);
27+
28+
event ChaosnetDeactivated();
29+
30+
constructor() {
31+
_transferChaosnetMaestro(msg.sender);
32+
isChaosnetActive = true;
33+
}
34+
35+
modifier onlyChaosnetMaestro() {
36+
require(msg.sender == chaosnetMaestro, "Not the chaosnet maestro");
37+
_;
38+
}
39+
40+
/// @notice Adds beta operator to chaosnet. Can be called only by the
41+
/// chaosnet maestro.
42+
function addBetaOperators(address[] calldata operators)
43+
public
44+
onlyChaosnetMaestro
45+
{
46+
for (uint256 i = 0; i < operators.length; i++) {
47+
isBetaOperator[operators[i]] = true;
48+
}
49+
50+
emit BetaOperatorsAdded(operators);
51+
}
52+
53+
/// @notice Deactivates the chaosnet. Can be called only by the chaosnet
54+
/// maestro. Once deactivated chaosnet can not be activated again.
55+
function deactivateChaosnet() public onlyChaosnetMaestro {
56+
require(isChaosnetActive, "Chaosnet is not active");
57+
isChaosnetActive = false;
58+
emit ChaosnetDeactivated();
59+
}
60+
61+
/// @notice Transfers the chaosnet maestro role to another non-zero address.
62+
function transferChaosnetMaestroRole(address newChaosnetMaestro)
63+
public
64+
onlyChaosnetMaestro
65+
{
66+
require(
67+
newChaosnetMaestro != address(0),
68+
"New chaosnet maestro must not be zero address"
69+
);
70+
_transferChaosnetMaestro(newChaosnetMaestro);
71+
}
72+
73+
function _transferChaosnetMaestro(address newChaosnetMaestro) internal {
74+
address oldChaosnetMaestro = chaosnetMaestro;
75+
chaosnetMaestro = newChaosnetMaestro;
76+
emit ChaosnetMaestroRoleTransferred(oldChaosnetMaestro, newChaosnetMaestro);
77+
}
78+
}

contracts/SortitionPool.sol

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ import "@openzeppelin/contracts/access/Ownable.sol";
88
import "./RNG.sol";
99
import "./SortitionTree.sol";
1010
import "./Rewards.sol";
11+
import "./Chaosnet.sol";
1112

1213
/// @title Sortition Pool
1314
/// @notice A logarithmic data structure used to store the pool of eligible
1415
/// operators weighted by their stakes. It allows to select a group of operators
1516
/// based on the provided pseudo-random seed.
16-
contract SortitionPool is SortitionTree, Rewards, Ownable, IReceiveApproval {
17+
contract SortitionPool is
18+
SortitionTree,
19+
Rewards,
20+
Ownable,
21+
Chaosnet,
22+
IReceiveApproval
23+
{
1724
using Branch for uint256;
1825
using Leaf for uint256;
1926
using Position for uint256;
@@ -98,7 +105,9 @@ contract SortitionPool is SortitionTree, Rewards, Ownable, IReceiveApproval {
98105
}
99106

100107
/// @notice Inserts an operator to the pool. Reverts if the operator is
101-
/// already present.
108+
/// already present. Reverts if the operator is not eligible because of their
109+
/// authorized stake. Reverts if the chaosnet is active and the operator is
110+
/// not a beta operator.
102111
/// @dev Can be called only by the contract owner.
103112
/// @param operator Address of the inserted operator.
104113
/// @param authorizedStake Inserted operator's authorized stake for the application.
@@ -110,6 +119,10 @@ contract SortitionPool is SortitionTree, Rewards, Ownable, IReceiveApproval {
110119
uint256 weight = getWeight(authorizedStake);
111120
require(weight > 0, "Operator not eligible");
112121

122+
if (isChaosnetActive) {
123+
require(isBetaOperator[operator], "Not beta operator for chaosnet");
124+
}
125+
113126
_insertOperator(operator, weight);
114127
uint32 id = getOperatorID(operator);
115128
Rewards.updateOperatorRewards(id, uint32(weight));

0 commit comments

Comments
 (0)