Merge pull request #3848 from emhane/empty_blobs_db

Don't write empty blobs to db
This commit is contained in:
realbigsean 2023-01-06 10:12:02 -05:00 committed by GitHub
commit 33ff84743d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 494 additions and 279 deletions

728
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -972,7 +972,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
Ok((
self.get_block(block_root).await?.map(Arc::new),
self.get_blobs(block_root).await?.map(Arc::new),
self.get_blobs(block_root).ok().flatten().map(Arc::new),
))
}
@ -1048,11 +1048,32 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// ## Errors
///
/// May return a database error.
pub async fn get_blobs(
pub fn get_blobs(
&self,
block_root: &Hash256,
) -> Result<Option<BlobsSidecar<T::EthSpec>>, Error> {
Ok(self.store.get_blobs(block_root)?)
match self.store.get_blobs(block_root)? {
Some(blobs) => Ok(Some(blobs)),
None => {
if let Ok(Some(block)) = self.get_blinded_block(block_root) {
let expected_kzg_commitments = block.message().body().blob_kzg_commitments()?;
if expected_kzg_commitments.len() > 0 {
Err(Error::DBInconsistent(format!(
"Expected kzg commitments but no blobs stored for block root {}",
block_root
)))
} else {
Ok(Some(BlobsSidecar::empty_from_parts(
*block_root,
block.slot(),
)))
}
} else {
Ok(None)
}
}
}
}
pub fn get_blinded_block(
@ -2945,9 +2966,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
ops.push(StoreOp::PutState(block.state_root(), &state));
if let Some(blobs) = blobs? {
//FIXME(sean) using this for debugging for now
info!(self.log, "Writing blobs to store"; "block_root" => ?block_root);
ops.push(StoreOp::PutBlobs(block_root, blobs));
if blobs.blobs.len() > 0 {
//FIXME(sean) using this for debugging for now
info!(self.log, "Writing blobs to store"; "block_root" => ?block_root);
ops.push(StoreOp::PutBlobs(block_root, blobs));
}
};
let txn_lock = self.store.hot_db.begin_rw_transaction();

View File

@ -658,20 +658,20 @@ impl<T: BeaconChainTypes> Worker<T> {
let send_response = true;
for root in block_roots {
match self.chain.store.get_blobs(&root) {
Ok(Some(blob)) => {
match self.chain.get_blobs(&root) {
Ok(Some(blobs)) => {
blobs_sent += 1;
self.send_network_message(NetworkMessage::SendResponse {
peer_id,
response: Response::BlobsByRange(Some(Arc::new(blob))),
response: Response::BlobsByRange(Some(Arc::new(blobs))),
id: request_id,
});
}
Ok(None) => {
error!(
self.log,
"Blob in the chain is not in the store";
"request_root" => ?root
"No blobs or block in the store for block root";
"block_root" => ?root
);
break;
}