-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathtypes.go
More file actions
128 lines (106 loc) · 4.78 KB
/
types.go
File metadata and controls
128 lines (106 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2025, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.
package preconf
import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
engineprimitives "github.com/berachain/beacon-kit/engine-primitives/engine-primitives"
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/primitives/math"
)
const (
// HealthEndpoint is the API endpoint for checking server liveness.
HealthEndpoint = "/eth/v1/preconf/health"
// PayloadEndpoint is the API endpoint for fetching/serving preconf payloads.
PayloadEndpoint = "/eth/v1/preconf/payload"
)
// GetPayloadRequest is the request body for the GetPayload endpoint.
type GetPayloadRequest struct {
// Slot is the slot number for which to retrieve the payload.
Slot math.Slot `json:"slot"`
// ParentBlockRoot is the parent block root used to look up the cached payload.
ParentBlockRoot common.Root `json:"parent_block_root"`
}
// GetPayloadResponse is the response body for the GetPayload endpoint.
type GetPayloadResponse struct {
// ForkVersion is the fork version of the payload.
// This is needed because the Versionable field is not JSON-serialized.
ForkVersion common.Version `json:"fork_version"`
// ExecutionPayload is the execution payload for the requested slot.
ExecutionPayload *ctypes.ExecutionPayload `json:"execution_payload"`
// BlobsBundle contains the blobs, commitments, and proofs.
BlobsBundle *engineprimitives.BlobsBundleV1 `json:"blobs_bundle"`
// BlockValue is the Wei value of the block.
BlockValue *math.U256 `json:"block_value"`
// ExecutionRequests contains the encoded execution requests (Electra+).
ExecutionRequests []ctypes.EncodedExecutionRequest `json:"execution_requests"`
}
// ToExecutionPayloadEnvelope converts the response to a BuiltExecutionPayloadEnv.
// This method sets the Versionable field which is not JSON-serialized.
func (r *GetPayloadResponse) ToExecutionPayloadEnvelope() ctypes.BuiltExecutionPayloadEnv {
// Set the Versionable field from the serialized fork version
if r.ExecutionPayload != nil {
r.ExecutionPayload.Versionable = ctypes.NewVersionable(r.ForkVersion)
}
blobsBundle := r.BlobsBundle
if blobsBundle == nil {
blobsBundle = &engineprimitives.BlobsBundleV1{}
}
return ctypes.NewExecutionPayloadEnvelope[*engineprimitives.BlobsBundleV1](
r.ExecutionPayload,
blobsBundle,
r.ExecutionRequests,
)
}
// NewGetPayloadResponseFromEnvelope creates a GetPayloadResponse from a BuiltExecutionPayloadEnv.
func NewGetPayloadResponseFromEnvelope(env ctypes.BuiltExecutionPayloadEnv) *GetPayloadResponse {
// Type assert blobs bundle to concrete type (nil-safe: assertion returns nil if input is nil)
blobsBundle, _ := env.GetBlobsBundle().(*engineprimitives.BlobsBundleV1)
var forkVersion common.Version
if payload := env.GetExecutionPayload(); payload != nil {
forkVersion = payload.GetForkVersion()
}
return &GetPayloadResponse{
ForkVersion: forkVersion,
ExecutionPayload: env.GetExecutionPayload(),
BlobsBundle: blobsBundle,
BlockValue: env.GetBlockValue(),
ExecutionRequests: env.GetEncodedExecutionRequests(),
}
}
// HealthResponse is the response body for the health endpoint.
type HealthResponse struct {
// IsReady indicates whether the node has committed at least one block.
IsReady bool `json:"is_ready"`
// IsSyncing indicates whether the node is still catching up with the chain.
IsSyncing bool `json:"is_syncing"`
// ELConnected indicates whether the execution-layer client is reachable.
ELConnected bool `json:"el_connected"`
// HeadSlot is the latest committed block height.
HeadSlot int64 `json:"head_slot"`
// SyncDistance is the number of slots remaining until the node is synced.
SyncDistance int64 `json:"sync_distance"`
}
// ErrorResponse is the error response body.
type ErrorResponse struct {
// Code is the error code.
Code int `json:"code"`
// Message is the error message.
Message string `json:"message"`
}