From e231d88ca07a601d0f9dc95096ec56d45384dee1 Mon Sep 17 00:00:00 2001 From: Potuz Date: Thu, 19 Oct 2023 12:33:19 -0300 Subject: [PATCH] Remove sidecars with invalid proofs (#13070) * Remove sidecars with invalid proofs * unhandled error * Add missing delete --- beacon-chain/blockchain/execution_engine.go | 2 +- beacon-chain/blockchain/process_block.go | 8 ++++++++ beacon-chain/db/iface/interface.go | 2 +- beacon-chain/db/kv/blob.go | 2 +- beacon-chain/db/kv/blob_test.go | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/beacon-chain/blockchain/execution_engine.go b/beacon-chain/blockchain/execution_engine.go index 355c66fd9..73ab17dd0 100644 --- a/beacon-chain/blockchain/execution_engine.go +++ b/beacon-chain/blockchain/execution_engine.go @@ -390,7 +390,7 @@ func (s *Service) removeInvalidBlockAndState(ctx context.Context, blkRoots [][32 return err } // No op if the sidecar does not exist. - if err := s.cfg.BeaconDB.DeleteBlobSidecar(ctx, root); err != nil { + if err := s.cfg.BeaconDB.DeleteBlobSidecars(ctx, root); err != nil { return err } } diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index a713a0b50..0ef06bc4d 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -564,6 +564,10 @@ func (s *Service) isDataAvailable(ctx context.Context, root [32]byte, signed int if len(sidecars) >= expected { s.blobNotifiers.delete(root) if err := kzg.IsDataAvailable(kzgCommitments, sidecars); err != nil { + log.WithField("root", fmt.Sprintf("%#x", root)).Warn("removing blob sidecars with invalid proofs") + if err2 := s.cfg.BeaconDB.DeleteBlobSidecars(ctx, root); err2 != nil { + log.WithError(err2).Error("could not delete sidecars") + } return err } logBlobSidecar(sidecars, t) @@ -594,6 +598,10 @@ func (s *Service) isDataAvailable(ctx context.Context, root [32]byte, signed int return errors.Wrap(err, "could not get blob sidecars") } if err := kzg.IsDataAvailable(kzgCommitments, sidecars); err != nil { + log.WithField("root", fmt.Sprintf("%#x", root)).Warn("removing blob sidecars with invalid proofs") + if err2 := s.cfg.BeaconDB.DeleteBlobSidecars(ctx, root); err2 != nil { + log.WithError(err2).Error("could not delete sidecars") + } return err } logBlobSidecar(sidecars, t) diff --git a/beacon-chain/db/iface/interface.go b/beacon-chain/db/iface/interface.go index 13df292fa..2180c23ab 100644 --- a/beacon-chain/db/iface/interface.go +++ b/beacon-chain/db/iface/interface.go @@ -96,7 +96,7 @@ type NoHeadAccessDatabase interface { // Blob operations. SaveBlobSidecar(ctx context.Context, sidecars []*ethpb.BlobSidecar) error - DeleteBlobSidecar(ctx context.Context, beaconBlockRoot [32]byte) error + DeleteBlobSidecars(ctx context.Context, beaconBlockRoot [32]byte) error CleanUpDirtyStates(ctx context.Context, slotsPerArchivedPoint primitives.Slot) error } diff --git a/beacon-chain/db/kv/blob.go b/beacon-chain/db/kv/blob.go index 278a52e23..3ceb0c1c5 100644 --- a/beacon-chain/db/kv/blob.go +++ b/beacon-chain/db/kv/blob.go @@ -261,7 +261,7 @@ func (s *Store) BlobSidecarsBySlot(ctx context.Context, slot types.Slot, indices } // DeleteBlobSidecar returns true if the blobs are in the db. -func (s *Store) DeleteBlobSidecar(ctx context.Context, beaconBlockRoot [32]byte) error { +func (s *Store) DeleteBlobSidecars(ctx context.Context, beaconBlockRoot [32]byte) error { _, span := trace.StartSpan(ctx, "BeaconDB.DeleteBlobSidecar") defer span.End() return s.db.Update(func(tx *bolt.Tx) error { diff --git a/beacon-chain/db/kv/blob_test.go b/beacon-chain/db/kv/blob_test.go index 0afc2c66b..a6705b09b 100644 --- a/beacon-chain/db/kv/blob_test.go +++ b/beacon-chain/db/kv/blob_test.go @@ -179,7 +179,7 @@ func TestStore_BlobSidecars(t *testing.T) { got, err := db.BlobSidecarsByRoot(ctx, bytesutil.ToBytes32(scs[0].BlockRoot)) require.NoError(t, err) require.NoError(t, equalBlobSlices(scs, got)) - require.NoError(t, db.DeleteBlobSidecar(ctx, bytesutil.ToBytes32(scs[0].BlockRoot))) + require.NoError(t, db.DeleteBlobSidecars(ctx, bytesutil.ToBytes32(scs[0].BlockRoot))) got, err = db.BlobSidecarsByRoot(ctx, bytesutil.ToBytes32(scs[0].BlockRoot)) require.ErrorIs(t, ErrNotFound, err) require.Equal(t, 0, len(got))