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

feat: implement getStateRandao #6072

Merged
merged 10 commits into from
Nov 4, 2023

Conversation

scorbajio
Copy link
Contributor

Motivation

See #5701.

Description

The goal of this PR is to implement the get-state-randao api.

@scorbajio scorbajio requested a review from a team as a code owner October 30, 2023 00:37
@CLAassistant
Copy link

CLAassistant commented Oct 30, 2023

CLA assistant check
All committers have signed the CLA.

@scorbajio scorbajio changed the title Implement getStateRandao [WIP] Implement getStateRandao Oct 30, 2023
@scorbajio scorbajio marked this pull request as draft October 30, 2023 00:38
@scorbajio scorbajio changed the title [WIP] Implement getStateRandao Implement getStateRandao Oct 30, 2023
@dapplion
Copy link
Contributor

dapplion commented Nov 1, 2023

@scorbajio thank you for your interest contributing! Please note that opening a PR and pushing commits triggers notifications to the entire team. I would recommend:

  • close this PR while you are developing it
  • if you have questions please ask in our discord at the #lodestar-general channel, or post the question in the issue Implement get state randao API #5701, we'll answer gladly!
  • once your PR is functionally complete and passes tests, re-open the PR as ready to review

@nflaig
Copy link
Member

nflaig commented Nov 1, 2023

@dapplion I have to push back on this

if you have questions please ask in our discord at the #lodestar-general channel

While I think discord is great for many things like general questions and technical help, I don't think it is a great tool to collaborate and give code related feedback. It is also good to have all the discussion in one place, which I think a PR is perfect place for it, it also has resolvable threads per topic, and allows directly comment on the code which provides much more clarify.

once your PR is functionally complete and passes tests, re-open the PR as ready to review

I agree that it doesn't make sense to open a PR that has little to no changes that should be implemented but this is definitely not the case here. It good to open a PR asap in my opinion especially as a new contributor to get feedback on the direction of the changes and not waste time on things that wouldn't even work in the end. That's why draft exists and a PR is a great collaboration tool we should use as much as possible.

Please note that opening a PR and pushing commits triggers notifications to the entire team

That's not a good reason why a PR should not be opened, there is always the option to unsubscribe, and that's it. We also had PRs open for weeks (or even months) and I think it is a good thing, it especially for new contributors to follow the work of others. Much better learning experience than just seeing the end result.

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this @scorbajio! Some initial feedback / thoughts

packages/api/src/beacon/routes/beacon/state.ts Outdated Show resolved Hide resolved
packages/beacon-node/src/api/impl/beacon/state/index.ts Outdated Show resolved Hide resolved
packages/beacon-node/src/api/impl/beacon/state/index.ts Outdated Show resolved Hide resolved
packages/beacon-node/src/api/impl/beacon/state/index.ts Outdated Show resolved Hide resolved
packages/beacon-node/src/api/impl/beacon/state/index.ts Outdated Show resolved Hide resolved
packages/beacon-node/src/api/impl/beacon/state/index.ts Outdated Show resolved Hide resolved
Comment on lines 155 to 163
if (usedEpoch > stateEpoch) {
return ret;
} else if (
usedEpoch < stateEpoch &&
Math.abs(stateEpoch - epochsPerHistoricalVector) > 0 &&
Math.abs(stateEpoch - epochsPerHistoricalVector) >= usedEpoch
) {
return ret;
}
Copy link
Member

@nflaig nflaig Nov 1, 2023

Choose a reason for hiding this comment

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

Not sure about this part, I think we should follow similar implementation as Lighthouse, seems simple and straight forward, see PR diff

As per spec randao.yaml:

  • 400 for invalid state id or epoch, mostly handled by json schema already (needs to be double checked)
  • 400 if epoch is out of range, see spec note
  • 404 if state not found

You can also check with other routes that load a state + have epoch as optional param for additional examples

Copy link
Contributor Author

@scorbajio scorbajio Nov 3, 2023

Choose a reason for hiding this comment

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

I was using teku's implementation as a reference. After taking a look at lighthouse, it seems like they do range checking in a more simple way in a separate get-index helper, which is what I used to rework the range-checking logic.

@nflaig nflaig changed the title Implement getStateRandao feat: implement getStateRandao Nov 1, 2023
@nflaig nflaig marked this pull request as ready for review November 4, 2023 08:41
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the updates @scorbajio

Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

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

lgtm

@g11tech g11tech enabled auto-merge (squash) November 4, 2023 08:56
@g11tech g11tech merged commit 5ff90ca into ChainSafe:unstable Nov 4, 2023
15 checks passed
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.12.0 🎉

@scorbajio scorbajio deleted the scorbajio/getStateRandao branch November 10, 2023 21:29
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.

6 participants