Skip to content

Commit 957b9a1

Browse files
authored
feat: add support for ultrasound validator preferences (#831)
## πŸ“ Summary Add support for ultrasound validator preferences. ## βœ… I have completed the following steps: * [x] Run `make lint` * [x] Run `make test` * [ ] Added tests (if applicable)
1 parent 4108cde commit 957b9a1

File tree

2 files changed

+54
-3
lines changed
  • crates
    • rbuilder-primitives/src/mev_boost
    • rbuilder/src/mev_boost

2 files changed

+54
-3
lines changed

β€Žcrates/rbuilder-primitives/src/mev_boost/mod.rsβ€Ž

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub struct ValidatorSlotData {
183183
pub regional_endpoints: Vec<BloxrouteRegionalEndpoint>,
184184
/// (Titan) Validator preferences.
185185
#[serde(default)]
186-
pub preferences: Option<TitanValidatorPreferences>,
186+
pub preferences: Option<ValidatorPreferences>,
187187
}
188188

189189
/// Bloxroute validator RProxy details.
@@ -201,6 +201,36 @@ pub struct BloxrouteRegionalEndpoint {
201201
pub websocket_endpoint: String,
202202
}
203203

204+
/// Relay validator preferences.
205+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Hash)]
206+
#[serde(untagged)]
207+
pub enum ValidatorPreferences {
208+
Ultrasound(UltrasoundValidatorPreferences),
209+
Titan(TitanValidatorPreferences),
210+
}
211+
212+
impl ValidatorPreferences {
213+
/// Returns [`TitanValidatorPreferences`] if the variant matches.
214+
pub fn as_titan(&self) -> Option<&TitanValidatorPreferences> {
215+
if let Self::Titan(preferences) = self {
216+
Some(preferences)
217+
} else {
218+
None
219+
}
220+
}
221+
}
222+
223+
/// Ultrasound validator preferences.
224+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Hash)]
225+
pub struct UltrasoundValidatorPreferences {
226+
/// Indicator whether the validator is filtering. Values: "none", "ofac".
227+
filtering: String,
228+
/// Flag indicating whether the validator is integrated with MEV Protect.
229+
is_mev_protect: bool,
230+
/// Flag indicating whether the validator is integrated with Primev.
231+
is_primev: bool,
232+
}
233+
204234
/// Titan validator preferences.
205235
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
206236
pub struct TitanValidatorPreferences {
@@ -292,6 +322,26 @@ mod tests {
292322
}
293323
}
294324
"#,
325+
r#"
326+
{
327+
"slot": "123",
328+
"validator_index": "123",
329+
"entry": {
330+
"message": {
331+
"fee_recipient": "0x0000000000000000000000000000000000000000",
332+
"gas_limit": "60000000",
333+
"timestamp": "123",
334+
"pubkey": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
335+
},
336+
"signature": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
337+
},
338+
"preferences": {
339+
"filtering": "none",
340+
"is_mev_protect": false,
341+
"is_primev": false
342+
}
343+
}
344+
"#,
295345
];
296346
for raw in registrations {
297347
assert!(serde_json::from_str::<ValidatorSlotData>(raw).is_ok());

β€Žcrates/rbuilder/src/mev_boost/mod.rsβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use flate2::{write::GzEncoder, Compression};
77
use governor::{DefaultDirectRateLimiter, Quota, RateLimiter};
88
use rbuilder_primitives::mev_boost::{
99
KnownRelay, MevBoostRelayID, RelayMode, SubmitBlockRequestNoBlobs,
10-
SubmitBlockRequestWithMetadata, SubmitHeaderRequestWithMetadata, ValidatorRegistration,
11-
ValidatorSlotData, MEV_BOOST_SLOT_INFO_REQUEST_TIMEOUT,
10+
SubmitBlockRequestWithMetadata, SubmitHeaderRequestWithMetadata, ValidatorPreferences,
11+
ValidatorRegistration, ValidatorSlotData, MEV_BOOST_SLOT_INFO_REQUEST_TIMEOUT,
1212
};
1313
use reqwest::{
1414
header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_ENCODING, CONTENT_TYPE},
@@ -691,6 +691,7 @@ impl RelayClient {
691691
.filter(|r| {
692692
r.preferences
693693
.as_ref()
694+
.and_then(ValidatorPreferences::as_titan)
694695
.is_none_or(|p| !p.censoring || self.ask_for_filtering_validators)
695696
})
696697
.collect();

0 commit comments

Comments
Β (0)