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

Fix: drand: calculation of round from Filecoin epochs #8606

Merged
merged 1 commit into from
May 25, 2022

Conversation

arajasek
Copy link
Contributor

@arajasek arajasek commented May 5, 2022

Related Issues

Resolves #2170

Proposed Changes

This PR was originally opened for the v14 upgrade, but descoped.

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • All commits have a clear commit message.
  • The PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, INTERFACE BREAKING CHANGE, CONSENSUS BREAKING, build, chore, ci, docs,perf, refactor, revert, style, test
    • area: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps
  • This PR has tests for new functionality or change in behaviour
  • If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or Discussion Tutorials.
  • CI is green

@arajasek arajasek requested a review from a team as a code owner May 5, 2022 16:26
@jennijuju jennijuju requested a review from Kubuxu May 6, 2022 05:08
@arajasek
Copy link
Contributor Author

Added test.

@arajasek arajasek changed the title Fix calculation of Drand round from Filecoin epochs Fix: drand: calculation of round from Filecoin epochs May 10, 2022
// we take the time from genesis divided by the periods in seconds, that
// gives us the number of periods since genesis. We also add +1 because
// round 1 starts at genesis time.
return uint64(math.Floor(float64(fromGenesis)/db.interval.Seconds())) + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel a bit uneasy using floats for this.
As you only need Floor it should be simple to do using pure ints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, simplifying this.

@Kubuxu
Copy link
Contributor

Kubuxu commented May 11, 2022

Hey, how does it work during the upgrade?
As I recall currently we track the previous randomness beacon and verify the new one based on the previous one. How does this continue to work during the upgrade?

@Kubuxu
Copy link
Contributor

Kubuxu commented May 11, 2022

Ahh, right in this upgrade we only add on one breacon. Ok, I can see how that can work.

@arajasek
Copy link
Contributor Author

Yeah, so what should happen is just that the first block after the upgrade kicks in should have 2 beacon entries (exactly as we have after a null tipset).

dround := (latestTs - db.drandGenTime) / uint64(db.interval.Seconds())
return dround
}

func (db *DrandBeacon) maxBeaconRoundV2(latestTs uint64) uint64 {
if latestTs < db.drandGenTime {
return 1
Copy link
Member

Choose a reason for hiding this comment

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

not 0?

Copy link
Member

Choose a reason for hiding this comment

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

When latestTs == db.drandGenTime, the round will be 1. I don't know if it matters, but it may make more sense to let the round be 0 before that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not super important for mainnet, but I think your argument makes sense. Changing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, looking at Drand code, round 0 seems to indicate a special value that says "give me the latest entry".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gonna leave as is, for now.

@arajasek arajasek merged commit 06279b5 into feat/nv16 May 25, 2022
@arajasek arajasek deleted the asr/fix-drand-round branch May 25, 2022 19:36
Copy link
Contributor

@Kubuxu Kubuxu left a comment

Choose a reason for hiding this comment

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

SGWM

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.

3 participants