-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJailingStorage.sol
171 lines (147 loc) · 5.53 KB
/
JailingStorage.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "../../../interfaces/validator/info-fragments/IJailingInfo.sol";
abstract contract JailingStorage is IJailingInfo {
/// @dev Mapping from candidate id => period number => block producer has no pending reward.
mapping(address => mapping(uint256 => bool)) internal _miningRewardDeprecatedAtPeriod;
/// @dev Mapping from candidate id => period number => whether the block producer get cut off reward, due to bailout.
mapping(address => mapping(uint256 => bool)) internal _miningRewardBailoutCutOffAtPeriod;
/// @dev Mapping from candidate id => period number => block operator has no pending reward.
mapping(address => mapping(uint256 => bool)) internal ______deprecatedBridgeRewardDeprecatedAtPeriod;
/// @dev Mapping from candidate id => the last block that the block producer is jailed.
mapping(address => uint256) internal _blockProducerJailedBlock;
/// @dev Mapping from candidate id => the last timestamp that the bridge operator is jailed.
mapping(address => uint256) internal _emergencyExitJailedTimestamp;
/// @dev Mapping from candidate id => the last block that the block producer cannot bailout.
mapping(address => uint256) internal _cannotBailoutUntilBlock;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
*/
uint256[48] private ______gap;
/**
* @inheritdoc IJailingInfo
*/
function checkJailed(
TConsensus consensus
) external view override returns (bool) {
address candidateId = __css2cid(consensus);
return _isJailedAtBlockById(candidateId, block.number);
}
/**
* @inheritdoc IJailingInfo
*/
function checkJailedAtBlock(TConsensus addr, uint256 blockNum) external view override returns (bool) {
address candidateId = __css2cid(addr);
return _isJailedAtBlockById(candidateId, blockNum);
}
/**
* @inheritdoc IJailingInfo
*/
function getJailedTimeLeft(
TConsensus consensus
) external view override returns (bool isJailed_, uint256 blockLeft_, uint256 epochLeft_) {
return _getJailedTimeLeftAtBlockById(__css2cid(consensus), block.number);
}
/**
* @inheritdoc IJailingInfo
*/
function getJailedTimeLeftAtBlock(
TConsensus consensus,
uint256 _blockNum
) external view override returns (bool isJailed_, uint256 blockLeft_, uint256 epochLeft_) {
return _getJailedTimeLeftAtBlockById(__css2cid(consensus), _blockNum);
}
function _getJailedTimeLeftAtBlockById(
address candidateId,
uint256 blockNum
) internal view returns (bool isJailed_, uint256 blockLeft_, uint256 epochLeft_) {
uint256 jailedBlock = _blockProducerJailedBlock[candidateId];
if (jailedBlock < blockNum) {
return (false, 0, 0);
}
isJailed_ = true;
blockLeft_ = jailedBlock - blockNum + 1;
epochLeft_ = epochOf(jailedBlock) - epochOf(blockNum) + 1;
}
/**
* @inheritdoc IJailingInfo
*/
function checkManyJailed(
TConsensus[] calldata consensusList
) external view override returns (bool[] memory) {
return _checkManyJailedById(__css2cidBatch(consensusList));
}
function checkManyJailedById(
address[] calldata candidateIds
) external view override returns (bool[] memory) {
return _checkManyJailedById(candidateIds);
}
function _checkManyJailedById(
address[] memory candidateIds
) internal view returns (bool[] memory result) {
result = new bool[](candidateIds.length);
for (uint256 i; i < candidateIds.length;) {
result[i] = _isJailedById(candidateIds[i]);
unchecked {
++i;
}
}
}
/**
* @inheritdoc IJailingInfo
*/
function checkMiningRewardDeprecated(
TConsensus consensus
) external view override returns (bool) {
uint256 period = currentPeriod();
return _miningRewardDeprecatedById(__css2cid(consensus), period);
}
/**
* @inheritdoc IJailingInfo
*/
function checkMiningRewardDeprecatedAtPeriod(
TConsensus consensus,
uint256 period
) external view override returns (bool) {
return _miningRewardDeprecatedById(__css2cid(consensus), period);
}
/**
* @dev See `ITimingInfo-epochOf`
*/
function epochOf(
uint256 _block
) public view virtual returns (uint256);
/**
* @dev See `ITimingInfo-currentPeriod`
*/
function currentPeriod() public view virtual returns (uint256);
/**
* @dev Returns whether the reward of the validator is put in jail (cannot join the set of validators) during the current period.
*/
function _isJailedById(
address validatorId
) internal view returns (bool) {
return _isJailedAtBlockById(validatorId, block.number);
}
/**
* @dev Returns whether the reward of the validator is put in jail (cannot join the set of validators) at a specific block.
*/
function _isJailedAtBlockById(address validatorId, uint256 blockNum) internal view returns (bool) {
return blockNum <= _blockProducerJailedBlock[validatorId];
}
/**
* @dev Returns whether the block producer has no pending reward in that period.
*/
function _miningRewardDeprecatedById(address validatorId, uint256 period) internal view returns (bool) {
return _miningRewardDeprecatedAtPeriod[validatorId][period];
}
/// @dev See {RoninValidatorSet-__css2cid}
function __css2cid(
TConsensus consensusAddr
) internal view virtual returns (address);
/// @dev See {RoninValidatorSet-__css2cidBatch}
function __css2cidBatch(
TConsensus[] memory consensusAddrs
) internal view virtual returns (address[] memory);
}