-
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
GetBlock() - Simple optimisations #9541
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #9541 +/- ##
===========================================
- Coverage 62.34% 61.90% -0.44%
===========================================
Files 572 565 -7
Lines 45457 44750 -707
===========================================
- Hits 28339 27703 -636
+ Misses 12568 12555 -13
+ Partials 4550 4492 -58 |
|
||
eg.Go(func() error { | ||
// Pack ETH1 deposits which have not been included in the beacon chain. | ||
localDeposits, err := vs.deposits(ctx, head, eth1Data) |
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.
Shouldn't you use egctx here?
localDeposits, err := vs.deposits(ctx, head, eth1Data) | |
localDeposits, err := vs.deposits(egctx, head, eth1Data) |
|
||
eg.Go(func() error { | ||
// Pack aggregated attestations which have not been included in the beacon chain. | ||
localAtts, err := vs.packAttestations(ctx, head) |
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.
Here too
localAtts, err := vs.packAttestations(ctx, head) | |
localAtts, err := vs.packAttestations(egctx, head) |
// This is very likely to happen because BlockTimeByHeight returns the last block AT OR BEFORE the specified time. | ||
if lastBlockByEarliestValidTime.Time < earliestValidTime { | ||
lastBlockByEarliestValidTime.Number = big.NewInt(0).Add(lastBlockByEarliestValidTime.Number, big.NewInt(1)) | ||
if !featureconfig.Get().EnableGetBlockOptimizations { |
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 is this branch omitted when the flag is on?
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 branch seems to not do anything here.
lastBlockByEarliestValidTime
is never used anywhere inside the code.
I need a confirmation if my thinking is right.
WDYT @nisdas
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.
That is a bit more complicated, as that value was used for our inRangeVotes
method. This was removed previously when we had the voting bug and defaulted to independent voting compared to voting by majority. Do we ever expect to add the vote by majority feature back ? @prestonvanloon
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.
My 2 cents: Even if want to add the feature back sometime later. Let's remove unused code for now.
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.
Discussed offline, its better to just remove it now. Performing the extra BlockByTimeStamp call is expensive and can increase block proposal times needlessly.
dbpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" | ||
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" | ||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" |
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.
These are the same imports, please use only one
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.
Can we implement benchmarks on before and after? We should know how much this improves
Numbers from tracing instrumentation will be helpful too
@@ -230,16 +232,9 @@ func (vs *Server) buildPhase0BlockData(ctx context.Context, req *ethpb.BlockRequ | |||
return nil, fmt.Errorf("could not get ETH1 data: %v", err) | |||
} | |||
|
|||
// Pack ETH1 deposits which have not been included in the beacon chain. | |||
deposits, err := vs.deposits(ctx, head, eth1Data) | |||
deposits, atts, err := vs.depositAndPackAttestations(ctx, head, eth1Data) |
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.
it is a bit odd to group deposit and attestation packing into one method. But I do understand that it makes it cleaner when applying the flag.
@terencechain yeah we can do that. |
@terencechain On the second thought, i think it will be nice to run the instrumentation and monitor block proposal times, after we fix the rest of the fixes related to getBlock(). What say? |
That's fine with me. Let's wait to merge this until we can monitor block proposal time then Another method here (easier) is to run getblock benchmark test on both featureflag on/off |
Thats a nice idea. I will do this. |
Decided offline with @terencechain to keep this PR open until we fix other issues in GetBlock() |
This PR will be closed once all the tracking issues are closed. |
} | ||
// Increment the earliest block if the original block's time is before valid time. | ||
// This is very likely to happen because BlockTimeByHeight returns the last block AT OR BEFORE the specified time. | ||
if lastBlockByEarliestValidTime.Time < earliestValidTime { |
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 this value isnt being used anywhere you can remove it, no need to gate it behind the flag.
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.
Makes sense. Done.
@@ -278,6 +271,70 @@ func (vs *Server) ProposeBeaconBlock(ctx context.Context, req *ethpb.GenericSign | |||
return vs.proposeGenericBeaconBlock(ctx, blk) | |||
} | |||
|
|||
func (vs *Server) depositAndPackAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []*ethpb.Attestation, error) { |
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.
func (vs *Server) depositAndPackAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []*ethpb.Attestation, error) { | |
func (vs *Server) packDepositsAndAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []*ethpb.Attestation, error) { |
return deposits, atts, nil | ||
} | ||
|
||
func (vs *Server) optimizedDepositAndPackAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []*ethpb.Attestation, error) { |
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.
func (vs *Server) optimizedDepositAndPackAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []*ethpb.Attestation, error) { | |
func (vs *Server) optimizedPackDepositsAndAttestations(ctx context.Context, head state.BeaconState, eth1Data *ethpb.Eth1Data) ([]*ethpb.Deposit, []*ethpb.Attestation, error) { |
if err != nil { | ||
return status.Errorf(codes.Internal, "Could not get ETH1 deposits: %v", err) | ||
} | ||
// if the original context is cancelled, then cancel this routine toobazel run //:gazelle -- fix` |
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 the original context is cancelled, then cancel this routine toobazel run //:gazelle -- fix` | |
// if the original context is cancelled, then cancel this routine too |
@@ -551,7 +605,7 @@ func (vs *Server) deposits( | |||
if vs.MockEth1Votes || !vs.Eth1InfoFetcher.IsConnectedToETH1() { | |||
return []*ethpb.Deposit{}, nil | |||
} | |||
// Need to fetch if the deposits up to the state's latest eth 1 data matches | |||
// Need to fetch if the deposits up to the state's latest ethpb 1 data matches |
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.
// Need to fetch if the deposits up to the state's latest ethpb 1 data matches | |
// Need to fetch if the deposits up to the state's latest eth 1 data matches |
config/features/config.go
Outdated
@@ -50,6 +50,7 @@ type Flags struct { | |||
EnableOptimizedBalanceUpdate bool // EnableOptimizedBalanceUpdate uses an updated method of performing balance updates. | |||
EnableDoppelGanger bool // EnableDoppelGanger enables doppelganger protection on startup for the validator. | |||
EnableHistoricalSpaceRepresentation bool // EnableHistoricalSpaceRepresentation enables the saving of registry validators in separate buckets to save space | |||
EnableGetBlockOptimizations bool // EnableGetBlockOptimizations optimizes some elements of the GetBlock() function |
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.
EnableGetBlockOptimizations bool // EnableGetBlockOptimizations optimizes some elements of the GetBlock() function | |
EnableGetBlockOptimizations bool // EnableGetBlockOptimizations optimizes some elements of the GetBlock() function. |
Co-authored-by: Nishant Das <nishdas93@gmail.com>
What type of PR is this?
Optimisation
What does this PR do? Why is it needed?
During debugging of #8943, it was found that some of the operations done
during GetBlock() can be optimised further. This PR does the simple optimisations under a flag.
Which issues(s) does this PR fix?
Related to #8943
Other notes for review
The flag is --enable-get-block-optimizations, and it is disabled by default.