mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
beacon, eth: add more comments about engine API
This commit is contained in:
parent
6a7f64e760
commit
ea8378511a
3 changed files with 52 additions and 11 deletions
|
|
@ -17,7 +17,7 @@ func (e ExecutionPayloadEnvelope) MarshalJSON() ([]byte, error) {
|
||||||
type ExecutionPayloadEnvelope struct {
|
type ExecutionPayloadEnvelope struct {
|
||||||
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
|
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
|
||||||
BlockValue *hexutil.Big `json:"blockValue" gencodec:"required"`
|
BlockValue *hexutil.Big `json:"blockValue" gencodec:"required"`
|
||||||
BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
|
BlobsBundle *BlobsBundle `json:"blobsBundle"`
|
||||||
Requests []hexutil.Bytes `json:"executionRequests"`
|
Requests []hexutil.Bytes `json:"executionRequests"`
|
||||||
Override bool `json:"shouldOverrideBuilder"`
|
Override bool `json:"shouldOverrideBuilder"`
|
||||||
Witness *hexutil.Bytes `json:"witness,omitempty"`
|
Witness *hexutil.Bytes `json:"witness,omitempty"`
|
||||||
|
|
@ -42,7 +42,7 @@ func (e *ExecutionPayloadEnvelope) UnmarshalJSON(input []byte) error {
|
||||||
type ExecutionPayloadEnvelope struct {
|
type ExecutionPayloadEnvelope struct {
|
||||||
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
|
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
|
||||||
BlockValue *hexutil.Big `json:"blockValue" gencodec:"required"`
|
BlockValue *hexutil.Big `json:"blockValue" gencodec:"required"`
|
||||||
BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
|
BlobsBundle *BlobsBundle `json:"blobsBundle"`
|
||||||
Requests []hexutil.Bytes `json:"executionRequests"`
|
Requests []hexutil.Bytes `json:"executionRequests"`
|
||||||
Override *bool `json:"shouldOverrideBuilder"`
|
Override *bool `json:"shouldOverrideBuilder"`
|
||||||
Witness *hexutil.Bytes `json:"witness,omitempty"`
|
Witness *hexutil.Bytes `json:"witness,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,22 @@ import (
|
||||||
type PayloadVersion byte
|
type PayloadVersion byte
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// PayloadV1 is the identifier of ExecutionPayloadV1 introduced in paris fork.
|
||||||
|
// https://github.com/ethereum/execution-apis/blob/main/src/engine/paris.md#executionpayloadv1
|
||||||
PayloadV1 PayloadVersion = 0x1
|
PayloadV1 PayloadVersion = 0x1
|
||||||
|
|
||||||
|
// PayloadV2 is the identifier of ExecutionPayloadV2 introduced in shanghai fork.
|
||||||
|
//
|
||||||
|
// https://github.com/ethereum/execution-apis/blob/main/src/engine/shanghai.md#executionpayloadv2
|
||||||
|
// ExecutionPayloadV2 has the syntax of ExecutionPayloadV1 and appends a
|
||||||
|
// single field: withdrawals.
|
||||||
PayloadV2 PayloadVersion = 0x2
|
PayloadV2 PayloadVersion = 0x2
|
||||||
|
|
||||||
|
// PayloadV3 is the identifier of ExecutionPayloadV3 introduced in cancun fork.
|
||||||
|
//
|
||||||
|
// https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#executionpayloadv3
|
||||||
|
// ExecutionPayloadV3 has the syntax of ExecutionPayloadV2 and appends the new
|
||||||
|
// fields: blobGasUsed and excessBlobGas.
|
||||||
PayloadV3 PayloadVersion = 0x3
|
PayloadV3 PayloadVersion = 0x3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -106,13 +120,18 @@ type StatelessPayloadStatusV1 struct {
|
||||||
type ExecutionPayloadEnvelope struct {
|
type ExecutionPayloadEnvelope struct {
|
||||||
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
|
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
|
||||||
BlockValue *big.Int `json:"blockValue" gencodec:"required"`
|
BlockValue *big.Int `json:"blockValue" gencodec:"required"`
|
||||||
BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
|
BlobsBundle *BlobsBundle `json:"blobsBundle"`
|
||||||
Requests [][]byte `json:"executionRequests"`
|
Requests [][]byte `json:"executionRequests"`
|
||||||
Override bool `json:"shouldOverrideBuilder"`
|
Override bool `json:"shouldOverrideBuilder"`
|
||||||
Witness *hexutil.Bytes `json:"witness,omitempty"`
|
Witness *hexutil.Bytes `json:"witness,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BlobsBundleV1 struct {
|
// BlobsBundle includes the marshalled sidecar data. Note this structure is
|
||||||
|
// shared by BlobsBundleV1 and BlobsBundleV2 for the sake of simplicity.
|
||||||
|
//
|
||||||
|
// - BlobsBundleV1: proofs contain exactly len(blobs) kzg proofs.
|
||||||
|
// - BlobsBundleV2: proofs contain exactly CELLS_PER_EXT_BLOB * len(blobs) cell proofs.
|
||||||
|
type BlobsBundle struct {
|
||||||
Commitments []hexutil.Bytes `json:"commitments"`
|
Commitments []hexutil.Bytes `json:"commitments"`
|
||||||
Proofs []hexutil.Bytes `json:"proofs"`
|
Proofs []hexutil.Bytes `json:"proofs"`
|
||||||
Blobs []hexutil.Bytes `json:"blobs"`
|
Blobs []hexutil.Bytes `json:"blobs"`
|
||||||
|
|
@ -327,18 +346,27 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add blobs.
|
// Add blobs.
|
||||||
bundle := BlobsBundleV1{
|
bundle := BlobsBundle{
|
||||||
Commitments: make([]hexutil.Bytes, 0),
|
Commitments: make([]hexutil.Bytes, 0),
|
||||||
Blobs: make([]hexutil.Bytes, 0),
|
Blobs: make([]hexutil.Bytes, 0),
|
||||||
Proofs: make([]hexutil.Bytes, 0),
|
Proofs: make([]hexutil.Bytes, 0),
|
||||||
}
|
}
|
||||||
for _, sidecar := range sidecars {
|
for _, sidecar := range sidecars {
|
||||||
for j := range sidecar.Blobs {
|
for j := range sidecar.Blobs {
|
||||||
bundle.Blobs = append(bundle.Blobs, hexutil.Bytes(sidecar.Blobs[j][:]))
|
bundle.Blobs = append(bundle.Blobs, sidecar.Blobs[j][:])
|
||||||
bundle.Commitments = append(bundle.Commitments, hexutil.Bytes(sidecar.Commitments[j][:]))
|
bundle.Commitments = append(bundle.Commitments, sidecar.Commitments[j][:])
|
||||||
}
|
}
|
||||||
|
// - Before the Osaka fork, only version-0 blob transactions should be packed,
|
||||||
|
// with the proof length equal to len(blobs).
|
||||||
|
//
|
||||||
|
// - After the Osaka fork, only version-1 blob transactions should be packed,
|
||||||
|
// with the proof length equal to CELLS_PER_EXT_BLOB * len(blobs).
|
||||||
|
//
|
||||||
|
// Ideally, length validation should be performed based on the bundle version.
|
||||||
|
// In practice, this is unnecessary because blob transaction filtering is
|
||||||
|
// already done during payload construction.
|
||||||
for _, proof := range sidecar.Proofs {
|
for _, proof := range sidecar.Proofs {
|
||||||
bundle.Proofs = append(bundle.Proofs, hexutil.Bytes(proof[:]))
|
bundle.Proofs = append(bundle.Proofs, proof[:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -418,13 +418,21 @@ func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.Execu
|
||||||
|
|
||||||
// GetPayloadV2 returns a cached payload by id.
|
// GetPayloadV2 returns a cached payload by id.
|
||||||
func (api *ConsensusAPI) GetPayloadV2(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
func (api *ConsensusAPI) GetPayloadV2(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
||||||
|
// executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2 where:
|
||||||
|
//
|
||||||
|
// - ExecutionPayloadV1 MUST be returned if the payload timestamp is lower
|
||||||
|
// than the Shanghai timestamp
|
||||||
|
//
|
||||||
|
// - ExecutionPayloadV2 MUST be returned if the payload timestamp is greater
|
||||||
|
// or equal to the Shanghai timestamp
|
||||||
if !payloadID.Is(engine.PayloadV1, engine.PayloadV2) {
|
if !payloadID.Is(engine.PayloadV1, engine.PayloadV2) {
|
||||||
return nil, engine.UnsupportedFork
|
return nil, engine.UnsupportedFork
|
||||||
}
|
}
|
||||||
return api.getPayload(payloadID, false)
|
return api.getPayload(payloadID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPayloadV3 returns a cached payload by id.
|
// GetPayloadV3 returns a cached payload by id. This endpoint should only
|
||||||
|
// be used after the Cancun fork.
|
||||||
func (api *ConsensusAPI) GetPayloadV3(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
func (api *ConsensusAPI) GetPayloadV3(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
||||||
if !payloadID.Is(engine.PayloadV3) {
|
if !payloadID.Is(engine.PayloadV3) {
|
||||||
return nil, engine.UnsupportedFork
|
return nil, engine.UnsupportedFork
|
||||||
|
|
@ -432,7 +440,8 @@ func (api *ConsensusAPI) GetPayloadV3(payloadID engine.PayloadID) (*engine.Execu
|
||||||
return api.getPayload(payloadID, false)
|
return api.getPayload(payloadID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPayloadV4 returns a cached payload by id.
|
// GetPayloadV4 returns a cached payload by id. This endpoint should only
|
||||||
|
// be used after the Prague fork.
|
||||||
func (api *ConsensusAPI) GetPayloadV4(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
func (api *ConsensusAPI) GetPayloadV4(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
||||||
if !payloadID.Is(engine.PayloadV3) {
|
if !payloadID.Is(engine.PayloadV3) {
|
||||||
return nil, engine.UnsupportedFork
|
return nil, engine.UnsupportedFork
|
||||||
|
|
@ -440,7 +449,11 @@ func (api *ConsensusAPI) GetPayloadV4(payloadID engine.PayloadID) (*engine.Execu
|
||||||
return api.getPayload(payloadID, false)
|
return api.getPayload(payloadID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPayloadV5 returns a cached payload by id.
|
// GetPayloadV5 returns a cached payload by id. This endpoint should only
|
||||||
|
// be used after the Osaka fork.
|
||||||
|
//
|
||||||
|
// This method follows the same specification as engine_getPayloadV4 with
|
||||||
|
// changes of returning BlobsBundleV2 with BlobSidecar version 1.
|
||||||
func (api *ConsensusAPI) GetPayloadV5(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
func (api *ConsensusAPI) GetPayloadV5(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
|
||||||
if !payloadID.Is(engine.PayloadV3) {
|
if !payloadID.Is(engine.PayloadV3) {
|
||||||
return nil, engine.UnsupportedFork
|
return nil, engine.UnsupportedFork
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue