-
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
Can retrieve cached initial sync block and db block #10568
Conversation
@@ -182,9 +182,14 @@ func (s *Service) notifyEngineIfChangedHead(ctx context.Context, newHeadRoot [32 | |||
log.WithError(errNilFinalizedInStore).Error("could not get finalized checkpoint") | |||
return | |||
} | |||
newHeadBlock, err := s.cfg.BeaconDB.Block(ctx, newHeadRoot) | |||
if err := s.cfg.BeaconDB.SaveBlocks(ctx, s.getInitSyncBlocks()); err != nil { |
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 we pass in 0 blocks, do we still write to the db ? I think SaveBlocks
should exit early if there is nothing to write.
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 think I will just remove it. This was from the previous solution. Now getBlock
should take care of it. Doesn't seem right to Save cached blocks here
defer s.initSyncBlocksLock.RUnlock() | ||
b := s.initSyncBlocks[r] | ||
return b | ||
|
||
// Check cache first because it's faster. | ||
b, ok := s.initSyncBlocks[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.
I think you can release the read lock immediately after the map read. In the case that there is a cache miss, you are holding the read lock for longer than necessary
@@ -438,7 +438,7 @@ func TestVerifyBeaconBlock_NoBlock(t *testing.T) { | |||
require.NoError(t, err) | |||
|
|||
d := util.HydrateAttestationData(ðpb.AttestationData{}) | |||
assert.ErrorContains(t, "signed beacon block can't be nil", service.verifyBeaconBlock(ctx, d)) | |||
assert.ErrorContains(t, "block not found in cache or db", service.verifyBeaconBlock(ctx, d)) |
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.
Use errBlockNotFoundInCacheOrDB
here
…m into save-cached-init-blks
Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
…m into save-cached-init-blks
…m into save-cached-init-blks
* Save cached initial sync blocks before getting head block * Add better abstraction to get block * Move unlock read to a better location * Feedbacks * Add head changed logging * Harder hasBlock requirement * Update beacon-chain/blockchain/service.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Update receive_attestation.go * Don't process head if the block is unknown * Use a helper method * Fix test Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> (cherry picked from commit b7a82d0)
This fixes #10570
To improve on previous behavior, we adopted a new
getBlock
method which retrieves blocks in the initial syncing cacher DB and returns an error not found if the block is nil. We applygetBlock
to more than one occurrence which adopted similar patterns. This is a much nicer clean-up than before.Ideally, the initial syncing cache really should belong inside DB package but that's a much more heavily refactor and will induce more risk. I'm incline to push this to the later