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

Use next slot cache for payload attribute #12286

Merged
merged 17 commits into from
Apr 25, 2023

Conversation

terencechain
Copy link
Member

@terencechain terencechain commented Apr 15, 2023

This PR changes

  • Use next slot cache for getPayloadAttribute to avoid duplicated ProcessSlotsIfPossible if necessary. This becomes relevant for epoch boundary blocks

@terencechain terencechain requested a review from a team as a code owner April 15, 2023 03:45
@terencechain terencechain requested review from kasey, rkapka and nisdas April 15, 2023 03:45
@@ -265,7 +265,8 @@ func (s *Service) getPayloadAttribute(ctx context.Context, st state.BeaconState,

// Get previous randao.
st = st.Copy()
st, err := transition.ProcessSlotsIfPossible(ctx, st, slot)
headRoot := s.headRoot()
st, err := transition.ProcessSlotsUsingNextSlotCache(ctx, st, headRoot[:], slot)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a functional difference between ProcessSlotsIfPossible and using NSC: the former does not error out if the requested slot is higher than the current slot. I've seen this fail on tests and I wonder if this won't fail on runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. The easiest way to solve this is to add process slots only if it's higher within ProcessSlotsUsingNextSlotCache. It seems no harm to do that but curious what you think

@@ -14,7 +14,7 @@ import (
)

type nextSlotCache struct {
sync.Mutex
sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change here? Is there a possibility of a deadlock? we should very rarely call getPayloadAttributes right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No dead lock but curious why we don't use RWMutex to begin with? It seems inevitable we move to that direction

@terencechain terencechain self-assigned this Apr 19, 2023
@terencechain terencechain added the Ready For Review A pull request ready for code review label Apr 19, 2023
potuz
potuz previously approved these changes Apr 20, 2023
Copy link
Contributor

@potuz potuz left a comment

Choose a reason for hiding this comment

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

Approving with a comment, should we error out if slot < st.Slot()?

@terencechain terencechain removed Ready For Review A pull request ready for code review OK to merge labels Apr 22, 2023
@terencechain terencechain marked this pull request as draft April 22, 2023 12:56
@terencechain terencechain marked this pull request as ready for review April 24, 2023 16:54
Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

Code seems good. I didn't run it locally

@terencechain terencechain merged commit 73fea51 into develop Apr 25, 2023
@delete-merged-branch delete-merged-branch bot deleted the use-next-slot-payload-attribute branch April 25, 2023 23:13
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