From 3454841adee412cc75b808a1120bfe913f3d633a Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Sat, 28 Feb 2026 20:56:37 +0800 Subject: [PATCH] fix(core): hex encode validators/validator/penalties in Header JSON (#2057) Ensure JSON marshal/unmarshal uses hex for validators, validator, and penalties so Header encoding is consistent with RPC output. --- core/types/block.go | 3 +++ core/types/gen_header_json.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index b9b4b56d62..4fad656260 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -95,6 +95,9 @@ type headerMarshaling struct { GasUsed hexutil.Uint64 Time hexutil.Uint64 Extra hexutil.Bytes + Validators hexutil.Bytes + Validator hexutil.Bytes + Penalties hexutil.Bytes BaseFee *hexutil.Big Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON } diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 05889cdc30..f9a1e787d3 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -31,9 +31,9 @@ func (h Header) MarshalJSON() ([]byte, error) { Extra hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest common.Hash `json:"mixHash" gencodec:"required"` Nonce BlockNonce `json:"nonce" gencodec:"required"` - Validators []byte `json:"validators" gencodec:"required"` - Validator []byte `json:"validator" gencodec:"required"` - Penalties []byte `json:"penalties" gencodec:"required"` + Validators hexutil.Bytes `json:"validators" gencodec:"required"` + Validator hexutil.Bytes `json:"validator" gencodec:"required"` + Penalties hexutil.Bytes `json:"penalties" gencodec:"required"` BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` Hash common.Hash `json:"hash"` } @@ -79,9 +79,9 @@ func (h *Header) UnmarshalJSON(input []byte) error { Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest *common.Hash `json:"mixHash" gencodec:"required"` Nonce *BlockNonce `json:"nonce" gencodec:"required"` - Validators []byte `json:"validators" gencodec:"required"` - Validator []byte `json:"validator" gencodec:"required"` - Penalties []byte `json:"penalties" gencodec:"required"` + Validators *hexutil.Bytes `json:"validators" gencodec:"required"` + Validator *hexutil.Bytes `json:"validator" gencodec:"required"` + Penalties *hexutil.Bytes `json:"penalties" gencodec:"required"` BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` } var dec Header @@ -151,15 +151,15 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.Validators == nil { return errors.New("missing required field 'validators' for Header") } - h.Validators = dec.Validators + h.Validators = *dec.Validators if dec.Validator == nil { return errors.New("missing required field 'validator' for Header") } - h.Validator = dec.Validator + h.Validator = *dec.Validator if dec.Penalties == nil { return errors.New("missing required field 'penalties' for Header") } - h.Penalties = dec.Penalties + h.Penalties = *dec.Penalties if dec.BaseFee != nil { h.BaseFee = (*big.Int)(dec.BaseFee) }