-
Notifications
You must be signed in to change notification settings - Fork 27
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
Centralize reward management in PoSValidatorManager #643
Conversation
005ec21
to
7cb0f4a
Compare
7cb0f4a
to
7e3c8ff
Compare
@@ -760,4 +744,41 @@ abstract contract PoSValidatorManager is | |||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); | |||
return $._posValidatorInfo[validationID].owner != address(0); | |||
} | |||
|
|||
function _withdrawValidationRewards(address rewardRecipient, bytes32 validationID) internal { | |||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); |
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.
Does it make more sense to pass this in?
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.
We currently retrieve the contract storage in every function that needs it, mainly under the assumption that the Solidity compiler is smart enough to cache subsequent reads of the same value. However, I'm not seeing anything in the optimizer steps that would directly translate. We should do a gas cost analysis of this pattern versus passing the storage object around (not necessary for this PR - let's stick to the existing pattern here)
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.
One small nit, otherwise LGTM
@@ -760,4 +744,41 @@ abstract contract PoSValidatorManager is | |||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); | |||
return $._posValidatorInfo[validationID].owner != address(0); | |||
} | |||
|
|||
function _withdrawValidationRewards(address rewardRecipient, bytes32 validationID) internal { | |||
PoSValidatorManagerStorage storage $ = _getPoSValidatorManagerStorage(); |
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.
We currently retrieve the contract storage in every function that needs it, mainly under the assumption that the Solidity compiler is smart enough to cache subsequent reads of the same value. However, I'm not seeing anything in the optimizer steps that would directly translate. We should do a gas cost analysis of this pattern versus passing the storage object around (not necessary for this PR - let's stick to the existing pattern here)
uint256 delegationRewards = 0; | ||
uint256 validatorFees = 0; |
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.
OpenZeppelin called out in their recent audit that not initializing variables with their default value is more gas efficient.
uint256 delegationRewards = 0; | |
uint256 validatorFees = 0; | |
uint256 delegationRewards; | |
uint256 validatorFees; |
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.
That's insane that this doesn't compile down to the same bytecode... will fix!
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.
LGTM other than the small issue that Cam brought up.
45a5f32
to
498650f
Compare
498650f
to
dee4e3d
Compare
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.
LGTM. Interesting that we are now getting Slither warnings.
Why this should be merged
If any of the reward logic changes, the change happens in one place. For the delegator, the logic only existed in one place before, but this keeps the pattern consistent and improves the readability of
_completeEndDelegation
function.How this works
Same as before, I just moved code
How this was tested
Existing tests
How is this documented
inline docs on new functions