mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-02 04:58:38 +00:00
core, eth: new engine api spec
This commit is contained in:
parent
a7896c90db
commit
1a7e0397bb
2 changed files with 12 additions and 29 deletions
|
|
@ -18,47 +18,31 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CustodyBitmap is a bitmap to represent which custody index to store (little endian).
|
// 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
|
type CustodyBitmap [16]byte
|
||||||
|
|
||||||
// MarshalText implements encoding.TextMarshaler.
|
// MarshalText implements encoding.TextMarshaler.
|
||||||
// Encodes the bitmap as a hex-encoded uint128 quantity.
|
|
||||||
func (b CustodyBitmap) MarshalText() ([]byte, error) {
|
func (b CustodyBitmap) MarshalText() ([]byte, error) {
|
||||||
var be [16]byte
|
return []byte(hexutil.Encode(b[:])), nil
|
||||||
for i := range b {
|
|
||||||
be[15-i] = b[i]
|
|
||||||
}
|
|
||||||
v := new(big.Int).SetBytes(be[:])
|
|
||||||
return []byte("0x" + v.Text(16)), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||||
// Parses a hex-encoded uint128 quantity into the bitmap.
|
|
||||||
func (b *CustodyBitmap) UnmarshalText(input []byte) error {
|
func (b *CustodyBitmap) UnmarshalText(input []byte) error {
|
||||||
s := string(input)
|
decoded, err := hexutil.Decode(string(input))
|
||||||
if len(s) < 2 || (s[:2] != "0x" && s[:2] != "0X") {
|
if err != nil {
|
||||||
return fmt.Errorf("custody bitmap: missing 0x prefix")
|
return fmt.Errorf("custody bitmap: %v", err)
|
||||||
}
|
}
|
||||||
v, ok := new(big.Int).SetString(s[2:], 16)
|
if len(decoded) != len(b) {
|
||||||
if !ok {
|
return fmt.Errorf("custody bitmap: invalid length %d, want %d", len(decoded), len(b))
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
copy(b[:], decoded)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(ctx context.Context, update engine.
|
||||||
|
|
||||||
// ForkchoiceUpdatedV4 is equivalent to V3 with the addition of slot number
|
// ForkchoiceUpdatedV4 is equivalent to V3 with the addition of slot number
|
||||||
// in the payload attributes. It supports only PayloadAttributesV4.
|
// 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 {
|
if params != nil {
|
||||||
switch {
|
switch {
|
||||||
case params.Withdrawals == nil:
|
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")
|
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
|
// 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
|
// 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
|
// 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
|
return bodies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *ConsensusAPI) BlobCustodyUpdatedV1(indicesBitarray types.CustodyBitmap) {
|
|
||||||
api.eth.BlobFetcher().UpdateCustody(indicesBitarray)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getBody(block *types.Block) *engine.ExecutionPayloadBody {
|
func getBody(block *types.Block) *engine.ExecutionPayloadBody {
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue