-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Builder: Electra #14344
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
Changes from 61 commits
d0522ac
9269e0e
1ed404c
592a45a
512e388
bfae0ca
d8b98d7
dbc55c9
2521755
9c8d26e
734ef94
066ce6a
67235fb
6d580ec
c67df35
6d1a9fa
d5f8e02
2c907b2
289bb52
1c4be98
45c1d0b
c1a93d8
802a68b
0aae98d
1adc957
759b819
35e8541
a5cea41
9cdb111
b409a59
6c6b582
c5e8c82
174ba31
504db9f
4c2dbbb
add6015
3982901
91aa1b3
c0d01ea
8cef6df
a47bd35
e6a404e
89b8358
3a837b0
b7d6bcd
96ed501
e85d6e7
18738bf
4ac326e
46c55fc
6277a1b
1e74eeb
70ff336
2726f7a
5bbbad6
1cd3a71
cfd65c0
fbf7aae
e0c5034
6ec4a0f
6595008
b8aa910
2a29e0f
08def54
03f5754
7ab30bd
40c180e
f9483ef
2ac5089
ac64d37
73d2b5b
ab16642
4c40f18
15199e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| ) | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| } | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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 { | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
| // 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 -- | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -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) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.