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
Isolate forkchoice to blockchain package #12174
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package blockchain | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state" | ||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives" | ||
ethpbv1 "github.com/prysmaticlabs/prysm/v4/proto/eth/v1" | ||
) | ||
|
||
// SetGenesisTime sets the genesis time of beacon chain. | ||
func (s *Service) SetGenesisTime(t time.Time) { | ||
s.genesisTime = t | ||
} | ||
|
||
// CachedHeadRoot returns the corresponding value from Forkchoice | ||
func (s *Service) CachedHeadRoot() [32]byte { | ||
s.cfg.ForkChoiceStore.RLock() | ||
defer s.cfg.ForkChoiceStore.RUnlock() | ||
return s.cfg.ForkChoiceStore.CachedHeadRoot() | ||
} | ||
|
||
// GetProposerHead returns the corresponding value from forkchoice | ||
func (s *Service) GetProposerHead() [32]byte { | ||
s.cfg.ForkChoiceStore.RLock() | ||
defer s.cfg.ForkChoiceStore.RUnlock() | ||
return s.cfg.ForkChoiceStore.GetProposerHead() | ||
} | ||
|
||
// SetForkChoiceGenesisTime sets the genesis time in Forkchoice | ||
func (s *Service) SetForkChoiceGenesisTime(timestamp uint64) { | ||
s.cfg.ForkChoiceStore.Lock() | ||
defer s.cfg.ForkChoiceStore.Unlock() | ||
s.cfg.ForkChoiceStore.SetGenesisTime(timestamp) | ||
} | ||
|
||
// HighestReceivedBlockSlot returns the corresponding value from forkchoice | ||
func (s *Service) HighestReceivedBlockSlot() primitives.Slot { | ||
s.cfg.ForkChoiceStore.RLock() | ||
defer s.cfg.ForkChoiceStore.RUnlock() | ||
return s.cfg.ForkChoiceStore.HighestReceivedBlockSlot() | ||
} | ||
|
||
// ReceivedBlocksLastEpoch returns the corresponding value from forkchoice | ||
func (s *Service) ReceivedBlocksLastEpoch() (uint64, error) { | ||
s.cfg.ForkChoiceStore.RLock() | ||
defer s.cfg.ForkChoiceStore.RUnlock() | ||
return s.cfg.ForkChoiceStore.ReceivedBlocksLastEpoch() | ||
} | ||
|
||
// InsertNode is a wrapper for node insertion which is self locked | ||
func (s *Service) InsertNode(ctx context.Context, st state.BeaconState, root [32]byte) error { | ||
s.cfg.ForkChoiceStore.Lock() | ||
defer s.cfg.ForkChoiceStore.Unlock() | ||
return s.cfg.ForkChoiceStore.InsertNode(ctx, st, root) | ||
} | ||
|
||
// ForkChoiceDump returns the corresponding value from forkchoice | ||
func (s *Service) ForkChoiceDump(ctx context.Context) (*ethpbv1.ForkChoiceDump, error) { | ||
s.cfg.ForkChoiceStore.RLock() | ||
defer s.cfg.ForkChoiceStore.RUnlock() | ||
return s.cfg.ForkChoiceStore.ForkChoiceDump(ctx) | ||
} | ||
|
||
// NewSlot returns the corresponding value from forkchoice | ||
func (s *Service) NewSlot(ctx context.Context, slot primitives.Slot) error { | ||
s.cfg.ForkChoiceStore.Lock() | ||
defer s.cfg.ForkChoiceStore.Unlock() | ||
return s.cfg.ForkChoiceStore.NewSlot(ctx, slot) | ||
} | ||
|
||
// ProposerBoost wraps the corresponding method from forkchoice | ||
func (s *Service) ProposerBoost() [32]byte { | ||
s.cfg.ForkChoiceStore.Lock() | ||
defer s.cfg.ForkChoiceStore.Unlock() | ||
return s.cfg.ForkChoiceStore.ProposerBoost() | ||
} | ||
|
||
// ChainHeads returns all possible chain heads (leaves of fork choice tree). | ||
// Heads roots and heads slots are returned. | ||
func (s *Service) ChainHeads() ([][32]byte, []primitives.Slot) { | ||
s.cfg.ForkChoiceStore.RLock() | ||
defer s.cfg.ForkChoiceStore.RUnlock() | ||
return s.cfg.ForkChoiceStore.Tips() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really a forkchoice method ? Seems unrelated