livepeer / protocol

Livepeer protocol
MIT License
154 stars 45 forks source link

pendingStake/pendingFees behavior when lastClaimRound = currentRound #363

Closed yondonfu closed 4 years ago

yondonfu commented 4 years ago

At the moment, BondingManager.pendingStake() and BondingManager.pendingFees() both revert if the following require statements fail:

require(_endRound <= currentRound, "end round must be before or equal to current round");
require(_endRound > del.lastClaimRound, "end round must be after last claim round");

The second require statement forces client devs to check a delegator's lastClaimRound before calling either function because otherwise the functions will return 0. The functions can be updated in the following way to eliminate the need for that check:

Note: This example is for pendingStake(), but the logical flow can be applied to pendingFees() as well.

// Rest of function...

if (_endRound > currentRound) {
    // Highest round we can calculate up to is the current round
    _endRound = currentRound;
}

uint256 currentBondedAmount = del.bondedAmount;

if (_endRound == del.lastClaimRound) {
    // If the end round is equal to the last claim round then we can skip the calculations since
    // since the delegator has claimed earnings through the end round already
    return currentBondedAmount;
}

// Rest of function...
yondonfu commented 4 years ago

Closed by #365