Skip to content

Commit e1f82a6

Browse files
authored
Merge pull request #2 from sigp/top-bid-ws-stream
Top bid ws stream
2 parents abe695b + 5a6f5f2 commit e1f82a6

File tree

8 files changed

+411
-232
lines changed

8 files changed

+411
-232
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ members = [
1111

1212
[workspace.dependencies]
1313
async-trait = "0.1"
14-
axum = "0.7"
14+
axum = { version = "0.7", features = ["ws"] }
1515
bytes = "1.6"
1616
eth2 = { git = "https://github.com/realbigsean/lighthouse.git", rev = "10ce60633859ab4f20308ef42bb88e219e09fee5" }
1717
ethereum_serde_utils = "0.5.2"
1818
ethereum_ssz = "0.5.4"
1919
ethereum_ssz_derive = "0.5.4"
20+
futures = "0.3.30"
2021
http = "1"
2122
reqwest = { version = "0.12.5", features = ["json"] }
2223
serde = { version = "1.0", features = ["derive"] }
2324
serde_json = { version = "1", features = ["raw_value"] }
2425
superstruct = "0.8"
2526
tokio = { version = "1", default-features = false, features = ["signal", "rt-multi-thread"] }
27+
tokio-tungstenite = "0.24.0"
2628
tracing = { version = "0.1", features = ["attributes"] }
2729
types = { git = "https://github.com/realbigsean/lighthouse.git", rev = "10ce60633859ab4f20308ef42bb88e219e09fee5" }
2830
rand = "0.8"

relay-api-types/src/lib.rs

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use serde_utils::quoted_u64::Quoted;
44
use ssz_derive::{Decode, Encode};
55
pub use types::{
66
superstruct, Address, EthSpec, ExecutionBlockHash, ExecutionPayloadBellatrix,
7-
ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadElectra, MainnetEthSpec,
8-
MinimalEthSpec, PublicKeyBytes, Signature, SignedValidatorRegistrationData, Slot, Uint256,
7+
ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadElectra,
8+
ExecutionPayloadHeaderBellatrix, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb,
9+
ExecutionPayloadHeaderElectra, MainnetEthSpec, MinimalEthSpec, PublicKeyBytes, Signature,
10+
SignedValidatorRegistrationData, Slot, Uint256,
911
};
1012

1113
// Builder API requests
@@ -108,13 +110,96 @@ pub struct GetValidatorRegistrationQueryParams {
108110
pub pubkey: PublicKeyBytes,
109111
}
110112

113+
#[superstruct(
114+
variants(Bellatrix, Capella, Deneb, Electra),
115+
variant_attributes(
116+
derive(Debug, Clone, Serialize, Deserialize, Encode, Decode),
117+
serde(bound = "E: EthSpec", deny_unknown_fields),
118+
),
119+
map_into(ExecutionPayloadHeader),
120+
map_ref_into(ExecutionPayloadHeader)
121+
)]
122+
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
123+
#[serde(bound = "E: EthSpec", untagged)]
124+
#[ssz(enum_behaviour = "transparent")]
125+
pub struct HeaderSubmission<E: EthSpec> {
126+
bid_trace: BidTraceV1,
127+
#[superstruct(flatten)]
128+
execution_payload_header: ExecutionPayloadHeader<E>,
129+
#[superstruct(only(Deneb))]
130+
blobs_bundle: BlobsBundle<E>,
131+
}
132+
133+
#[superstruct(
134+
variants(Bellatrix, Capella, Deneb, Electra),
135+
variant_attributes(
136+
derive(Debug, Clone, Serialize, Deserialize, Encode, Decode),
137+
serde(bound = "E: EthSpec", deny_unknown_fields),
138+
),
139+
map_into(ExecutionPayloadHeader),
140+
map_ref_into(ExecutionPayloadHeader)
141+
)]
142+
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
143+
#[serde(bound = "E: EthSpec", untagged)]
144+
#[ssz(enum_behaviour = "transparent")]
145+
pub struct SignedHeaderSubmission<E: EthSpec> {
146+
#[superstruct(flatten)]
147+
message: HeaderSubmission<E>,
148+
signature: Signature,
149+
}
150+
151+
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
152+
pub struct Cancellation {
153+
#[serde(with = "serde_utils::quoted_u64")]
154+
pub slot: u64,
155+
pub parent_hash: ExecutionBlockHash,
156+
pub proposer_public_key: PublicKeyBytes,
157+
pub builder_public_key: PublicKeyBytes,
158+
}
159+
160+
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
161+
pub struct SignedCancellation {
162+
pub message: Cancellation,
163+
pub signature: Signature,
164+
}
165+
166+
// Websockets types
167+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
168+
pub struct TopBidUpdate {
169+
#[serde(with = "serde_utils::quoted_u64")]
170+
timestamp: u64,
171+
slot: Slot,
172+
#[serde(with = "serde_utils::quoted_u64")]
173+
block_number: u64,
174+
block_hash: ExecutionBlockHash,
175+
parent_hash: ExecutionBlockHash,
176+
builder_pubkey: PublicKeyBytes,
177+
fee_recipient: Address,
178+
#[serde(with = "serde_utils::quoted_u256")]
179+
value: Uint256,
180+
}
181+
111182
// Builder API responses
183+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
184+
#[serde(rename_all = "kebab-case")]
185+
pub enum Filtering {
186+
Regional,
187+
Global,
188+
}
189+
190+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
191+
pub struct ValidatorPreferences {
192+
filtering: Filtering,
193+
trusted_builders: Option<Vec<String>>,
194+
}
195+
112196
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
113197
pub struct ValidatorsResponse {
114198
pub slot: Slot,
115199
#[serde(with = "serde_utils::quoted_u64")]
116200
pub validator_index: u64,
117201
pub entry: SignedValidatorRegistrationData,
202+
pub preferences: Option<ValidatorPreferences>,
118203
}
119204

120205
// Data API responses
@@ -156,15 +241,6 @@ pub struct BidTraceV2WithTimestamp {
156241
}
157242

158243
// Response types common
159-
160-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
161-
#[serde(untagged)]
162-
#[must_use]
163-
pub enum Response<T> {
164-
Success(T),
165-
Error(ErrorResponse),
166-
}
167-
168244
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
169245
pub struct ErrorResponse {
170246
pub code: u16,
@@ -173,11 +249,18 @@ pub struct ErrorResponse {
173249
pub stacktraces: Option<Vec<String>>,
174250
}
175251

252+
pub fn custom_internal_err(message: String) -> ErrorResponse {
253+
ErrorResponse {
254+
code: 500,
255+
message,
256+
stacktraces: None,
257+
}
258+
}
259+
176260
// Builder API response types
177-
pub type GetValidatorsResponse = Response<Vec<ValidatorsResponse>>;
178-
pub type SubmitBlockResponse = Response<()>;
261+
pub type GetValidatorsResponse = Vec<ValidatorsResponse>;
179262

180263
// Data API response types
181-
pub type GetDeliveredPayloadsResponse = Response<Vec<BidTraceV2>>;
182-
pub type GetReceivedBidsResponse = Response<Vec<BidTraceV2WithTimestamp>>;
183-
pub type GetValidatorRegistrationResponse = Response<SignedValidatorRegistrationData>;
264+
pub type GetDeliveredPayloadsResponse = Vec<BidTraceV2>;
265+
pub type GetReceivedBidsResponse = Vec<BidTraceV2WithTimestamp>;
266+
pub type GetValidatorRegistrationResponse = SignedValidatorRegistrationData;

relay-client/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
futures.workspace = true
78
http.workspace = true
8-
relay-api-types = { version = "0.1.0", path = "../relay-api-types" }
9+
relay-api-types = { path = "../relay-api-types" }
910
reqwest.workspace = true
1011
serde.workspace = true
1112
serde_json.workspace = true
13+
tokio-tungstenite.workspace = true
1214
types.workspace = true

0 commit comments

Comments
 (0)