-
Notifications
You must be signed in to change notification settings - Fork 48
Add reward caller (using transcoder-to-reward caller mapping direction) #648
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
Changes from all commits
3a4056d
32d094a
e69bdcb
6fe4dfa
a3bd430
5bce7ca
884a9a2
c3d1256
9a01599
fa8522e
d27972b
b1df47d
3e28524
ae18d5a
adf105c
d7bb088
d81d76b
99c0008
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,7 +29,7 @@ | |||||||||||
| // Constants | ||||||||||||
| // Occurances are replaced at compile time | ||||||||||||
| // and computed to a single value if possible by the optimizer | ||||||||||||
| uint256 constant MAX_FUTURE_ROUND = 2**256 - 1; | ||||||||||||
|
|
||||||||||||
| // Time between unbonding and possible withdrawl in rounds | ||||||||||||
| uint64 public unbondingPeriod; | ||||||||||||
|
|
@@ -102,6 +102,10 @@ | |||||||||||
| // If the balance of the treasury in LPT is above this value, automatic treasury contributions will halt. | ||||||||||||
| uint256 public treasuryBalanceCeiling; | ||||||||||||
|
|
||||||||||||
| // Allow reward() calls from one pre-defined address per transcoder. | ||||||||||||
| // @dev Since the setter is callable by any address, a mapping key does not guarantee to be a registered or active transcoder. | ||||||||||||
| mapping(address => address) public transcoderToRewardCaller; | ||||||||||||
|
|
||||||||||||
| // Check if sender is TicketBroker | ||||||||||||
| modifier onlyTicketBroker() { | ||||||||||||
| _onlyTicketBroker(); | ||||||||||||
|
|
@@ -188,6 +192,16 @@ | |||||||||||
| emit ParameterUpdate("numActiveTranscoders"); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @notice Set a reward caller for a transcoder | ||||||||||||
| * @param _rewardCaller Address of the new reward caller | ||||||||||||
| * @dev By providing address(0) the reward caller can be unset | ||||||||||||
| */ | ||||||||||||
| function setRewardCaller(address _rewardCaller) external whenSystemNotPaused { | ||||||||||||
| transcoderToRewardCaller[msg.sender] = _rewardCaller; | ||||||||||||
| emit RewardCallerSet(msg.sender, _rewardCaller); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @notice Sets commission rates as a transcoder and if the caller is not in the transcoder pool tries to add it | ||||||||||||
| * @dev Percentages are represented as numerators of fractions over MathUtils.PERC_DIVISOR | ||||||||||||
|
|
@@ -294,6 +308,15 @@ | |||||||||||
| rewardWithHint(address(0), address(0)); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @notice Mint token rewards for an active transcoder and its delegators | ||||||||||||
| * @param _transcoder Address of the transcoder on behalf of which the reward is called | ||||||||||||
| * @dev Only callable by trusted rewardCaller | ||||||||||||
| */ | ||||||||||||
| function rewardForTranscoder(address _transcoder) external { | ||||||||||||
| rewardForTranscoderWithHint(_transcoder, address(0), address(0)); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @notice Update transcoder's fee pool. Only callable by the TicketBroker | ||||||||||||
| * @param _transcoder Transcoder address | ||||||||||||
|
|
@@ -863,21 +886,53 @@ | |||||||||||
| * @param _newPosPrev Address of previous transcoder in pool if the caller is in the pool | ||||||||||||
| * @param _newPosNext Address of next transcoder in pool if the caller is in the pool | ||||||||||||
| */ | ||||||||||||
| function rewardWithHint(address _newPosPrev, address _newPosNext) | ||||||||||||
| public | ||||||||||||
| whenSystemNotPaused | ||||||||||||
| currentRoundInitialized | ||||||||||||
| autoCheckpoint(msg.sender) | ||||||||||||
| { | ||||||||||||
| function rewardWithHint(address _newPosPrev, address _newPosNext) public { | ||||||||||||
|
Member
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. Why did we do away with the whenSystemNotPaused, currentRoundInitialized, autoCheckpoint modifiers on this function?
Collaborator
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. They didn't go away. All of those modifiers are being called in the underlying private function protocol/contracts/bonding/BondingManager.sol Lines 922 to 926 in 99c0008
This way, both
Member
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. To add to this, keeping it in the parent function may increase the risk of introducing side effects if |
||||||||||||
| _rewardWithHint(msg.sender, _newPosPrev, _newPosNext); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @notice Mint token rewards for an active transcoder and its delegators and update the transcoder pool using an optional list hint if needed | ||||||||||||
| * @dev If the `_transcoder` is in the transcoder pool, the caller can provide an optional hint for its insertion position in the | ||||||||||||
| * pool via the `_newPosPrev` and `_newPosNext` params. A linear search will be executed starting at the hint to find the correct position. | ||||||||||||
| * In the best case, the hint is the correct position so no search is executed. See SortedDoublyLL.sol for details on list hints | ||||||||||||
| * @dev Only callable by trusted rewardCaller | ||||||||||||
| * @param _transcoder Address of the transcoder on behalf of which the reward is called | ||||||||||||
| * @param _newPosPrev Address of previous transcoder in pool if the `_transcoder` is in the pool | ||||||||||||
| * @param _newPosNext Address of next transcoder in pool if the `_transcoder` is in the pool | ||||||||||||
| */ | ||||||||||||
| function rewardForTranscoderWithHint( | ||||||||||||
| address _transcoder, | ||||||||||||
| address _newPosPrev, | ||||||||||||
| address _newPosNext | ||||||||||||
| ) public { | ||||||||||||
| address rewardCaller = transcoderToRewardCaller[_transcoder]; | ||||||||||||
| require(rewardCaller == msg.sender, "caller must be a reward caller set by the transcoder"); | ||||||||||||
| _rewardWithHint(_transcoder, _newPosPrev, _newPosNext); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @notice Mint token rewards for an active transcoder and its delegators and update the transcoder pool using an optional list hint if needed | ||||||||||||
| * @dev If the `_transcoder` is in the transcoder pool, the caller can provide an optional hint for its insertion position in the | ||||||||||||
| * pool via the `_newPosPrev` and `_newPosNext` params. A linear search will be executed starting at the hint to find the correct position. | ||||||||||||
| * In the best case, the hint is the correct position so no search is executed. See SortedDoublyLL.sol for details on list hints | ||||||||||||
| * @param _transcoder Address of the transcoder on behalf of which the reward is called | ||||||||||||
| * @param _newPosPrev Address of previous transcoder in pool if `_transcoder` is in the pool | ||||||||||||
| * @param _newPosNext Address of next transcoder in pool if `_transcoder` is in the pool | ||||||||||||
| */ | ||||||||||||
| function _rewardWithHint( | ||||||||||||
| address _transcoder, | ||||||||||||
| address _newPosPrev, | ||||||||||||
| address _newPosNext | ||||||||||||
| ) private whenSystemNotPaused currentRoundInitialized autoCheckpoint(_transcoder) { | ||||||||||||
| uint256 currentRound = roundsManager().currentRound(); | ||||||||||||
|
|
||||||||||||
| require(isActiveTranscoder(msg.sender), "caller must be an active transcoder"); | ||||||||||||
| require(isActiveTranscoder(_transcoder), "transcoder must be active"); | ||||||||||||
| require( | ||||||||||||
| transcoders[msg.sender].lastRewardRound != currentRound, | ||||||||||||
| transcoders[_transcoder].lastRewardRound != currentRound, | ||||||||||||
| "caller has already called reward for the current round" | ||||||||||||
|
SidestreamCrunchyCarrot marked this conversation as resolved.
|
||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| Transcoder storage t = transcoders[msg.sender]; | ||||||||||||
| Transcoder storage t = transcoders[_transcoder]; | ||||||||||||
| EarningsPool.Data storage earningsPool = t.earningsPoolPerRound[currentRound]; | ||||||||||||
|
|
||||||||||||
| // Set last round that transcoder called reward | ||||||||||||
|
|
@@ -910,17 +965,17 @@ | |||||||||||
|
|
||||||||||||
| mtr.trustedTransferTokens(trsry, treasuryRewards); | ||||||||||||
|
|
||||||||||||
| emit TreasuryReward(msg.sender, trsry, treasuryRewards); | ||||||||||||
| emit TreasuryReward(_transcoder, trsry, treasuryRewards); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| uint256 transcoderRewards = totalRewardTokens.sub(treasuryRewards); | ||||||||||||
|
|
||||||||||||
| updateTranscoderWithRewards(msg.sender, transcoderRewards, currentRound, _newPosPrev, _newPosNext); | ||||||||||||
| updateTranscoderWithRewards(_transcoder, transcoderRewards, currentRound, _newPosPrev, _newPosNext); | ||||||||||||
|
|
||||||||||||
| // Set last round that transcoder called reward | ||||||||||||
| t.lastRewardRound = currentRound; | ||||||||||||
|
|
||||||||||||
| emit Reward(msg.sender, transcoderRewards); | ||||||||||||
| emit Reward(_transcoder, transcoderRewards); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.