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

expose eligible_at and signed_at in data api #359

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions cmd/tool/export-data-api-payloads-bids.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ var DataAPIExportBids = &cobra.Command{
}

log.Infof("got %d bids", len(bids))
entries := make([]common.BidTraceV2WithTimestampJSON, len(bids))
entries := make([]common.BidTraceV3JSON, len(bids))
for i, bid := range bids {
entries[i] = database.BuilderSubmissionEntryToBidTraceV2WithTimestampJSON(bid)
entries[i] = database.BuilderSubmissionEntryToBidTraceV3JSON(bid)
}

if len(entries) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tool/export-data-api-payloads-delivered.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ var DataAPIExportPayloads = &cobra.Command{
}

log.Infof("got %d payloads", len(deliveredPayloads))
entries := make([]common.BidTraceV2JSON, len(deliveredPayloads))
entries := make([]common.BidTraceV3JSON, len(deliveredPayloads))
for i, payload := range deliveredPayloads {
entries[i] = database.DeliveredPayloadEntryToBidTraceV2JSON(payload)
entries[i] = database.DeliveredPayloadEntryToBidTraceV3JSON(payload)
}

if len(entries) == 0 {
Expand Down
58 changes: 58 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,64 @@ func (b *BidTraceV2WithTimestampJSON) ToCSVRecord() []string {
}
}

type BidTraceV3JSON 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"`
Timestamp int64 `json:"timestamp,string,omitempty"`
TimestampMs int64 `json:"timestamp_ms,string,omitempty"`
EligibleAtTimestampMs int64 `json:"eligible_at_timestamp_ms,string,omitempty"`
SignedAtTimestampMs int64 `json:"signed_at_timestamp_ms,string,omitempty"`
}

func (b *BidTraceV3JSON) CSVHeader() []string {
return []string{
"slot",
"parent_hash",
"block_hash",
"builder_pubkey",
"proposer_pubkey",
"proposer_fee_recipient",
"gas_limit",
"gas_used",
"value",
"num_tx",
"block_number",
"timestamp",
"timestamp_ms",
"eligible_at_timestamp_ms",
"signed_at_timestamp_ms",
}
}

func (b *BidTraceV3JSON) ToCSVRecord() []string {
return []string{
fmt.Sprint(b.Slot),
b.ParentHash,
b.BlockHash,
b.BuilderPubkey,
b.ProposerPubkey,
b.ProposerFeeRecipient,
fmt.Sprint(b.GasLimit),
fmt.Sprint(b.GasUsed),
b.Value,
fmt.Sprint(b.NumTx),
fmt.Sprint(b.BlockNumber),
fmt.Sprint(b.Timestamp),
fmt.Sprint(b.TimestampMs),
fmt.Sprint(b.EligibleAtTimestampMs),
fmt.Sprint(b.SignedAtTimestampMs),
}
}

type SignedBlindedBeaconBlock struct {
Bellatrix *boostTypes.SignedBlindedBeaconBlock
Capella *apiv1capella.SignedBlindedBeaconBlock
Expand Down
57 changes: 57 additions & 0 deletions database/typesconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,60 @@ func ExecutionPayloadEntryToExecutionPayload(executionPayloadEntry *ExecutionPay
return nil, ErrUnsupportedExecutionPayload
}
}

func DeliveredPayloadEntryToBidTraceV3JSON(payload *DeliveredPayloadEntry) common.BidTraceV3JSON {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it'll be great if there's tests for these for json marshal and unmarshalling

bidTrace := common.BidTraceV3JSON{
Slot: payload.Slot,
ParentHash: payload.ParentHash,
BlockHash: payload.BlockHash,
BuilderPubkey: payload.BuilderPubkey,
ProposerPubkey: payload.ProposerPubkey,
ProposerFeeRecipient: payload.ProposerFeeRecipient,
GasLimit: payload.GasLimit,
GasUsed: payload.GasUsed,
Value: payload.Value,
NumTx: payload.NumTx,
BlockNumber: payload.BlockNumber,
Timestamp: int64(0),
TimestampMs: int64(0),
SignedAtTimestampMs: int64(0),
EligibleAtTimestampMs: int64(0),
}

if payload.SignedAt.Valid {
bidTrace.SignedAtTimestampMs = payload.SignedAt.Time.UnixMilli()
}

return bidTrace
}

func BuilderSubmissionEntryToBidTraceV3JSON(payload *BuilderBlockSubmissionEntry) common.BidTraceV3JSON {
timestamp := payload.InsertedAt
if payload.ReceivedAt.Valid {
timestamp = payload.ReceivedAt.Time
}

bidtrace := common.BidTraceV3JSON{
Timestamp: timestamp.Unix(),
TimestampMs: timestamp.UnixMilli(),
Slot: payload.Slot,
ParentHash: payload.ParentHash,
BlockHash: payload.BlockHash,
BuilderPubkey: payload.BuilderPubkey,
ProposerPubkey: payload.ProposerPubkey,
ProposerFeeRecipient: payload.ProposerFeeRecipient,
GasLimit: payload.GasLimit,
GasUsed: payload.GasUsed,
Value: payload.Value,
NumTx: payload.NumTx,
BlockNumber: payload.BlockNumber,
EligibleAtTimestampMs: int64(0),
SignedAtTimestampMs: int64(0),
}

if payload.EligibleAt.Valid {
bidtrace.EligibleAtTimestampMs = payload.EligibleAt.Time.UnixMilli()
}

return bidtrace
}
8 changes: 4 additions & 4 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2102,9 +2102,9 @@ func (api *RelayAPI) handleDataProposerPayloadDelivered(w http.ResponseWriter, r
return
}

response := make([]common.BidTraceV2JSON, len(deliveredPayloads))
response := make([]common.BidTraceV3JSON, len(deliveredPayloads))
for i, payload := range deliveredPayloads {
response[i] = database.DeliveredPayloadEntryToBidTraceV2JSON(payload)
response[i] = database.DeliveredPayloadEntryToBidTraceV3JSON(payload)
}

api.RespondOK(w, response)
Expand Down Expand Up @@ -2187,9 +2187,9 @@ func (api *RelayAPI) handleDataBuilderBidsReceived(w http.ResponseWriter, req *h
return
}

response := make([]common.BidTraceV2WithTimestampJSON, len(blockSubmissions))
response := make([]common.BidTraceV3JSON, len(blockSubmissions))
for i, payload := range blockSubmissions {
response[i] = database.BuilderSubmissionEntryToBidTraceV2WithTimestampJSON(payload)
response[i] = database.BuilderSubmissionEntryToBidTraceV3JSON(payload)
}

api.RespondOK(w, response)
Expand Down
Loading