Skip to content

Commit 2a8fbf0

Browse files
committed
Add docs into SFCState, errors rename
1 parent 8a062f7 commit 2a8fbf0

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

contracts/sfc/SFC.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ contract SFC is SFCBase, Version {
138138
bytes memory pubkey = getValidatorPubkey[vid];
139139
if (pubkey.length > 0 && pubkeyHashToValidatorID[keccak256(pubkey)] != vid) {
140140
if (pubkeyHashToValidatorID[keccak256(pubkey)] != 0) {
141-
revert PubkeyExists();
141+
revert PubkeyUsedByOtherValidator();
142142
}
143143
pubkeyHashToValidatorID[keccak256(pubkey)] = vid;
144144
}
@@ -154,13 +154,13 @@ contract SFC is SFCBase, Version {
154154
revert ValidatorNotExists();
155155
}
156156
if (keccak256(pubkey) == keccak256(getValidatorPubkey[validatorID])) {
157-
revert SamePubkey();
157+
revert PubkeyNotChanged();
158158
}
159159
if (pubkeyHashToValidatorID[keccak256(pubkey)] != 0) {
160-
revert PubkeyExists();
160+
revert PubkeyUsedByOtherValidator();
161161
}
162162
if (validatorPubkeyChanges[validatorID] != 0) {
163-
revert PubkeyAllowedOnlyOnce();
163+
revert TooManyPubkeyUpdates();
164164
}
165165

166166
validatorPubkeyChanges[validatorID]++;
@@ -187,7 +187,7 @@ contract SFC is SFCBase, Version {
187187
revert NotAuthorized();
188188
}
189189
if (getRedirection[from] == to) {
190-
revert RequestedCompleted();
190+
revert AlreadyRedirected();
191191
}
192192
if (from == to) {
193193
revert SameAddress();

contracts/sfc/SFCBase.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ contract SFCBase is SFCState {
2424
error ZeroRewards();
2525

2626
// pubkeys
27-
error PubkeyExists();
27+
error PubkeyUsedByOtherValidator();
2828
error MalformedPubkey();
29-
error SamePubkey();
29+
error PubkeyNotChanged();
3030
error EmptyPubkey();
31-
error PubkeyAllowedOnlyOnce();
31+
error TooManyPubkeyUpdates();
3232

3333
// redirections
3434
error SameRedirectionAuthorizer();
@@ -42,7 +42,7 @@ contract SFCBase is SFCState {
4242
error WrongValidatorStatus();
4343

4444
// requests
45-
error RequestedCompleted();
45+
error AlreadyRedirected();
4646
error RequestExists();
4747
error RequestNotExists();
4848

contracts/sfc/SFCLib.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ contract SFCLib is SFCBase {
103103
revert EmptyPubkey();
104104
}
105105
if (pubkeyHashToValidatorID[keccak256(pubkey)] != 0) {
106-
revert PubkeyExists();
106+
revert PubkeyUsedByOtherValidator();
107107
}
108108
_createValidator(msg.sender, pubkey);
109109
_delegate(msg.sender, lastValidatorID, msg.value);

contracts/sfc/SFCState.sol

+38-12
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ contract SFCState is Initializable, Ownable {
1414
uint256 status;
1515
uint256 deactivatedTime;
1616
uint256 deactivatedEpoch;
17-
uint256 receivedStake;
17+
uint256 receivedStake; // from all delegators (weight of the validator)
1818
uint256 createdEpoch;
1919
uint256 createdTime;
20-
address auth;
20+
address auth; // self-stake delegator
2121
}
2222

2323
NodeDriverAuth internal node;
@@ -28,26 +28,34 @@ contract SFCState is Initializable, Ownable {
2828
uint256 unlockedReward;
2929
}
3030

31+
// last sealed epoch (currentEpoch - 1)
3132
uint256 public currentSealedEpoch;
3233
mapping(uint256 => Validator) public getValidator;
3334
mapping(address => uint256) public getValidatorID;
3435
mapping(uint256 => bytes) public getValidatorPubkey;
3536

3637
uint256 public lastValidatorID;
38+
39+
// total stake of all validators - includes slashed/offline validators
3740
uint256 public totalStake;
41+
// total stake of active (OK_STATUS) validators (total weight)
3842
uint256 public totalActiveStake;
43+
// sum of penalties subtracted from successful withdrawals - TODO misleading - remove?
3944
uint256 public totalSlashedStake;
4045

41-
mapping(address => mapping(uint256 => Rewards)) internal _rewardsStash; // addr, validatorID -> Rewards
46+
// delegator => validator ID => stashed rewards (to be claimed/restaked)
47+
mapping(address => mapping(uint256 => Rewards)) internal _rewardsStash;
4248

49+
// delegator => validator ID => last epoch number for which were rewards stashed
4350
mapping(address => mapping(uint256 => uint256)) public stashedRewardsUntilEpoch;
4451

4552
struct WithdrawalRequest {
46-
uint256 epoch;
47-
uint256 time;
53+
uint256 epoch; // epoch where undelegated
54+
uint256 time; // when undelegated
4855
uint256 amount;
4956
}
5057

58+
// delegator => validator ID => withdrawal ID => withdrawal request
5159
mapping(address => mapping(uint256 => mapping(uint256 => WithdrawalRequest))) public getWithdrawalRequest;
5260

5361
struct LockedDelegation {
@@ -57,43 +65,56 @@ contract SFCState is Initializable, Ownable {
5765
uint256 duration;
5866
}
5967

68+
// delegator => validator ID => current stake (locked+unlocked)
6069
mapping(address => mapping(uint256 => uint256)) public getStake;
6170

71+
// delegator => validator ID => locked stake info
6272
mapping(address => mapping(uint256 => LockedDelegation)) public getLockupInfo;
6373

6474
mapping(address => mapping(uint256 => Rewards)) public getStashedLockupRewards;
6575

6676
struct EpochSnapshot {
77+
// validator ID => validator weight in the epoch
6778
mapping(uint256 => uint256) receivedStake;
79+
// validator ID => accumulated ( delegatorsReward * 1e18 / receivedStake )
6880
mapping(uint256 => uint256) accumulatedRewardPerToken;
81+
// validator ID => accumulated online time
6982
mapping(uint256 => uint256) accumulatedUptime;
83+
// validator ID => gas fees from txs originated by the validator
7084
mapping(uint256 => uint256) accumulatedOriginatedTxsFee;
7185
mapping(uint256 => uint256) offlineTime;
7286
mapping(uint256 => uint256) offlineBlocks;
7387
uint256[] validatorIDs;
7488
uint256 endTime;
7589
uint256 endBlock;
76-
uint256 epochFee;
77-
uint256 totalBaseRewardWeight;
78-
uint256 totalTxRewardWeight;
79-
uint256 baseRewardPerSecond;
80-
uint256 totalStake;
81-
uint256 totalSupply;
90+
uint256 epochFee; // gas fees from txs in the epoch
91+
uint256 totalBaseRewardWeight; // sum( stake * uptimeRatio ^ 2 ) TODO write only - remove?
92+
uint256 totalTxRewardWeight; // sum( originatedTxsFee * uptimeRatio ) TODO write only - remove?
93+
uint256 baseRewardPerSecond; // the base reward to divide among validators for each second of the epoch
94+
uint256 totalStake; // total weight of all validators
95+
uint256 totalSupply; // total supply of native tokens
8296
}
8397

98+
// the total supply of native tokens in the chain
8499
uint256 public totalSupply;
100+
// epoch id => epoch snapshot
85101
mapping(uint256 => EpochSnapshot) public getEpochSnapshot;
86102

87-
mapping(uint256 => uint256) public slashingRefundRatio; // validator ID -> (slashing refund ratio)
103+
// validator ID -> slashing refund ratio (allows to withdraw slashed stake)
104+
mapping(uint256 => uint256) public slashingRefundRatio;
88105

106+
// the minimal gas price calculated for the current epoch
89107
uint256 public minGasPrice;
90108

109+
// the treasure contract (receives unlock penalties and a part of epoch fees)
91110
address public treasuryAddress;
92111

112+
// the SFCLib contract
93113
address internal libAddress;
94114

95115
ConstantsManager internal c;
96116

117+
// the governance contract (to recalculate votes when the stake changes)
97118
address public voteBookAddress;
98119

99120
struct Penalty {
@@ -103,13 +124,18 @@ contract SFCState is Initializable, Ownable {
103124
// delegator => validatorID => penalties info
104125
mapping(address => mapping(uint256 => Penalty[])) public getStashedPenalties;
105126

127+
// validator ID => amount of pubkey updates
106128
mapping(uint256 => uint256) internal validatorPubkeyChanges;
107129

130+
// keccak256(pubkey bytes) => validator ID (prevents using the same key by multiple validators)
108131
mapping(bytes32 => uint256) internal pubkeyHashToValidatorID;
109132

133+
// address authorized to initiate redirection
110134
address public redirectionAuthorizer;
111135

136+
// delegator => withdrawals receiver
112137
mapping(address => address) public getRedirectionRequest;
113138

139+
// delegator => withdrawals receiver
114140
mapping(address => address) public getRedirection;
115141
}

0 commit comments

Comments
 (0)