-
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
db: fix save blob sidecar using wrong prefix #12849
Conversation
@@ -54,7 +54,7 @@ func (s *Store) SaveBlobSidecar(ctx context.Context, scs []*ethpb.BlobSidecar) e | |||
// If there is no element stored at blob.slot % MAX_SLOTS_TO_PERSIST_BLOBS, then we simply | |||
// store the blob by key and exit early. | |||
if len(replacingKey) != 0 { | |||
slotBytes := replacingKey[:8] | |||
slotBytes := replacingKey[8:16] |
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.
is there a comment that can be added to direct readers on this
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.
@james-prysm it's in the godoc for this method.
// 2. Compute key for blob as bytes(slot_to_rotating_buffer(blob.slot)) ++ bytes(blob.slot) ++ blob.block_root
Terence wants bytes(blob.slot)
here, which is the second quadword
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.
@james-prysm what do you think about this? #12855
Would that the PR make it easier to understand?
hi @terencechain, @saolyn and I were looking at this PR and felt the description and fix did not have enough context. A few questions we had coming it blind:
In terms of testing, we think the unit tests can be made a lot simpler. They should be more human-readable. For example, we should override the config to store 10 slots of blobs, and then do something like maxBlobTimeToLive := types.Slot(10)
for i := 0; i < maxBlobTimeToLive; i++ {
db.SaveBlob(generateBlobAtSlot(i))
}
// Then check a few things about the stored blobs..
// Then, override the first 3 blobs, check they were overwritten
// Override the whole thing, save at the boundaries This way, we can better audit for edge-cases |
@rauljordan @saolyn I'll answer them here
The rotating buffer is to handle blobs outside of the retention window ~4096 epochs. It enables a fast lookup without having to unmarshal the blob sidecar and check. It was motivated by your PR here :) terencechain#3
It's a slot that's higher than
Can add this
I believe there is already a unit test for this |
Background:
Bolt DB struggles with pruning, which has been evident during the development of the slasher. With the introduction of EIP-4844 in Prysm, there will be a significant amount of blob data. In the last design, we implemented a rotating buffer database schema for blobs. This schema will overwrite old data once the expiration period for blobs is reached, eliminating the need for pruning or deletion routines.
How It Works:
Saving blobs involves:
[0, maxSlots]
, wheremaxSlots = MAX_BLOB_EPOCHS * SLOTS_PER_EPOCH
bytes(slot_to_rotating_buffer(blob.slot)) + bytes(blob.slot) + blob.block_root
.This PR ensures efficient data storage and retrieval without frequent pruning, thus keeping the database size bounded.
Bug fix:
When checking for a pre-existing blob sidecar to override (ex: if blob sidecar slot is > 4096 epoch),
it is supposed to use
bytes(blob.slot)
, which is[8:16]
.The bug is it was using:
[:8]
, which isbytes(slot_to_rotating_buffer(blob.slot))