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

refactor next slot cache #12233

Merged
merged 6 commits into from
Apr 4, 2023
Merged

refactor next slot cache #12233

merged 6 commits into from
Apr 4, 2023

Conversation

potuz
Copy link
Contributor

@potuz potuz commented Apr 3, 2023

This PR refactors the next slot cache to keep track of two alternative states. This makes the cache safe under skipped slots and 1-slot reorgs, including across epoch boundaries. Design is in https://www.notion.so/arbitrum/Next-Slot-Cache-2-0-301e3788c1b248e6a587bd3505c4034a

This also fixes some bugs making the cache not thread safe (by copying the root slice instead of keeping the slice parameter in the cache).

@potuz potuz added Bug Something isn't working Ready For Review A pull request ready for code review labels Apr 3, 2023
@potuz potuz requested a review from a team as a code owner April 3, 2023 18:37
@potuz potuz requested review from rkapka, nisdas and james-prysm April 3, 2023 18:37
@@ -147,25 +147,15 @@ func ProcessSlotsUsingNextSlotCache(
ctx, span := trace.StartSpan(ctx, "core.state.ProcessSlotsUsingNextSlotCache")
defer span.End()

// Check whether the parent state has been advanced by 1 slot in next slot cache.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a very simple function that was overly commented making it less readable. I removed some useless variables and most comments.

s.headLock.RUnlock()
_, err = s.notifyForkchoiceUpdate(ctx, &notifyForkchoiceUpdateArg{
headState: headState,
headRoot: headRoot,
headBlock: headBlock.Block(),
})
return err
if err != nil {
log.WithError(err).Debug("could not perform late block tasks: failed to update forkchoice with engine")
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if these Debug verbosity error logs should have higher visibility

beacon-chain/core/transition/trailing_slot_state_cache.go Outdated Show resolved Hide resolved
Copy link
Member

@nisdas nisdas left a comment

Choose a reason for hiding this comment

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

How does this prevent updates to the cache for non-canonical blocks ? UpdateNextSlotCache is still called for all blocks processed

headRoot := s.headRoot()
headState := s.headState(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you switched the ordering from

  • state then root to root and then state ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no reason, was going to use the cached state as head state, but that ended up being too hard to do in one PR,

@potuz
Copy link
Contributor Author

potuz commented Apr 4, 2023

How does this prevent updates to the cache for non-canonical blocks ? UpdateNextSlotCache is still called for all blocks processed

I could prevent it, but decided that it's more useful to actually keep them, we may get reorgs that are non-canonical as soon as we insert them if we receive them near the 4 second boundary and they become canonical at 12 seconds. The likelyhood of this happening is higher than the likelihood of the previous state being needed advanced to another slot to pass an epoch transition, so I decided to keep them here.

@prylabs-bulldozer prylabs-bulldozer bot merged commit fb65421 into develop Apr 4, 2023
@delete-merged-branch delete-merged-branch bot deleted the next_slot_cache branch April 4, 2023 16:04
@nisdas nisdas mentioned this pull request Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants