Skip to content
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

eth: Fix active total stake calc in RewardWithHint #2029

Merged
merged 2 commits into from
Sep 13, 2021
Merged

Conversation

yondonfu
Copy link
Member

@yondonfu yondonfu commented Sep 12, 2021

What does this pull request do? Explain your changes. (required)

This PR fixes a bug in the total stake calculations used for hint generation in eth.client.Reward(). I've added in-line PR comments to explain the bug and the solutions used.

Specific updates (required)

See commit history.

How did you test each of these updates (required)

Tested manually using devtool.

Does this pull request close any open issues?

Fixes #2015

Checklist:

@Franck-UltimaRatio
Copy link

Thanks Yondon 👍

@@ -792,7 +794,7 @@ func (c *client) Reward() (*types.Transaction, error) {
return nil, errors.Wrapf(err, "unable to get transcoder pool max size")
}

hints := simulateTranscoderPoolUpdate(addr, reward.Add(reward, ep.TotalStake), transcoders, len(transcoders) == int(maxSize.Int64()))
hints := simulateTranscoderPoolUpdate(addr, reward.Add(reward, tr.DelegatedStake), transcoders, len(transcoders) == int(maxSize.Int64()))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, we used the TotalStake field on the earnings pool here. There were two problems with this:

  1. If the orchestratrator's LastActiveStakeUpdateRound is before the current round, then the TotalStake field would be 0 and empty hints would be returned which results in the increased gas usage described in eth: Fix active total stake calc in RewardWithHint #2029
  2. Even if the correct earnings pool was fetched, the TotalStake field on the earnings pool would reflect the orchestrator's active total stake which remains fixed throughout the current round. If the orchestrator receives delegation during the round, its active total stake would not change, but its total stake would change and its total stake is the value that should be used for simulateTranscoderPoolUpdate

Both 1 and 2 are resolved by using the DelegatedStake field on the Transcoder struct which accurately reflects the orchestrator's total stake at all points in the round.

if err != nil {
return nil, err
}

ep, err := c.GetTranscoderEarningsPoolForRound(c.accountManager.Account().Address, currentRound)
ep, err := c.GetTranscoderEarningsPoolForRound(addr, tr.LastActiveStakeUpdateRound)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, we always fetched the earnings pool for the current round. When LastActiveStakeUpdateRound is in the past, the TotalStake field of the earnings pool for the current round would be 0 and the total stake of the orchestrator would be stored in the earnings pool for LastActiveStakeUpdateRound. This is resolved by always fetching the earnings pool for LastActiveStakeUpdateRound here.

@yondonfu yondonfu marked this pull request as ready for review September 13, 2021 13:54
Copy link
Contributor

@jailuthra jailuthra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Increased Gas cost when calling reward via CLI with Master build 0.5.19-e9b81b25
3 participants