-
Notifications
You must be signed in to change notification settings - Fork 49
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
Open
SidestreamSweatyPumpkin
wants to merge
15
commits into
livepeer:delta
Choose a base branch
from
sidestream-tech:feat/add-reward-caller/transcoder-to-reward-caller
base: delta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3a4056d
add rewardCallerToTranscoder mapping, reward logic, setter
SidestreamSweatyPumpkin 32d094a
add basic tests
SidestreamSweatyPumpkin e69bdcb
ci: enforce test coverage threshold
SidestreamSweatyPumpkin 6fe4dfa
add unsetRewardCaller
SidestreamSweatyPumpkin a3bd430
full test coverage
SidestreamSweatyPumpkin 5bce7ca
remove unnecessary variable
SidestreamSweatyPumpkin 884a9a2
use transcoder -> rewardCaller mapping direction to prevent frontruns
SidestreamSweatyPumpkin c3d1256
make mapping public
SidestreamSweatyPumpkin 9a01599
add checkpoint test for the reward caller
SidestreamSweatyPumpkin fa8522e
fix typo: an active -> active
SidestreamSweatyPumpkin d27972b
fix: rewardForTranscoderWithHint, _rewardWithHint comments to mention…
SidestreamSweatyPumpkin b1df47d
add missing interfaces
SidestreamSweatyPumpkin 3e28524
add additional sanity checks
SidestreamSweatyPumpkin ae18d5a
update _rewardWithHint natspec comment
SidestreamSweatyPumpkin adf105c
Merge branch 'delta' into feat/add-reward-caller/transcoder-to-reward…
SidestreamSweatyPumpkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,9 @@ | |||||
| // 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 | ||||||
| mapping(address => address) public transcoderToRewardCaller; | ||||||
|
|
||||||
| // Check if sender is TicketBroker | ||||||
| modifier onlyTicketBroker() { | ||||||
| _onlyTicketBroker(); | ||||||
|
|
@@ -188,6 +191,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 +307,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 +885,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 { | ||||||
| _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 previous transcoder in pool if the `_transcoder` is in the pool | ||||||
|
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.
Suggested change
|
||||||
| */ | ||||||
| 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" | ||||||
| ); | ||||||
|
|
||||||
| 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 +964,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); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 noting that in spite of the mapping name, anyone can call this function so the address key in the mapping may not correspond to a transcoder. I don't see an immediate problem with this, but wanted to a) confirm that this property has been considered and b) suggest some in-line documentation if this property has been deemed a non-issue.