Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder: Electra #14344

Merged
merged 74 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
d0522ac
removing skip from test
james-prysm Aug 14, 2024
9269e0e
Merge branch 'develop' into electra-test-remove-skip
james-prysm Aug 14, 2024
1ed404c
builder wip
james-prysm Aug 14, 2024
592a45a
Merge branch 'develop' into builder-electra
james-prysm Aug 14, 2024
512e388
removing todo, it's probably ok
james-prysm Aug 14, 2024
bfae0ca
adding more TODOs
james-prysm Aug 14, 2024
d8b98d7
adding fromProtoElectra
james-prysm Aug 14, 2024
dbc55c9
using lightclient
james-prysm Aug 15, 2024
2521755
minor fixes
james-prysm Aug 15, 2024
9c8d26e
Merge branch 'develop' into builder-electra
james-prysm Sep 5, 2024
734ef94
Merge branch 'develop' into builder-electra
james-prysm Sep 16, 2024
066ce6a
Merge branch 'develop' into builder-electra
james-prysm Sep 24, 2024
67235fb
rolling back dependency changes
james-prysm Sep 24, 2024
6d580ec
go mod tidy
james-prysm Sep 24, 2024
c67df35
adding space back in
james-prysm Sep 24, 2024
6d1a9fa
Merge branch 'develop' into builder-electra
james-prysm Sep 25, 2024
d5f8e02
updating builder changes based on execution request changes
james-prysm Sep 26, 2024
2c907b2
Merge branch 'develop' into builder-electra
james-prysm Oct 15, 2024
289bb52
update ssz
james-prysm Oct 15, 2024
1c4be98
changelog
james-prysm Oct 15, 2024
45c1d0b
Merge branch 'develop' into builder-electra
james-prysm Oct 17, 2024
c1a93d8
updating based on execution request changes
james-prysm Oct 17, 2024
802a68b
fixing validation
james-prysm Oct 17, 2024
0aae98d
adding builder test for electra
james-prysm Oct 18, 2024
1adc957
Merge branch 'develop' into builder-electra
james-prysm Oct 18, 2024
759b819
gaz
james-prysm Oct 21, 2024
35e8541
attempting to fix test
james-prysm Oct 21, 2024
a5cea41
fixing ssz
james-prysm Oct 21, 2024
9cdb111
Merge branch 'develop' into builder-electra
james-prysm Oct 21, 2024
b409a59
Merge branch 'develop' into builder-electra
james-prysm Oct 23, 2024
6c6b582
Merge branch 'develop' into builder-electra
james-prysm Jan 13, 2025
c5e8c82
Merge branch 'develop' into builder-electra
james-prysm Jan 13, 2025
174ba31
fixing build and handling develop changes
james-prysm Jan 13, 2025
504db9f
gaz
james-prysm Jan 13, 2025
4c2dbbb
fixing unfinished function
james-prysm Jan 13, 2025
add6015
fixing test
james-prysm Jan 13, 2025
3982901
Merge branch 'develop' into builder-electra
james-prysm Jan 13, 2025
91aa1b3
fixing important missed regression
james-prysm Jan 13, 2025
c0d01ea
removing unneeded validations
james-prysm Jan 13, 2025
8cef6df
missed linting
james-prysm Jan 13, 2025
a47bd35
gofmt
james-prysm Jan 13, 2025
e6a404e
fixing fulu test
james-prysm Jan 13, 2025
89b8358
Merge branch 'develop' into builder-electra
james-prysm Jan 15, 2025
3a837b0
Merge branch 'develop' into builder-electra
james-prysm Jan 15, 2025
b7d6bcd
fixing changelog
james-prysm Jan 15, 2025
96ed501
Merge branch 'develop' into builder-electra
james-prysm Jan 15, 2025
e85d6e7
Merge branch 'develop' into builder-electra
james-prysm Jan 16, 2025
18738bf
Update bid.go
james-prysm Jan 16, 2025
4ac326e
Update bid.go
james-prysm Jan 16, 2025
46c55fc
Update types.go
james-prysm Jan 16, 2025
6277a1b
Update types.go
james-prysm Jan 16, 2025
1e74eeb
Update james-prysm_builder-electra.md
james-prysm Jan 16, 2025
70ff336
Update testing/middleware/builder/builder.go
james-prysm Jan 22, 2025
2726f7a
Merge branch 'develop' into builder-electra
james-prysm Jan 22, 2025
5bbbad6
addressing review feedback and updating e2e
james-prysm Jan 22, 2025
1cd3a71
fixing parsing bid version
james-prysm Jan 22, 2025
cfd65c0
reversing incorrect check
james-prysm Jan 22, 2025
fbf7aae
improving tests and updating more code based on review feedback
james-prysm Jan 22, 2025
e0c5034
gofmt
james-prysm Jan 22, 2025
6ec4a0f
Merge branch 'develop' into builder-electra
james-prysm Jan 22, 2025
6595008
fixing unit tests
james-prysm Jan 22, 2025
b8aa910
more feedback from terence
james-prysm Jan 23, 2025
2a29e0f
gofmt
james-prysm Jan 23, 2025
08def54
Update api/client/builder/types.go
james-prysm Jan 23, 2025
03f5754
Update beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go
james-prysm Jan 23, 2025
7ab30bd
Update beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go
james-prysm Jan 23, 2025
40c180e
Update beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go
james-prysm Jan 23, 2025
f9483ef
Update beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix.go
james-prysm Jan 23, 2025
2ac5089
Update api/client/builder/types.go
james-prysm Jan 23, 2025
ac64d37
addressing nitpicks
james-prysm Jan 23, 2025
73d2b5b
gofmt
james-prysm Jan 23, 2025
ab16642
radek feedback
james-prysm Jan 23, 2025
4c40f18
Merge branch 'develop' into builder-electra
james-prysm Jan 23, 2025
15199e5
improves error
james-prysm Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/client/builder/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
deps = [
"//api:go_default_library",
"//api/client:go_default_library",
"//api/server:go_default_library",
"//api/server/structs:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
Expand All @@ -27,6 +28,7 @@ go_library(
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_fastssz//:go_default_library",
Expand Down
121 changes: 107 additions & 14 deletions api/client/builder/bid.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package builder

import (
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
consensus_types "github.com/prysmaticlabs/prysm/v5/consensus-types"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
v1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
Expand All @@ -22,7 +22,6 @@ type SignedBid interface {
// Bid is an interface describing the method set of a builder bid.
type Bid interface {
Header() (interfaces.ExecutionData, error)
BlobKzgCommitments() ([][]byte, error)
Value() primitives.Wei
Pubkey() []byte
Version() int
Expand All @@ -31,6 +30,18 @@ type Bid interface {
HashTreeRootWith(hh *ssz.Hasher) error
}

// BidDeneb is an interface that exposes newly added kzg commitments on top of builder bid
type BidDeneb interface {
Bid
BlobKzgCommitments() [][]byte
}

// BidElectra is an interface that exposes the newly added execution requests on top of the builder bid
type BidElectra interface {
BidDeneb
ExecutionRequests() *v1.ExecutionRequests
}

type signedBuilderBid struct {
p *ethpb.SignedBuilderBid
}
Expand Down Expand Up @@ -115,11 +126,6 @@ func (b builderBid) Header() (interfaces.ExecutionData, error) {
return blocks.WrappedExecutionPayloadHeader(b.p.Header)
}

// BlobKzgCommitments --
func (b builderBid) BlobKzgCommitments() ([][]byte, error) {
return [][]byte{}, errors.New("blob kzg commitments not available before Deneb")
}

// Version --
func (b builderBid) Version() int {
return version.Bellatrix
Expand Down Expand Up @@ -169,11 +175,6 @@ func (b builderBidCapella) Header() (interfaces.ExecutionData, error) {
return blocks.WrappedExecutionPayloadHeaderCapella(b.p.Header)
}

// BlobKzgCommitments --
func (b builderBidCapella) BlobKzgCommitments() ([][]byte, error) {
return [][]byte{}, errors.New("blob kzg commitments not available before Deneb")
}

// Version --
func (b builderBidCapella) Version() int {
return version.Capella
Expand Down Expand Up @@ -254,8 +255,8 @@ func (b builderBidDeneb) Header() (interfaces.ExecutionData, error) {
}

// BlobKzgCommitments --
func (b builderBidDeneb) BlobKzgCommitments() ([][]byte, error) {
return b.p.BlobKzgCommitments, nil
func (b builderBidDeneb) BlobKzgCommitments() [][]byte {
return b.p.BlobKzgCommitments
}

type signedBuilderBidDeneb struct {
Expand Down Expand Up @@ -290,3 +291,95 @@ func (b signedBuilderBidDeneb) Version() int {
func (b signedBuilderBidDeneb) IsNil() bool {
return b.p == nil
}

type builderBidElectra struct {
p *ethpb.BuilderBidElectra
}

// WrappedBuilderBidElectra is a constructor which wraps a protobuf bid into an interface.
func WrappedBuilderBidElectra(p *ethpb.BuilderBidElectra) (Bid, error) {
w := builderBidElectra{p: p}
if w.IsNil() {
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}

// Version --
func (b builderBidElectra) Version() int {
return version.Electra
}

// Value --
func (b builderBidElectra) Value() primitives.Wei {
return primitives.LittleEndianBytesToWei(b.p.Value)
}

// Pubkey --
func (b builderBidElectra) Pubkey() []byte {
return b.p.Pubkey
}

// IsNil --
func (b builderBidElectra) IsNil() bool {
return b.p == nil
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
}

// HashTreeRoot --
func (b builderBidElectra) HashTreeRoot() ([32]byte, error) {
return b.p.HashTreeRoot()
}

// HashTreeRootWith --
func (b builderBidElectra) HashTreeRootWith(hh *ssz.Hasher) error {
return b.p.HashTreeRootWith(hh)
}

// Header --
func (b builderBidElectra) Header() (interfaces.ExecutionData, error) {
// We have to convert big endian to little endian because the value is coming from the execution layer.
return blocks.WrappedExecutionPayloadHeaderDeneb(b.p.Header)
}

// ExecutionRequests --
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we make this type of comment here instead of leaving a real valid comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's been this way for the entire file, was supposed to mean it's self explanatory

func (b builderBidElectra) ExecutionRequests() *v1.ExecutionRequests {
return b.p.ExecutionRequests // does not copy
}

// BlobKzgCommitments --
func (b builderBidElectra) BlobKzgCommitments() [][]byte {
return b.p.BlobKzgCommitments
}

type signedBuilderBidElectra struct {
p *ethpb.SignedBuilderBidElectra
}

// WrappedSignedBuilderBidElectra is a constructor which wraps a protobuf signed bit into an interface.
func WrappedSignedBuilderBidElectra(p *ethpb.SignedBuilderBidElectra) (SignedBid, error) {
w := signedBuilderBidElectra{p: p}
if w.IsNil() {
return nil, consensus_types.ErrNilObjectWrapped
}
return w, nil
}

// Message --
func (b signedBuilderBidElectra) Message() (Bid, error) {
return WrappedBuilderBidElectra(b.p.Message)
}

// Signature --
func (b signedBuilderBidElectra) Signature() []byte {
return b.p.Signature
}

// Version --
func (b signedBuilderBidElectra) Version() int {
return version.Electra
}

// IsNil --
func (b signedBuilderBidElectra) IsNil() bool {
return b.p == nil
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
}
28 changes: 22 additions & 6 deletions api/client/builder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,23 @@ func (c *Client) GetHeader(ctx context.Context, slot primitives.Slot, parentHash
if err := json.Unmarshal(hb, v); err != nil {
return nil, errors.Wrapf(err, "error unmarshaling the builder GetHeader response, using slot=%d, parentHash=%#x, pubkey=%#x", slot, parentHash, pubkey)
}
switch strings.ToLower(v.Version) {
case strings.ToLower(version.String(version.Deneb)):

ver, err := version.FromString(strings.ToLower(v.Version))
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("unsupported header version %s", strings.ToLower(v.Version)))
}
if ver >= version.Electra {
hr := &ExecHeaderResponseElectra{}
if err := json.Unmarshal(hb, hr); err != nil {
return nil, errors.Wrapf(err, "error unmarshaling the builder GetHeader response, using slot=%d, parentHash=%#x, pubkey=%#x", slot, parentHash, pubkey)
}
p, err := hr.ToProto()
if err != nil {
return nil, errors.Wrapf(err, "could not extract proto message from header")
}
return WrappedSignedBuilderBidElectra(p)
}
if ver >= version.Deneb {
hr := &ExecHeaderResponseDeneb{}
if err := json.Unmarshal(hb, hr); err != nil {
return nil, errors.Wrapf(err, "error unmarshaling the builder GetHeader response, using slot=%d, parentHash=%#x, pubkey=%#x", slot, parentHash, pubkey)
Expand All @@ -230,7 +245,8 @@ func (c *Client) GetHeader(ctx context.Context, slot primitives.Slot, parentHash
return nil, errors.Wrapf(err, "could not extract proto message from header")
}
return WrappedSignedBuilderBidDeneb(p)
case strings.ToLower(version.String(version.Capella)):
}
if ver >= version.Capella {
hr := &ExecHeaderResponseCapella{}
if err := json.Unmarshal(hb, hr); err != nil {
return nil, errors.Wrapf(err, "error unmarshaling the builder GetHeader response, using slot=%d, parentHash=%#x, pubkey=%#x", slot, parentHash, pubkey)
Expand All @@ -240,7 +256,8 @@ func (c *Client) GetHeader(ctx context.Context, slot primitives.Slot, parentHash
return nil, errors.Wrapf(err, "could not extract proto message from header")
}
return WrappedSignedBuilderBidCapella(p)
case strings.ToLower(version.String(version.Bellatrix)):
}
if ver >= version.Bellatrix {
hr := &ExecHeaderResponse{}
if err := json.Unmarshal(hb, hr); err != nil {
return nil, errors.Wrapf(err, "error unmarshaling the builder GetHeader response, using slot=%d, parentHash=%#x, pubkey=%#x", slot, parentHash, pubkey)
Expand All @@ -250,9 +267,8 @@ func (c *Client) GetHeader(ctx context.Context, slot primitives.Slot, parentHash
return nil, errors.Wrap(err, "could not extract proto message from header")
}
return WrappedSignedBuilderBid(p)
default:
return nil, fmt.Errorf("unsupported header version %s", strings.ToLower(v.Version))
}
return nil, fmt.Errorf("unsupported header version %s", strings.ToLower(v.Version))
}

// RegisterValidator encodes the SignedValidatorRegistrationV1 message to json (including hex-encoding the byte
Expand Down
50 changes: 47 additions & 3 deletions api/client/builder/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ func TestClient_GetHeader(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 0, value.Int.Cmp(primitives.WeiToBigInt(bid.Value())))
require.Equal(t, bidStr, primitives.WeiToBigInt(bid.Value()).String())

kcgCommitments, err := bid.BlobKzgCommitments()
require.NoError(t, err)
dbid, ok := bid.(builderBidDeneb)
require.Equal(t, true, ok)
kcgCommitments := dbid.BlobKzgCommitments()
require.Equal(t, len(kcgCommitments) > 0, true)
for i := range kcgCommitments {
require.Equal(t, len(kcgCommitments[i]) == 48, true)
Expand All @@ -292,6 +292,50 @@ func TestClient_GetHeader(t *testing.T) {
_, err := c.GetHeader(ctx, slot, bytesutil.ToBytes32(parentHash), bytesutil.ToBytes48(pubkey))
require.ErrorContains(t, "could not extract proto message from header: too many blob commitments: 7", err)
})
t.Run("electra", func(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should i add any more kinds of tests?

hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
require.Equal(t, expectedPath, r.URL.Path)
return &http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString(testExampleHeaderResponseElectra)),
Request: r.Clone(ctx),
}, nil
}),
}
c := &Client{
hc: hc,
baseURL: &url.URL{Host: "localhost:3500", Scheme: "http"},
}
h, err := c.GetHeader(ctx, slot, bytesutil.ToBytes32(parentHash), bytesutil.ToBytes48(pubkey))
require.NoError(t, err)
expectedWithdrawalsRoot := ezDecode(t, "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2")
bid, err := h.Message()
require.NoError(t, err)
bidHeader, err := bid.Header()
require.NoError(t, err)
withdrawalsRoot, err := bidHeader.WithdrawalsRoot()
require.NoError(t, err)
require.Equal(t, true, bytes.Equal(expectedWithdrawalsRoot, withdrawalsRoot))

bidStr := "652312848583266388373324160190187140051835877600158453279131187530910662656"
value, err := stringToUint256(bidStr)
require.NoError(t, err)
require.Equal(t, 0, value.Int.Cmp(primitives.WeiToBigInt(bid.Value())))
require.Equal(t, bidStr, primitives.WeiToBigInt(bid.Value()).String())
ebid, ok := bid.(builderBidElectra)
require.Equal(t, true, ok)
kcgCommitments := ebid.BlobKzgCommitments()
require.Equal(t, len(kcgCommitments) > 0, true)
for i := range kcgCommitments {
require.Equal(t, len(kcgCommitments[i]) == 48, true)
}
requests := ebid.ExecutionRequests()
require.Equal(t, 1, len(requests.Deposits))
require.Equal(t, 1, len(requests.Withdrawals))
require.Equal(t, 1, len(requests.Consolidations))

})
t.Run("unsupported version", func(t *testing.T) {
hc := &http.Client{
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
Expand Down
Loading
Loading