Sidecar KZG Proofs storage#10137
Conversation
There was a problem hiding this comment.
Bug: Orphaned Proofs Bloat Database
The pruneDataColumnSidecars method removes individual data column sidecars but fails to remove the corresponding KZG proofs stored in dataColumnSidecarsProofsBySlot. Since proofs are keyed by slot and stored separately, they should be deleted via updater.removeDataColumnSidecarsProofs(slot) when pruning sidecars for each slot. This causes proofs to accumulate indefinitely in the database even after their sidecars are pruned, creating a memory leak.
storage/src/main/java/tech/pegasys/teku/storage/server/kvstore/KvStoreDatabase.java#L1211-L1245
|
cursotbot is correct on the comment, but it will be a part of another PR together with other pruning changes. This one contains only database API, no logic |
| .sszDeserialize(serializedSidecar); | ||
| } | ||
|
|
||
| public List<List<KZGProof>> deserializeDataColumnSidecarsProofs(final Bytes serializedProofs) { |
There was a problem hiding this comment.
I think we normally have these DB-specific serializations\deserializations here: tech.pegasys.teku.storage.server.kvstore.serialization.
Is there a reason we can't push these down there?
There was a problem hiding this comment.
we also already have toSSZBytes fromSSZBytes serialization\deserialization functions in KZGProof itself. Maybe we could reuse them? (we will have a concatenation of SSZs instead of one SSZ with concatenated bytes, maybe it is equivalent)
There was a problem hiding this comment.
KzgProof's ssz functions looks junky, removed it.
I cannot remember what was my logic to avoid KVSerializer, tried it, looks ok: 7f1c519
So it's now single number only in serialization and all proofs.
| Bytes bytes = | ||
| SSZ.encode( | ||
| writer -> { | ||
| final int blobSize = value.isEmpty() ? 0 : value.getFirst().size(); |
There was a problem hiding this comment.
Bug: Fixed Size Assumption Corrupts Data
The serializer assumes all inner lists have the same size by using value.getFirst().size() as the blob size for all columns. If the input contains inner lists of varying sizes, deserialization will incorrectly regroup the proofs, causing data corruption. The deserializer splits all proofs using this single blobSize value, which fails when inner lists have different lengths.
There was a problem hiding this comment.
it's equal size by the spec
| blobSize, output.size())); | ||
| } | ||
| return output; | ||
| }); |
There was a problem hiding this comment.
Bug: Empty columns corrupt data on round-trip.
The serializer cannot correctly handle empty inner lists. When serializing [[]] (one column with zero proofs), it writes blobSize=0 and no proof bytes. During deserialization, this produces [] (zero columns) instead of [[]] (one empty column). The serializer loses information about the number of columns when any column is empty, causing data corruption on round-trip.
There was a problem hiding this comment.
not a case for real data
PR Description
Part of #10132, implementing #10095
Implementing only database part: storing, reading, removing KZG Proofs for DataColumnSidecars.
Main concerns:
64*4=256 bytesper slot, which could be shrinked to a single int value, 4 bytes. But both are tiny numbers on the whole scale, say, with 14 target blobs supernode:Anyway I'm happy to apply any solution which looks more elegant than this one.
Fixed Issue(s)
Documentation
doc-change-requiredlabel to this PR if updates are required.Changelog
Note
Adds DB column, serialization, and APIs to store/retrieve/remove KZG proofs for
DataColumnSidecars, with query exposure in storage channels and client.DATA_COLUMN_SIDECARS_PROOFS_BY_SLOTto schemas (V6SchemaCombined*,Schema*adapters).DataColumnSidecarsProofsSerializerand register inKvStoreSerializer.KvStoreCombinedDao,V4FinalizedKvStoreDao, adapters) with methods to add/remove/getList<List<KZGProof>>and fetch last slot.KvStoreDatabaseandDatabaseinterfaces to read/write proofs.getDataColumnSidecarsProofs(UInt64 slot)toStorageQueryChanneland implement inChainStorage,ThrottlingStorageQueryChannel,CombinedStorageChannelSplitter.getDataColumnSidecarProofs(UInt64 slot)inCombinedChainDataClient.KZGProof: addSIZEconstant, remove SSZ helpers; minor refactor.Written by Cursor Bugbot for commit 6e805d0. This will update automatically on new commits. Configure here.