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 Block Interface Across Prysm #8918

Merged
merged 53 commits into from
May 26, 2021
Merged

Use Block Interface Across Prysm #8918

merged 53 commits into from
May 26, 2021

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented May 21, 2021

What type of PR is this?

Hard Fork Cleanup

What does this PR do? Why is it needed?

  • Replaces our protobuf block object with a block interface. This is to allow for easier representation of blocks for future
    hardforks
  • Add in new block interface.
  • Fix all tests which broke due to this change.
  • Use block interface as much as possible across prysm.

Which issues(s) does this PR fix?

Part of #8638

Other notes for review

@nisdas nisdas marked this pull request as ready for review May 25, 2021 16:30
@nisdas nisdas requested a review from a team as a code owner May 25, 2021 16:30
@nisdas nisdas requested a review from farazdagi May 25, 2021 16:30
@@ -104,7 +103,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
if err != nil {
return err
}
if newHeadBlock == nil || newHeadBlock.Block == nil {
if newHeadBlock == nil || newHeadBlock.IsNil() || newHeadBlock.Block().IsNil() {
Copy link
Contributor

@rkapka rkapka May 26, 2021

Choose a reason for hiding this comment

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

How about this change?

func (w WrappedSignedBeaconBlock) IsNil() bool {
	return w.b == nil || w.Block() == nil || w.Block().IsNil()
}

It allows to write a single IsNil() check, and I am afraid most of the time the second check will be forgotten. You also never verify if w.Block() == nil in this PR (I don't either in my suggestions because this was an afterthought) and you already missed several w.Block().IsNil() checks. I'm sure this will happen more often. The downside is that we couple both checks together. Would we ever not care if the underlying beacon block is nil or not though?

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal was to not add in additional nil block checks unless that particular function requires it. I have tried to strictly mimick existing behaviour and minimize any additional logic changes added into an already large PR. I just wanted to replace what were existing nil checks for a block struct with an interface. Adding in an inner block check would differ from what is the current behaviour (if signedBlock == nil) . We can add it in a follow up PR in that case, it would only be a one line change for both the SignedBeaconBlock and BeaconBlock.

@@ -99,14 +99,14 @@ func (s *Service) verifyBeaconBlock(ctx context.Context, data *ethpb.Attestation
}
// If the block does not exist in db, check again if block exists in initial sync block cache.
// This could happen as the node first syncs to head.
if b == nil && s.hasInitSyncBlock(r) {
if (b == nil || b.IsNil()) && s.hasInitSyncBlock(r) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (b == nil || b.IsNil()) && s.hasInitSyncBlock(r) {
if (b == nil || b.IsNil() || b.Block().IsNil()) && s.hasInitSyncBlock(r) {

@@ -119,8 +120,8 @@ func (s *Service) Start() {
if err != nil {
log.Fatalf("Could not fetch finalized cp: %v", err)
}
if genesisBlock != nil {
r, err = genesisBlock.Block.HashTreeRoot()
if genesisBlock != nil && !genesisBlock.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if genesisBlock != nil && !genesisBlock.IsNil() {
if genesisBlock != nil && !genesisBlock.IsNil() && !genesisBlock.Block().IsNil() {

@@ -337,10 +338,10 @@ func (s *Service) saveGenesisData(ctx context.Context, genesisState iface.Beacon
return errors.Wrap(err, "could not save genesis data")
}
genesisBlk, err := s.cfg.BeaconDB.GenesisBlock(ctx)
if err != nil || genesisBlk == nil {
if err != nil || genesisBlk == nil || genesisBlk.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if err != nil || genesisBlk == nil || genesisBlk.IsNil() {
if err != nil || genesisBlk == nil || genesisBlk.IsNil() || genesisBlk.Block().IsNil() {

@@ -380,10 +381,10 @@ func (s *Service) initializeChainInfo(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "could not get genesis block from db")
}
if genesisBlock == nil {
if genesisBlock == nil || genesisBlock.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if genesisBlock == nil || genesisBlock.IsNil() {
if genesisBlock == nil || genesisBlock.IsNil() || genesisBlock.Block().IsNil() {

@@ -248,7 +248,7 @@ func (s *State) lastAncestorState(ctx context.Context, root [32]byte) (iface.Bea
if err != nil {
return nil, err
}
if b == nil {
if b == nil || b.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if b == nil || b.IsNil() {
if b == nil || b.IsNil() || b.Block().IsNil() {

@@ -289,7 +289,7 @@ func (s *State) lastAncestorState(ctx context.Context, root [32]byte) (iface.Bea
if err != nil {
return nil, err
}
if b == nil {
if b == nil || b.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if b == nil || b.IsNil() {
if b == nil || b.IsNil() || b.Block().IsNil() {

@@ -68,10 +69,10 @@ func (s *Service) beaconBlocksRootRPCHandler(ctx context.Context, msg interface{
s.writeErrorResponseToStream(responseCodeServerError, types.ErrGeneric.Error(), stream)
return err
}
if blk == nil {
if blk == nil || blk.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if blk == nil || blk.IsNil() {
if blk == nil || blk.IsNil() || blk.Block().IsNil() {

@@ -315,30 +315,30 @@ func (s *Service) validateStatusMessage(ctx context.Context, msg *pb.Status) err
if err != nil {
return p2ptypes.ErrGeneric
}
if blk == nil {
if blk == nil || blk.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if blk == nil || blk.IsNil() {
if blk == nil || blk.IsNil() || blk.Block().IsNil() {

childBlock, err := s.cfg.DB.FinalizedChildBlock(ctx, bytesutil.ToBytes32(msg.FinalizedRoot))
if err != nil {
return p2ptypes.ErrGeneric
}
// Is a valid finalized block if no
// other child blocks exist yet.
if childBlock == nil {
if childBlock == nil || childBlock.IsNil() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if childBlock == nil || childBlock.IsNil() {
if childBlock == nil || childBlock.IsNil() || childBlock.Block().IsNil() {

@codecov
Copy link

codecov bot commented May 26, 2021

Codecov Report

Merging #8918 (ff3b8a2) into develop (7b55213) will increase coverage by 0.00%.
The diff coverage is 58.72%.

@@           Coverage Diff            @@
##           develop    #8918   +/-   ##
========================================
  Coverage    60.91%   60.92%           
========================================
  Files          529      530    +1     
  Lines        37419    37488   +69     
========================================
+ Hits         22793    22838   +45     
- Misses       11364    11376   +12     
- Partials      3262     3274   +12     

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