-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Track uptimes for delegation period #520
Changes from 2 commits
b59614d
feef247
31f4c83
59b83c1
3f20e79
1d21ca7
03f58d2
0834d6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,11 +79,11 @@ | |
uint64 minimumStakeDuration, | ||
IRewardCalculator rewardCalculator | ||
) internal onlyInitializing { | ||
PoSValidatorManagerStorage storage s = _getPoSValidatorManagerStorage(); | ||
s._minimumStakeAmount = minimumStakeAmount; | ||
s._maximumStakeAmount = maximumStakeAmount; | ||
s._minimumStakeDuration = minimumStakeDuration; | ||
s._rewardCalculator = rewardCalculator; | ||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); | ||
$._minimumStakeAmount = minimumStakeAmount; | ||
$._maximumStakeAmount = maximumStakeAmount; | ||
$._minimumStakeDuration = minimumStakeDuration; | ||
$._rewardCalculator = rewardCalculator; | ||
} | ||
|
||
function initializeEndValidation( | ||
|
@@ -92,34 +92,38 @@ | |
uint32 messageIndex | ||
) external { | ||
if (includeUptimeProof) { | ||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); | ||
(WarpMessage memory warpMessage, bool valid) = | ||
WARP_MESSENGER.getVerifiedWarpMessage(messageIndex); | ||
require(valid, "PoSValidatorManager: invalid warp message"); | ||
|
||
require( | ||
warpMessage.sourceChainID == WARP_MESSENGER.getBlockchainID(), | ||
"PoSValidatorManager: invalid source chain ID" | ||
); | ||
require( | ||
warpMessage.originSenderAddress == address(0), | ||
"PoSValidatorManager: invalid origin sender address" | ||
); | ||
|
||
(bytes32 uptimeValidationID, uint64 uptime) = | ||
ValidatorMessages.unpackValidationUptimeMessage(warpMessage.payload); | ||
require( | ||
validationID == uptimeValidationID, | ||
"PoSValidatorManager: invalid uptime validation ID" | ||
); | ||
|
||
$._validatorUptimes[validationID] = uptime; | ||
emit ValidationUptimeUpdated(validationID, uptime); | ||
_updateUptime(validationID, messageIndex); | ||
} | ||
|
||
_initializeEndValidation(validationID); | ||
} | ||
|
||
function _updateUptime(bytes32 validationID, uint32 messageIndex) internal returns (uint64) { | ||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); | ||
(WarpMessage memory warpMessage, bool valid) = | ||
WARP_MESSENGER.getVerifiedWarpMessage(messageIndex); | ||
require(valid, "PoSValidatorManager: invalid warp message"); | ||
|
||
require( | ||
warpMessage.sourceChainID == WARP_MESSENGER.getBlockchainID(), | ||
"PoSValidatorManager: invalid source chain ID" | ||
); | ||
require( | ||
warpMessage.originSenderAddress == address(0), | ||
"PoSValidatorManager: invalid origin sender address" | ||
); | ||
|
||
(bytes32 uptimeValidationID, uint64 uptime) = | ||
ValidatorMessages.unpackValidationUptimeMessage(warpMessage.payload); | ||
require( | ||
validationID == uptimeValidationID, "PoSValidatorManager: invalid uptime validation ID" | ||
); | ||
|
||
$._validatorUptimes[validationID] = uptime; | ||
emit ValidationUptimeUpdated(validationID, uptime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should only update the validator's uptime if the uptime provided is greater than the previously provided uptime. This way delegators may not have to provide an uptime proof to get their rewards, provided the validator has had a sufficiently high uptime. |
||
|
||
return uptime; | ||
} | ||
|
||
function _processStake(uint256 stakeAmount) internal virtual returns (uint64) { | ||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); | ||
// Lock the stake in the contract. | ||
|
@@ -185,6 +189,7 @@ | |
endedAt: 0, | ||
startingNonce: nonce, | ||
endingNonce: 0, | ||
validatorUptime: 0, | ||
status: DelegatorStatus.PendingAdded | ||
}); | ||
|
||
|
@@ -241,7 +246,16 @@ | |
}); | ||
} | ||
|
||
function initializeEndDelegation(bytes32 validationID) external { | ||
function initializeEndDelegation( | ||
bytes32 validationID, | ||
bool includeUptimeProof, | ||
uint32 messageIndex | ||
) external { | ||
uint64 uptime; | ||
|
||
if (includeUptimeProof) { | ||
uptime = _updateUptime(validationID, messageIndex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should read from state instead of using a return from |
||
} | ||
|
||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); | ||
|
||
// Ensure the delegator is active | ||
|
@@ -253,6 +267,7 @@ | |
delegator.status = DelegatorStatus.PendingRemoved; | ||
delegator.endedAt = uint64(block.timestamp); | ||
delegator.endingNonce = nonce; | ||
delegator.validatorUptime = uptime; | ||
|
||
$._delegatorStakes[validationID][_msgSender()] = delegator; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my own understanding, does uptime return the absolute amount of time that the validator was up, or a percent of time that it was up during the staking period? I'm just thinking of whether other information is necessary to calculate rewards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns the absolute number of seconds the validator has been up