From 1a7e0397bbf5faf711cdf32687df34a5bcb9032c Mon Sep 17 00:00:00 2001 From: healthykim Date: Thu, 14 May 2026 19:15:48 +0200 Subject: [PATCH] core, eth: new engine api spec --- core/types/custody_bitmap.go | 32 ++++++++------------------------ eth/catalyst/api.go | 9 ++++----- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/core/types/custody_bitmap.go b/core/types/custody_bitmap.go index d3624bb914..74585cdc42 100644 --- a/core/types/custody_bitmap.go +++ b/core/types/custody_bitmap.go @@ -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 } diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index b980920493..ebe0b880aa 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -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