Skip to content

Commit

Permalink
Add DA check
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Feb 15, 2025
1 parent 24f3a7f commit 034c82c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
18 changes: 11 additions & 7 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,17 @@ func (s *Service) isDataAvailable(ctx context.Context, root [32]byte, signed int
if err != nil {
return errors.Wrap(err, "could not get KZG commitments")
}
// expected is the number of kzg commitments observed in the block.

return s.isDataAvailableCore(ctx, kzgCommitments, root, block.Slot())
}

func (s *Service) isDataAvailableCore(ctx context.Context, kzgCommitments [][]byte, root [32]byte, slot primitives.Slot) error {
expected := len(kzgCommitments)
if expected == 0 {
return nil
}
// get a map of BlobSidecar indices that are not currently available.
missing, err := missingIndices(s.blobStorage, root, kzgCommitments, block.Slot())

missing, err := missingIndices(s.blobStorage, root, kzgCommitments, slot)
if err != nil {
return err
}
Expand All @@ -592,17 +596,17 @@ func (s *Service) isDataAvailable(ctx context.Context, root [32]byte, signed int

// The gossip handler for blobs writes the index of each verified blob referencing the given
// root to the channel returned by blobNotifiers.forRoot.
nc := s.blobNotifiers.forRoot(root, block.Slot())
nc := s.blobNotifiers.forRoot(root, slot)

// Log for DA checks that cross over into the next slot; helpful for debugging.
nextSlot := slots.BeginsAt(signed.Block().Slot()+1, s.genesisTime)
nextSlot := slots.BeginsAt(slot+1, s.genesisTime)
// Avoid logging if DA check is called after next slot start.
if nextSlot.After(time.Now()) {
nst := time.AfterFunc(time.Until(nextSlot), func() {
if len(missing) == 0 {
return
}
log.WithFields(daCheckLogFields(root, signed.Block().Slot(), expected, len(missing))).
log.WithFields(daCheckLogFields(root, slot, expected, len(missing))).
Error("Still waiting for DA check at slot end.")
})
defer nst.Stop()
Expand All @@ -620,7 +624,7 @@ func (s *Service) isDataAvailable(ctx context.Context, root [32]byte, signed int
s.blobNotifiers.delete(root)
return nil
case <-ctx.Done():
return errors.Wrapf(ctx.Err(), "context deadline waiting for blob sidecars slot: %d, BlockRoot: %#x", block.Slot(), root)
return errors.Wrapf(ctx.Err(), "context deadline waiting for blob sidecars slot: %d, BlockRoot: %#x", slot, root)
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions beacon-chain/blockchain/receive_execution_payload_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (s *Service) ReceiveExecutionPayloadEnvelope(ctx context.Context, signed in
return err
}
daStartTime := time.Now()
// TODO: Add DA check
if err := s.isDataAvailableCore(ctx, envelope.BlobKzgCommitments(), root, envelope.Slot()); err != nil {
return errors.Wrap(err, "could not verify data availability")
}
daWaitedTime := time.Since(daStartTime)
dataAvailWaitedTime.Observe(float64(daWaitedTime.Milliseconds()))
if err := s.savePostPayload(ctx, signed, preState); err != nil {
Expand Down Expand Up @@ -142,10 +144,11 @@ func (s *Service) ReceiveExecutionPayloadEnvelope(ctx context.Context, signed in
})

log.WithFields(logrus.Fields{
"slot": envelope.Slot(),
"blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(root[:])),
"blockHash": fmt.Sprintf("%#x", bytesutil.Trunc(ex.BlockHash())),
"ParentHash": fmt.Sprintf("%#x", bytesutil.Trunc(ex.ParentHash())),
"slot": envelope.Slot(),
"blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(root[:])),
"blockHash": fmt.Sprintf("%#x", bytesutil.Trunc(ex.BlockHash())),
"ParentHash": fmt.Sprintf("%#x", bytesutil.Trunc(ex.ParentHash())),
"KzgCommitmentCount": len(envelope.BlobKzgCommitments()),
}).Info("Processed execution payload envelope")
return nil
}
Expand Down
20 changes: 20 additions & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
Expand Down Expand Up @@ -316,6 +317,25 @@ func (vs *Server) ProposeBeaconBlock(ctx context.Context, req *ethpb.GenericSign
block, sidecars, err = vs.handleBlindedBlock(ctx, block)
} else if block.Version() >= version.Deneb && block.Version() < version.EPBS {
sidecars, err = vs.blobSidecarsFromUnblindedBlock(block, req)
} else if block.Version() >= version.EPBS {
h, err := block.Header()
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get header: %v", err)
}
commitmentInclusionProof := make([][]byte, 17)
for i := range commitmentInclusionProof {
commitmentInclusionProof[i] = bytesutil.PadTo([]byte{}, 32)
}
for i, proof := range vs.blobsBundle.Proofs {
sidecars = append(sidecars, &ethpb.BlobSidecar{
Index: uint64(i),
Blob: vs.blobsBundle.Blobs[i],
KzgCommitment: vs.blobsBundle.KzgCommitments[i],
KzgProof: proof,
SignedBlockHeader: h,
CommitmentInclusionProof: commitmentInclusionProof, // TODO: add commitment inclusion proof
})
}
}
if err != nil {
return nil, status.Errorf(codes.Internal, "%s: %v", "handle block failed", err)
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/rpc/prysm/v1alpha1/validator/proposer_epbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (vs *Server) SubmitSignedExecutionPayloadEnvelope(ctx context.Context, env
}
log.Info("Broadcasted signed execution payload envelope")

env.Message.BlobKzgCommitments = [][]byte{}
m, err := blocks.WrappedROSignedExecutionPayloadEnvelope(env)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to wrap execution payload envelope: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/verification/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ func (bv *ROBlobVerifier) SidecarDescendsFromFinalized() (err error) {
// [REJECT] The sidecar's inclusion proof is valid as verified by verify_blob_sidecar_inclusion_proof(blob_sidecar).
func (bv *ROBlobVerifier) SidecarInclusionProven() (err error) {
defer bv.recordResult(RequireSidecarInclusionProven, &err)
// TODO: Skipping inclusion proof for epbs fork for now.
if slots.ToEpoch(bv.blob.Slot()) >= params.BeaconConfig().EPBSForkEpoch {
return nil
}
if err = blocks.VerifyKZGInclusionProof(bv.blob); err != nil {
log.WithError(err).WithFields(logging.BlobFields(bv.blob)).Debug("sidecar inclusion proof verification failed")
return blobErrBuilder(ErrSidecarInclusionProofInvalid)
Expand Down
2 changes: 1 addition & 1 deletion config/fieldparams/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
MaxBlsToExecutionChanges = 16 // Maximum number of bls to execution changes in a block.
MaxRandomByte = uint64(1<<8 - 1) // MaxRandomByte defines max for a random byte using for proposer and sync committee sampling.
MaxRandomValueElectra = uint64(1<<16 - 1) // MaxRandomValueElectra defines max for a random value using for proposer and sync committee sampling.
PTCSize = 512 // PTC_SIZE [New in ePBS]
PTCSize = 16 // PTC_SIZE [New in ePBS]
MaxPayloadAttestationsPerBlock = 4 // MAX_PAYLOAD_ATTESTATIONS [New in ePBS]
MaxTransactionsPerInclusionList = 1024 // MAX_TRANSACTIONS_PER_INCLUSION_LIST [New in ePBS]
PayloadTimelyThreshold = 256 // PTC_SIZE / 2 [New in ePBS]
Expand Down

0 comments on commit 034c82c

Please sign in to comment.