Skip to content

Commit

Permalink
Add Blob column to website (#576)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
avalonche and sukoneck authored Feb 1, 2024
1 parent 72fab1a commit d8a0d7b
Show file tree
Hide file tree
Showing 21 changed files with 346 additions and 175 deletions.
2 changes: 1 addition & 1 deletion common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var ValidPayloadRegisterValidator = builderApiV1.SignedValidatorRegistration{
"0xaf12df007a0c78abb5575067e5f8b089cfcc6227e4a91db7dd8cf517fe86fb944ead859f0781277d9b78c672e4a18c5d06368b603374673cf2007966cece9540f3a1b3f6f9e1bf421d779c4e8010368e6aac134649c7a009210780d401a778a5"),
}

func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2, version spec.DataVersion) *VersionedSubmitBlockRequest {
func TestBuilderSubmitBlockRequest(sk *bls.SecretKey, bid *BidTraceV2WithBlobFields, version spec.DataVersion) *VersionedSubmitBlockRequest {
signature, err := ssz.SignMessage(bid, ssz.DomainBuilder, sk)
check(err, " SignMessage: ", bid, sk)
if version == spec.DataVersionDeneb {
Expand Down
88 changes: 78 additions & 10 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"
boostSsz "github.com/flashbots/go-boost-utils/ssz"
"github.com/holiman/uint256"
)

var (
Expand Down Expand Up @@ -194,8 +194,8 @@ type BuilderGetValidatorsResponseEntry struct {

type BidTraceV2 struct {
builderApiV1.BidTrace
BlockNumber uint64 `db:"block_number" json:"block_number,string"`
NumTx uint64 `db:"num_tx" json:"num_tx,string"`
BlockNumber uint64 `db:"block_number" json:"block_number,string"`
NumTx uint64 `db:"num_tx" json:"num_tx,string"`
}

type BidTraceV2JSON struct {
Expand Down Expand Up @@ -326,25 +326,93 @@ func (b *BidTraceV2WithTimestampJSON) ToCSVRecord() []string {
}
}

type BidTraceV2WithBlobFields struct {
builderApiV1.BidTrace
BlockNumber uint64 `db:"block_number" json:"block_number,string"`
NumTx uint64 `db:"num_tx" json:"num_tx,string"`
NumBlobs uint64 `db:"num_blobs" json:"num_blobs,string"`
BlobGasUsed uint64 `db:"blob_gas_used" json:"blob_gas_used,string"`
ExcessBlobGas uint64 `db:"excess_blob_gas" json:"excess_blob_gas,string"`
}

type BidTraceV2WithBlobFieldsJSON struct {
Slot uint64 `json:"slot,string"`
ParentHash string `json:"parent_hash"`
BlockHash string `json:"block_hash"`
BuilderPubkey string `json:"builder_pubkey"`
ProposerPubkey string `json:"proposer_pubkey"`
ProposerFeeRecipient string `json:"proposer_fee_recipient"`
GasLimit uint64 `json:"gas_limit,string"`
GasUsed uint64 `json:"gas_used,string"`
Value string `json:"value"`
NumTx uint64 `json:"num_tx,string"`
BlockNumber uint64 `json:"block_number,string"`
NumBlobs uint64 `json:"num_blobs,string"`
BlobGasUsed uint64 `json:"blob_gas_used,string"`
ExcessBlobGas uint64 `json:"excess_blob_gas,string"`
}

func (b BidTraceV2WithBlobFields) MarshalJSON() ([]byte, error) {
return json.Marshal(&BidTraceV2WithBlobFieldsJSON{
Slot: b.Slot,
ParentHash: b.ParentHash.String(),
BlockHash: b.BlockHash.String(),
BuilderPubkey: b.BuilderPubkey.String(),
ProposerPubkey: b.ProposerPubkey.String(),
ProposerFeeRecipient: b.ProposerFeeRecipient.String(),
GasLimit: b.GasLimit,
GasUsed: b.GasUsed,
Value: b.Value.ToBig().String(),
NumTx: b.NumTx,
BlockNumber: b.BlockNumber,
NumBlobs: b.NumBlobs,
BlobGasUsed: b.BlobGasUsed,
ExcessBlobGas: b.ExcessBlobGas,
})
}

func (b *BidTraceV2WithBlobFields) UnmarshalJSON(data []byte) error {
params := &struct {
NumTx uint64 `json:"num_tx,string"`
BlockNumber uint64 `json:"block_number,string"`
NumBlobs uint64 `json:"num_blobs,string"`
BlobGasUsed uint64 `json:"blob_gas_used,string"`
ExcessBlobGas uint64 `json:"excess_blob_gas,string"`
}{}
err := json.Unmarshal(data, params)
if err != nil {
return err
}
b.NumTx = params.NumTx
b.BlockNumber = params.BlockNumber
b.NumBlobs = params.NumBlobs
b.BlobGasUsed = params.BlobGasUsed
b.ExcessBlobGas = params.ExcessBlobGas

bidTrace := new(builderApiV1.BidTrace)
err = json.Unmarshal(data, bidTrace)
if err != nil {
return err
}
b.BidTrace = *bidTrace
return nil
}

type BlockSubmissionInfo struct {
BidTrace *builderApiV1.BidTrace
Slot uint64
BlockHash phase0.Hash32
ParentHash phase0.Hash32
ExecutionPayloadBlockHash phase0.Hash32
ExecutionPayloadParentHash phase0.Hash32
Builder phase0.BLSPubKey
Proposer phase0.BLSPubKey
ProposerFeeRecipient bellatrix.ExecutionAddress
GasUsed uint64
GasLimit uint64
Timestamp uint64
BlockNumber uint64
Value *uint256.Int
PrevRandao phase0.Hash32
Signature phase0.BLSSignature
Transactions []bellatrix.Transaction
Withdrawals []*capella.Withdrawal
Blobs []deneb.Blob
BlobGasUsed uint64
ExcessBlobGas uint64
}

/*
Expand Down
56 changes: 38 additions & 18 deletions common/types_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
builderApi "github.com/attestantio/go-builder-client/api"
builderApiCapella "github.com/attestantio/go-builder-client/api/capella"
builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb"
builderApiV1 "github.com/attestantio/go-builder-client/api/v1"
builderSpec "github.com/attestantio/go-builder-client/spec"
eth2Api "github.com/attestantio/go-eth2-client/api"
eth2ApiV1Capella "github.com/attestantio/go-eth2-client/api/v1/capella"
Expand Down Expand Up @@ -232,28 +233,47 @@ func DenebUnblindSignedBlock(blindedBlock *eth2ApiV1Deneb.SignedBlindedBeaconBlo

type BuilderBlockValidationRequest struct {
*VersionedSubmitBlockRequest
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
ParentBeaconBlockRoot *phase0.Root `json:"parent_beacon_block_root,omitempty"`
RegisteredGasLimit uint64
ParentBeaconBlockRoot *phase0.Root
}

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

attrs, err := json.Marshal(&struct {
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
ParentBeaconBlockRoot *phase0.Root `json:"parent_beacon_block_root,omitempty"`
}{
RegisteredGasLimit: r.RegisteredGasLimit,
ParentBeaconBlockRoot: r.ParentBeaconBlockRoot,
})
if err != nil {
return nil, err
type denebBuilderBlockValidationRequestJSON struct {
Message *builderApiV1.BidTrace `json:"message"`
ExecutionPayload *deneb.ExecutionPayload `json:"execution_payload"`
BlobsBundle *builderApiDeneb.BlobsBundle `json:"blobs_bundle"`
Signature string `json:"signature"`
RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
ParentBeaconBlockRoot string `json:"parent_beacon_block_root"`
}

func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error) {
switch r.Version { //nolint:exhaustive
case spec.DataVersionCapella:
return json.Marshal(&capellaBuilderBlockValidationRequestJSON{
Message: r.Capella.Message,
ExecutionPayload: r.Capella.ExecutionPayload,
Signature: r.Capella.Signature.String(),
RegisteredGasLimit: r.RegisteredGasLimit,
})
case spec.DataVersionDeneb:
return json.Marshal(&denebBuilderBlockValidationRequestJSON{
Message: r.Deneb.Message,
ExecutionPayload: r.Deneb.ExecutionPayload,
BlobsBundle: r.Deneb.BlobsBundle,
Signature: r.Deneb.Signature.String(),
RegisteredGasLimit: r.RegisteredGasLimit,
ParentBeaconBlockRoot: r.ParentBeaconBlockRoot.String(),
})
default:
return nil, errors.Wrap(ErrInvalidVersion, fmt.Sprintf("%s is not supported", r.Version))
}
attrs[0] = ','
return append(blockRequest[:len(blockRequest)-1], attrs...), nil
}

type VersionedSubmitBlockRequest struct {
Expand Down
50 changes: 15 additions & 35 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
builderApi "github.com/attestantio/go-builder-client/api"
builderApiDeneb "github.com/attestantio/go-builder-client/api/deneb"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -190,18 +191,6 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
if err != nil {
return nil, err
}
slot, err := submission.Slot()
if err != nil {
return nil, err
}
blockHash, err := submission.BlockHash()
if err != nil {
return nil, err
}
parentHash, err := submission.ParentHash()
if err != nil {
return nil, err
}
executionPayloadBlockHash, err := submission.ExecutionPayloadBlockHash()
if err != nil {
return nil, err
Expand All @@ -210,18 +199,6 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
if err != nil {
return nil, err
}
builder, err := submission.Builder()
if err != nil {
return nil, err
}
proposerPubkey, err := submission.ProposerPubKey()
if err != nil {
return nil, err
}
proposerFeeRecipient, err := submission.ProposerFeeRecipient()
if err != nil {
return nil, err
}
gasUsed, err := submission.GasUsed()
if err != nil {
return nil, err
Expand All @@ -238,10 +215,6 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
if err != nil {
return nil, err
}
value, err := submission.Value()
if err != nil {
return nil, err
}
blockNumber, err := submission.BlockNumber()
if err != nil {
return nil, err
Expand All @@ -254,25 +227,32 @@ func GetBlockSubmissionInfo(submission *VersionedSubmitBlockRequest) (*BlockSubm
if err != nil {
return nil, err
}
// TODO (deneb): after deneb fork error if no blob fields
var (
blobs []deneb.Blob
blobGasUsed uint64
excessBlobGas uint64
)
if submission.Version == spec.DataVersionDeneb {
blobs = submission.Deneb.BlobsBundle.Blobs
blobGasUsed = submission.Deneb.ExecutionPayload.BlobGasUsed
excessBlobGas = submission.Deneb.ExecutionPayload.ExcessBlobGas
}
return &BlockSubmissionInfo{
BidTrace: bidTrace,
Signature: signature,
Slot: slot,
BlockHash: blockHash,
ParentHash: parentHash,
ExecutionPayloadBlockHash: executionPayloadBlockHash,
ExecutionPayloadParentHash: executionPayloadParentHash,
Builder: builder,
Proposer: proposerPubkey,
ProposerFeeRecipient: proposerFeeRecipient,
GasUsed: gasUsed,
GasLimit: gasLimit,
Timestamp: timestamp,
Transactions: txs,
Value: value,
PrevRandao: prevRandao,
BlockNumber: blockNumber,
Withdrawals: withdrawals,
Blobs: blobs,
BlobGasUsed: blobGasUsed,
ExcessBlobGas: excessBlobGas,
}, nil
}

Expand Down
Loading

0 comments on commit d8a0d7b

Please sign in to comment.