core, eth: new engine api spec

This commit is contained in:
healthykim 2026-05-14 19:15:48 +02:00
parent a7896c90db
commit 1a7e0397bb
2 changed files with 12 additions and 29 deletions

View file

@ -18,47 +18,31 @@ package types
import (
"fmt"
"math/big"
"math/bits"
"math/rand"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
)
// CustodyBitmap is a bitmap to represent which custody index to store (little endian).
// It is serialized as a hex-encoded uint128 quantity (e.g. "0x89") for JSON-RPC.
type CustodyBitmap [16]byte
// MarshalText implements encoding.TextMarshaler.
// Encodes the bitmap as a hex-encoded uint128 quantity.
func (b CustodyBitmap) MarshalText() ([]byte, error) {
var be [16]byte
for i := range b {
be[15-i] = b[i]
}
v := new(big.Int).SetBytes(be[:])
return []byte("0x" + v.Text(16)), nil
return []byte(hexutil.Encode(b[:])), nil
}
// UnmarshalText implements encoding.TextUnmarshaler.
// Parses a hex-encoded uint128 quantity into the bitmap.
func (b *CustodyBitmap) UnmarshalText(input []byte) error {
s := string(input)
if len(s) < 2 || (s[:2] != "0x" && s[:2] != "0X") {
return fmt.Errorf("custody bitmap: missing 0x prefix")
decoded, err := hexutil.Decode(string(input))
if err != nil {
return fmt.Errorf("custody bitmap: %v", err)
}
v, ok := new(big.Int).SetString(s[2:], 16)
if !ok {
return fmt.Errorf("custody bitmap: invalid hex %q", s)
}
if v.BitLen() > 128 {
return fmt.Errorf("custody bitmap: value exceeds 128 bits")
}
*b = CustodyBitmap{}
beBytes := v.Bytes() // big-endian
for i, byt := range beBytes {
b[len(beBytes)-1-i] = byt
if len(decoded) != len(b) {
return fmt.Errorf("custody bitmap: invalid length %d, want %d", len(decoded), len(b))
}
copy(b[:], decoded)
return nil
}

View file

@ -214,7 +214,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(ctx context.Context, update engine.
// ForkchoiceUpdatedV4 is equivalent to V3 with the addition of slot number
// in the payload attributes. It supports only PayloadAttributesV4.
func (api *ConsensusAPI) ForkchoiceUpdatedV4(ctx context.Context, update engine.ForkchoiceStateV1, params *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
func (api *ConsensusAPI) ForkchoiceUpdatedV4(ctx context.Context, update engine.ForkchoiceStateV1, params *engine.PayloadAttributes, custodyColumns *types.CustodyBitmap) (engine.ForkChoiceResponse, error) {
if params != nil {
switch {
case params.Withdrawals == nil:
@ -227,6 +227,9 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV4(ctx context.Context, update engine.
return engine.STATUS_INVALID, unsupportedForkErr("fcuV4 must only be called for amsterdam payloads")
}
}
if custodyColumns != nil {
api.eth.BlobFetcher().UpdateCustody(*custodyColumns)
}
// TODO(matt): the spec requires that fcu is applied when called on a valid
// hash, even if params are wrong. To do this we need to split up
// forkchoiceUpdate into a function that only updates the head and then a
@ -1218,10 +1221,6 @@ func (api *ConsensusAPI) getBodiesByRange(start, count hexutil.Uint64) ([]*engin
return bodies, nil
}
func (api *ConsensusAPI) BlobCustodyUpdatedV1(indicesBitarray types.CustodyBitmap) {
api.eth.BlobFetcher().UpdateCustody(indicesBitarray)
}
func getBody(block *types.Block) *engine.ExecutionPayloadBody {
if block == nil {
return nil