Skip to content

Commit d8a0d7b

Browse files
avalonchesukoneck
andauthored
Add Blob column to website (#576)
* Add blobs column to website * add default * add marshalling for blob fields * marshalling block validation request * slim column name * fix icon in website (#578) replace website etherscan url with svg --------- Co-authored-by: sukoneck <[email protected]>
1 parent 72fab1a commit d8a0d7b

21 files changed

+346
-175
lines changed

common/test_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var ValidPayloadRegisterValidator = builderApiV1.SignedValidatorRegistration{
7878
"0xaf12df007a0c78abb5575067e5f8b089cfcc6227e4a91db7dd8cf517fe86fb944ead859f0781277d9b78c672e4a18c5d06368b603374673cf2007966cece9540f3a1b3f6f9e1bf421d779c4e8010368e6aac134649c7a009210780d401a778a5"),
7979
}
8080

81-
func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2, version spec.DataVersion) *VersionedSubmitBlockRequest {
81+
func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2WithBlobFields, version spec.DataVersion) *VersionedSubmitBlockRequest {
8282
signature, err := ssz.SignMessage(bid, ssz.DomainBuilder, sk)
8383
check(err, " SignMessage: ", bid, sk)
8484
if version == spec.DataVersionDeneb {

common/types.go

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
1111
"github.com/attestantio/go-eth2-client/spec/bellatrix"
1212
"github.com/attestantio/go-eth2-client/spec/capella"
13+
"github.com/attestantio/go-eth2-client/spec/deneb"
1314
"github.com/attestantio/go-eth2-client/spec/phase0"
1415
ssz "github.com/ferranbt/fastssz"
1516
boostSsz "github.com/flashbots/go-boost-utils/ssz"
16-
"github.com/holiman/uint256"
1717
)
1818

1919
var (
@@ -194,8 +194,8 @@ type BuilderGetValidatorsResponseEntry struct {
194194

195195
type BidTraceV2 struct {
196196
builderApiV1.BidTrace
197-
BlockNumber uint64 `db:"block_number" json:"block_number,string"`
198-
NumTx uint64 `db:"num_tx" json:"num_tx,string"`
197+
BlockNumber uint64 `db:"block_number" json:"block_number,string"`
198+
NumTx uint64 `db:"num_tx" json:"num_tx,string"`
199199
}
200200

201201
type BidTraceV2JSON struct {
@@ -326,25 +326,93 @@ func (b *BidTraceV2WithTimestampJSON) ToCSVRecord() []string {
326326
}
327327
}
328328

329+
type BidTraceV2WithBlobFields struct {
330+
builderApiV1.BidTrace
331+
BlockNumber uint64 `db:"block_number" json:"block_number,string"`
332+
NumTx uint64 `db:"num_tx" json:"num_tx,string"`
333+
NumBlobs uint64 `db:"num_blobs" json:"num_blobs,string"`
334+
BlobGasUsed uint64 `db:"blob_gas_used" json:"blob_gas_used,string"`
335+
ExcessBlobGas uint64 `db:"excess_blob_gas" json:"excess_blob_gas,string"`
336+
}
337+
338+
type BidTraceV2WithBlobFieldsJSON struct {
339+
Slot uint64 `json:"slot,string"`
340+
ParentHash string `json:"parent_hash"`
341+
BlockHash string `json:"block_hash"`
342+
BuilderPubkey string `json:"builder_pubkey"`
343+
ProposerPubkey string `json:"proposer_pubkey"`
344+
ProposerFeeRecipient string `json:"proposer_fee_recipient"`
345+
GasLimit uint64 `json:"gas_limit,string"`
346+
GasUsed uint64 `json:"gas_used,string"`
347+
Value string `json:"value"`
348+
NumTx uint64 `json:"num_tx,string"`
349+
BlockNumber uint64 `json:"block_number,string"`
350+
NumBlobs uint64 `json:"num_blobs,string"`
351+
BlobGasUsed uint64 `json:"blob_gas_used,string"`
352+
ExcessBlobGas uint64 `json:"excess_blob_gas,string"`
353+
}
354+
355+
func (b BidTraceV2WithBlobFields) MarshalJSON() ([]byte, error) {
356+
return json.Marshal(&BidTraceV2WithBlobFieldsJSON{
357+
Slot: b.Slot,
358+
ParentHash: b.ParentHash.String(),
359+
BlockHash: b.BlockHash.String(),
360+
BuilderPubkey: b.BuilderPubkey.String(),
361+
ProposerPubkey: b.ProposerPubkey.String(),
362+
ProposerFeeRecipient: b.ProposerFeeRecipient.String(),
363+
GasLimit: b.GasLimit,
364+
GasUsed: b.GasUsed,
365+
Value: b.Value.ToBig().String(),
366+
NumTx: b.NumTx,
367+
BlockNumber: b.BlockNumber,
368+
NumBlobs: b.NumBlobs,
369+
BlobGasUsed: b.BlobGasUsed,
370+
ExcessBlobGas: b.ExcessBlobGas,
371+
})
372+
}
373+
374+
func (b *BidTraceV2WithBlobFields) UnmarshalJSON(data []byte) error {
375+
params := &struct {
376+
NumTx uint64 `json:"num_tx,string"`
377+
BlockNumber uint64 `json:"block_number,string"`
378+
NumBlobs uint64 `json:"num_blobs,string"`
379+
BlobGasUsed uint64 `json:"blob_gas_used,string"`
380+
ExcessBlobGas uint64 `json:"excess_blob_gas,string"`
381+
}{}
382+
err := json.Unmarshal(data, params)
383+
if err != nil {
384+
return err
385+
}
386+
b.NumTx = params.NumTx
387+
b.BlockNumber = params.BlockNumber
388+
b.NumBlobs = params.NumBlobs
389+
b.BlobGasUsed = params.BlobGasUsed
390+
b.ExcessBlobGas = params.ExcessBlobGas
391+
392+
bidTrace := new(builderApiV1.BidTrace)
393+
err = json.Unmarshal(data, bidTrace)
394+
if err != nil {
395+
return err
396+
}
397+
b.BidTrace = *bidTrace
398+
return nil
399+
}
400+
329401
type BlockSubmissionInfo struct {
330402
BidTrace *builderApiV1.BidTrace
331-
Slot uint64
332-
BlockHash phase0.Hash32
333-
ParentHash phase0.Hash32
334403
ExecutionPayloadBlockHash phase0.Hash32
335404
ExecutionPayloadParentHash phase0.Hash32
336-
Builder phase0.BLSPubKey
337-
Proposer phase0.BLSPubKey
338-
ProposerFeeRecipient bellatrix.ExecutionAddress
339405
GasUsed uint64
340406
GasLimit uint64
341407
Timestamp uint64
342408
BlockNumber uint64
343-
Value *uint256.Int
344409
PrevRandao phase0.Hash32
345410
Signature phase0.BLSSignature
346411
Transactions []bellatrix.Transaction
347412
Withdrawals []*capella.Withdrawal
413+
Blobs []deneb.Blob
414+
BlobGasUsed uint64
415+
ExcessBlobGas uint64
348416
}
349417

350418
/*

common/types_spec.go

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
builderApi "github.com/attestantio/go-builder-client/api"
88
builderApiCapella "github.com/attestantio/go-builder-client/api/capella"
99
builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb"
10+
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
1011
builderSpec "github.com/attestantio/go-builder-client/spec"
1112
eth2Api "github.com/attestantio/go-eth2-client/api"
1213
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
@@ -232,28 +233,47 @@ func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlo
232233

233234
type BuilderBlockValidationRequest struct {
234235
*VersionedSubmitBlockRequest
235-
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
236-
ParentBeaconBlockRoot *phase0.Root `json:"parent_beacon_block_root,omitempty"`
236+
RegisteredGasLimit uint64
237+
ParentBeaconBlockRoot *phase0.Root
237238
}
238239

239-
func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) {
240-
blockRequest, err := json.Marshal(r.VersionedSubmitBlockRequest)
241-
if err != nil {
242-
return nil, err
243-
}
240+
type capellaBuilderBlockValidationRequestJSON struct {
241+
Message *builderApiV1.BidTrace `json:"message"`
242+
ExecutionPayload *capella.ExecutionPayload `json:"execution_payload"`
243+
Signature string `json:"signature"`
244+
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
245+
}
244246

245-
attrs, err := json.Marshal(&struct {
246-
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
247-
ParentBeaconBlockRoot *phase0.Root `json:"parent_beacon_block_root,omitempty"`
248-
}{
249-
RegisteredGasLimit: r.RegisteredGasLimit,
250-
ParentBeaconBlockRoot: r.ParentBeaconBlockRoot,
251-
})
252-
if err != nil {
253-
return nil, err
247+
type denebBuilderBlockValidationRequestJSON struct {
248+
Message *builderApiV1.BidTrace `json:"message"`
249+
ExecutionPayload *deneb.ExecutionPayload `json:"execution_payload"`
250+
BlobsBundle *builderApiDeneb.BlobsBundle `json:"blobs_bundle"`
251+
Signature string `json:"signature"`
252+
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
253+
ParentBeaconBlockRoot string `json:"parent_beacon_block_root"`
254+
}
255+
256+
func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) {
257+
switch r.Version { //nolint:exhaustive
258+
case spec.DataVersionCapella:
259+
return json.Marshal(&capellaBuilderBlockValidationRequestJSON{
260+
Message: r.Capella.Message,
261+
ExecutionPayload: r.Capella.ExecutionPayload,
262+
Signature: r.Capella.Signature.String(),
263+
RegisteredGasLimit: r.RegisteredGasLimit,
264+
})
265+
case spec.DataVersionDeneb:
266+
return json.Marshal(&denebBuilderBlockValidationRequestJSON{
267+
Message: r.Deneb.Message,
268+
ExecutionPayload: r.Deneb.ExecutionPayload,
269+
BlobsBundle: r.Deneb.BlobsBundle,
270+
Signature: r.Deneb.Signature.String(),
271+
RegisteredGasLimit: r.RegisteredGasLimit,
272+
ParentBeaconBlockRoot: r.ParentBeaconBlockRoot.String(),
273+
})
274+
default:
275+
return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%s is not supported", r.Version))
254276
}
255-
attrs[0] = ','
256-
return append(blockRequest[:len(blockRequest)-1], attrs...), nil
257277
}
258278

259279
type VersionedSubmitBlockRequest struct {

common/utils.go

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
builderApi "github.com/attestantio/go-builder-client/api"
1818
builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb"
1919
"github.com/attestantio/go-eth2-client/spec"
20+
"github.com/attestantio/go-eth2-client/spec/deneb"
2021
"github.com/attestantio/go-eth2-client/spec/phase0"
2122
ethcommon "github.com/ethereum/go-ethereum/common"
2223
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -190,18 +191,6 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
190191
if err != nil {
191192
return nil, err
192193
}
193-
slot, err := submission.Slot()
194-
if err != nil {
195-
return nil, err
196-
}
197-
blockHash, err := submission.BlockHash()
198-
if err != nil {
199-
return nil, err
200-
}
201-
parentHash, err := submission.ParentHash()
202-
if err != nil {
203-
return nil, err
204-
}
205194
executionPayloadBlockHash, err := submission.ExecutionPayloadBlockHash()
206195
if err != nil {
207196
return nil, err
@@ -210,18 +199,6 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
210199
if err != nil {
211200
return nil, err
212201
}
213-
builder, err := submission.Builder()
214-
if err != nil {
215-
return nil, err
216-
}
217-
proposerPubkey, err := submission.ProposerPubKey()
218-
if err != nil {
219-
return nil, err
220-
}
221-
proposerFeeRecipient, err := submission.ProposerFeeRecipient()
222-
if err != nil {
223-
return nil, err
224-
}
225202
gasUsed, err := submission.GasUsed()
226203
if err != nil {
227204
return nil, err
@@ -238,10 +215,6 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
238215
if err != nil {
239216
return nil, err
240217
}
241-
value, err := submission.Value()
242-
if err != nil {
243-
return nil, err
244-
}
245218
blockNumber, err := submission.BlockNumber()
246219
if err != nil {
247220
return nil, err
@@ -254,25 +227,32 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
254227
if err != nil {
255228
return nil, err
256229
}
230+
// TODO (deneb): after deneb fork error if no blob fields
231+
var (
232+
blobs []deneb.Blob
233+
blobGasUsed uint64
234+
excessBlobGas uint64
235+
)
236+
if submission.Version == spec.DataVersionDeneb {
237+
blobs = submission.Deneb.BlobsBundle.Blobs
238+
blobGasUsed = submission.Deneb.ExecutionPayload.BlobGasUsed
239+
excessBlobGas = submission.Deneb.ExecutionPayload.ExcessBlobGas
240+
}
257241
return &BlockSubmissionInfo{
258242
BidTrace: bidTrace,
259243
Signature: signature,
260-
Slot: slot,
261-
BlockHash: blockHash,
262-
ParentHash: parentHash,
263244
ExecutionPayloadBlockHash: executionPayloadBlockHash,
264245
ExecutionPayloadParentHash: executionPayloadParentHash,
265-
Builder: builder,
266-
Proposer: proposerPubkey,
267-
ProposerFeeRecipient: proposerFeeRecipient,
268246
GasUsed: gasUsed,
269247
GasLimit: gasLimit,
270248
Timestamp: timestamp,
271249
Transactions: txs,
272-
Value: value,
273250
PrevRandao: prevRandao,
274251
BlockNumber: blockNumber,
275252
Withdrawals: withdrawals,
253+
Blobs: blobs,
254+
BlobGasUsed: blobGasUsed,
255+
ExcessBlobGas: excessBlobGas,
276256
}, nil
277257
}
278258

0 commit comments

Comments
 (0)