Skip to content

Commit

Permalink
fix(blobs): cleanup logging and node-api handling of blobs (#2486)
Browse files Browse the repository at this point in the history
Signed-off-by: Cal Bera <[email protected]>
Co-authored-by: Nidhi Singh <[email protected]>
Co-authored-by: Shota Ehrlich <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2025
1 parent 9af4d0d commit d90756b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
9 changes: 3 additions & 6 deletions beacon/blockchain/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,19 @@ func (s *Service) VerifyIncomingBlobSidecars(
blkHeader *ctypes.BeaconBlockHeader,
kzgCommitments eip4844.KZGCommitments[common.ExecutionHash],
) error {
s.logger.Info("Received incoming blob sidecars")

// Verify the blobs and ensure they match the local state.
err := s.blobProcessor.VerifySidecars(ctx, sidecars, blkHeader, kzgCommitments)
if err != nil {
s.logger.Error(
"rejecting incoming blob sidecars",
"reason", err,
"Blob sidecars verification failed - rejecting incoming blob sidecars",
"reason", err, "slot", blkHeader.GetSlot(),
)
return err
}

s.logger.Info(
"Blob sidecars verification succeeded - accepting incoming blob sidecars",
"num_blobs",
len(sidecars),
"num_blobs", len(sidecars), "slot", blkHeader.GetSlot(),
)
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions node-api/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ func (b *Backend) stateFromSlotRaw(slot math.Slot) (*statedb.StateDB, math.Slot,
}
st = b.sb.StateFromContext(queryCtx)

// If using height 0 for the query context, make sure to return the latest
// slot.
// If using height 0 for the query context, make sure to return the latest slot.
if slot == 0 {
slot, err = st.GetSlot()
if err != nil {
Expand Down
16 changes: 14 additions & 2 deletions node-api/backend/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
package backend

import (
"github.com/berachain/beacon-kit/errors"
"errors"
"fmt"

apitypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types"
"github.com/berachain/beacon-kit/primitives/math"
)
Expand All @@ -34,8 +36,18 @@ func (b *Backend) BlobSidecarsByIndices(slot math.Slot, indices []uint64) ([]*ap
if currentSlot < 0 {
return nil, errors.New("invalid negative block height")
}

// If the requested slot is 0 (head, finalized, justified), use the current slot.
if slot == 0 {
slot = math.Slot(currentSlot)
}

// Validate the requested slot is within the Data Availability Period.
if !b.cs.WithinDAPeriod(slot, math.Slot(currentSlot)) {
return nil, errors.New("requested block is no longer within the Data Availability Period")
return nil, fmt.Errorf(
"requested slot (%d) is not within Data Availability Period (previous %d epochs)",
slot, b.cs.MinEpochsForBlobsSidecarsRequest(),
)
}

// Validate request indices.
Expand Down

0 comments on commit d90756b

Please sign in to comment.