-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
@@ -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() { |
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.
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?
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.
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) { |
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.
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() { |
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.
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() { |
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.
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() { |
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.
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() { |
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.
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() { |
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.
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() { |
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.
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() { |
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.
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() { |
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.
if childBlock == nil || childBlock.IsNil() { | |
if childBlock == nil || childBlock.IsNil() || childBlock.Block().IsNil() { |
Co-authored-by: Radosław Kapka <rkapka@wp.pl>
Codecov Report
@@ 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 |
What type of PR is this?
Hard Fork Cleanup
What does this PR do? Why is it needed?
hardforks
Which issues(s) does this PR fix?
Part of #8638
Other notes for review