-
Notifications
You must be signed in to change notification settings - Fork 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 headblock for prunePostBlockOperationPools, remove duplicate markInclusionBLStoExecutionChange calls #12085
Changes from 15 commits
27c8bc7
0e04895
8d08dce
34b9b61
c20c641
63f95cc
90bf88e
5b5823e
3235997
ab353ca
362f353
10058a3
2d2545c
f838b31
30cf37c
904944b
4cbb316
ad05c42
1ac08f8
ef5da67
7a5818a
38ecfee
52cb064
7c7b7ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package blockchain | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
@@ -48,6 +49,9 @@ func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySig | |
|
||
s.cfg.ForkChoiceStore.Lock() | ||
defer s.cfg.ForkChoiceStore.Unlock() | ||
// Checks if the current blockRoot ( which is also the head root) is new. | ||
// This check must come before forkchoiceUpdateWithExecution because it saves the new head. | ||
isNewHead := s.isNewHead(blockRoot) | ||
|
||
// Apply state transition on the new block. | ||
if err := s.onBlock(ctx, blockCopy, blockRoot); err != nil { | ||
|
@@ -56,9 +60,11 @@ func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySig | |
return err | ||
} | ||
|
||
// Handle post block operations such as attestations and exits. | ||
if err := s.handlePostBlockOperations(blockCopy.Block()); err != nil { | ||
return err | ||
if isNewHead { | ||
// Handle post block operations such as pruning exits and bls messages. | ||
if err := s.prunePostBlockOperationPools(ctx, blockRoot); err != nil { | ||
log.WithError(err).Error("Could not prune canonical objects from pool ") | ||
} | ||
} | ||
|
||
// Have we been finalizing? Should we start saving hot states to db? | ||
|
@@ -157,29 +163,42 @@ func (s *Service) ReceiveAttesterSlashing(ctx context.Context, slashing *ethpb.A | |
s.InsertSlashingsToForkChoiceStore(ctx, []*ethpb.AttesterSlashing{slashing}) | ||
} | ||
|
||
func (s *Service) handlePostBlockOperations(b interfaces.ReadOnlyBeaconBlock) error { | ||
// prunePostBlockOperationPools only runs on new head otherwise should return a nil. | ||
func (s *Service) prunePostBlockOperationPools(ctx context.Context, root [32]byte) error { | ||
headRoot, err := s.HeadRoot(ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there will be a dead lock. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought what potuz mentioned here #12085 (comment) was to use this lock instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok. |
||
if err != nil { | ||
return err | ||
} | ||
if !bytes.Equal(headRoot, root[:]) { | ||
return nil | ||
} | ||
// uses the newly saved block from forkchoiceUpdateWithExecution | ||
headBlock, err := s.HeadBlock(ctx) | ||
if err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just pass the block as part of the argument? We can save a block copy |
||
} | ||
// Mark block exits as seen so we don't include same ones in future blocks. | ||
for _, e := range b.Body().VoluntaryExits() { | ||
for _, e := range headBlock.Block().Body().VoluntaryExits() { | ||
s.cfg.ExitPool.MarkIncluded(e) | ||
} | ||
|
||
// Mark block BLS changes as seen so we don't include same ones in future blocks. | ||
if err := s.handleBlockBLSToExecChanges(b); err != nil { | ||
if err := s.markIncludedBlockBLSToExecChanges(headBlock.Block()); err != nil { | ||
return errors.Wrap(err, "could not process BLSToExecutionChanges") | ||
} | ||
|
||
// Mark attester slashings as seen so we don't include same ones in future blocks. | ||
for _, as := range b.Body().AttesterSlashings() { | ||
for _, as := range headBlock.Block().Body().AttesterSlashings() { | ||
s.cfg.SlashingPool.MarkIncludedAttesterSlashing(as) | ||
} | ||
return nil | ||
} | ||
|
||
func (s *Service) handleBlockBLSToExecChanges(blk interfaces.ReadOnlyBeaconBlock) error { | ||
if blk.Version() < version.Capella { | ||
func (s *Service) markIncludedBlockBLSToExecChanges(headBlock interfaces.ReadOnlyBeaconBlock) error { | ||
if headBlock.Version() < version.Capella { | ||
return nil | ||
} | ||
changes, err := blk.Body().BLSToExecutionChanges() | ||
changes, err := headBlock.Body().BLSToExecutionChanges() | ||
if err != nil { | ||
return errors.Wrap(err, "could not get BLSToExecutionChanges") | ||
} | ||
|
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.
Why do this here versus next to the usage?
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.
I need to get is New Head before forkchoiceUpdateWithExecution saves the head which happens inside the onblock. otherwise it's not new anymore.
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.
This doesn't work either: an incoming block will always have
isNewHead==true
here. You need to save the headroot here and then after the call toonBlock
check the the new head.