Skip to content

Commit

Permalink
merge GetBlobsBundleV1 with GetPayloadV3 per spec update (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-bayardo authored Apr 21, 2023
1 parent 1ea2f96 commit 15504a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
14 changes: 10 additions & 4 deletions beacon/engine/gen_epe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ type payloadAttributesMarshaling struct {
Timestamp hexutil.Uint64
}

// BlobsBundle holds the blobs of an execution payload, to be retrieved separately
// BlobsBundle holds the blobs of an execution payload
type BlobsBundle struct {
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
KZGs []types.KZGCommitment `json:"kzgs" gencodec:"required"`
Blobs []types.Blob `json:"blobs" gencodec:"required"`
KZGs []types.KZGCommitment `json:"kzgs" gencodec:"required"`
Blobs []types.Blob `json:"blobs" gencodec:"required"`
}

//go:generate go run github.com/fjl/gencodec -type ExecutableData -field-override executableDataMarshaling -out gen_ed.go
Expand Down Expand Up @@ -87,8 +86,9 @@ type executableDataMarshaling struct {
//go:generate go run github.com/fjl/gencodec -type ExecutionPayloadEnvelope -field-override executionPayloadEnvelopeMarshaling -out gen_epe.go

type ExecutionPayloadEnvelope struct {
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
BlockValue *big.Int `json:"blockValue" gencodec:"required"`
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
BlockValue *big.Int `json:"blockValue" gencodec:"required"`
BlobsBundle *BlobsBundle `json:"blobsBundle" gencodec:"omitempty"`
}

// JSON type overrides for ExecutionPayloadEnvelope.
Expand Down Expand Up @@ -248,18 +248,16 @@ type ExecutionPayloadBodyV1 struct {
}

func BlockToBlobData(block *types.Block) (*BlobsBundle, error) {
blockHash := block.Hash()
blobsBundle := &BlobsBundle{
BlockHash: blockHash,
Blobs: []types.Blob{},
KZGs: []types.KZGCommitment{},
Blobs: []types.Blob{},
KZGs: []types.KZGCommitment{},
}
for i, tx := range block.Transactions() {
if tx.Type() == types.BlobTxType {
versionedHashes, kzgs, blobs, proofs := tx.BlobWrapData()
if len(versionedHashes) != len(kzgs) || len(versionedHashes) != len(blobs) || len(blobs) != len(proofs) {
return nil, fmt.Errorf("tx %d in block %s has inconsistent blobs (%d) / kzgs (%d)"+
" / versioned hashes (%d) / proofs (%d)", i, blockHash, len(blobs), len(kzgs), len(versionedHashes), len(proofs))
" / versioned hashes (%d) / proofs (%d)", i, block.Hash(), len(blobs), len(kzgs), len(versionedHashes), len(proofs))
}

blobsBundle.Blobs = append(blobsBundle.Blobs, blobs...)
Expand Down
14 changes: 6 additions & 8 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ var caps = []string{
"engine_newPayloadV3",
"engine_getPayloadBodiesByHashV1",
"engine_getPayloadBodiesByRangeV1",
"engine_getBlobsBundleV1",
}

type ConsensusAPI struct {
Expand Down Expand Up @@ -424,20 +423,19 @@ func (api *ConsensusAPI) getPayload(payloadID engine.PayloadID) (*engine.Executi

// GetPayloadV3 returns a cached payload by id.
func (api *ConsensusAPI) GetPayloadV3(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
return api.GetPayloadV2(payloadID)
}

// GetBlobsBundleV1 returns a bundle of all blob and corresponding KZG commitments by payload id
func (api *ConsensusAPI) GetBlobsBundleV1(payloadID engine.PayloadID) (*engine.BlobsBundle, error) {
log.Trace("Engine API request received", "method", "GetBlobsBundle")
pl, err := api.GetPayloadV2(payloadID)
if err != nil {
return nil, err
}
data, err := api.localBlocks.getBlobsBundle(payloadID)
if err != nil {
return nil, err
}
if data == nil {
return nil, engine.UnknownPayload
}
return data, nil
pl.BlobsBundle = data
return pl, nil
}

// NewPayloadV1 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
Expand Down

0 comments on commit 15504a6

Please sign in to comment.