-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from NethermindEth/mu/prep-mev-boost
Prepare transaction list to force push to MEV Boost
- Loading branch information
Showing
9 changed files
with
347 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
pub struct Constraint { | ||
tx: String, | ||
index: Option<u64>, | ||
} | ||
|
||
impl Constraint { | ||
pub fn new(tx: String, index: Option<u64>) -> Self { | ||
Self { tx, index } | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
pub struct ConstraintsMessage { | ||
validator_index: u64, | ||
slot: u64, | ||
constraints: Vec<Constraint>, | ||
} | ||
|
||
impl ConstraintsMessage { | ||
pub fn new(validator_index: u64, slot: u64, constraints: Vec<Constraint>) -> Self { | ||
Self { | ||
validator_index, | ||
slot, | ||
constraints, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
pub struct SignedConstraints { | ||
message: ConstraintsMessage, | ||
signature: String, | ||
} | ||
|
||
impl SignedConstraints { | ||
pub fn new(message: ConstraintsMessage, signature: String) -> Self { | ||
Self { message, signature } | ||
} | ||
} | ||
|
||
impl From<ConstraintsMessage> for Vec<u8> { | ||
fn from(val: ConstraintsMessage) -> Self { | ||
bincode::serialize(&val).expect("MEV Boost message serialization failed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,57 @@ | ||
#![allow(unused)] //TODO remove after the EthereumL1 is used in release code | ||
|
||
use crate::ethereum_l1::EthereumL1; | ||
use crate::utils::rpc_client::RpcClient; | ||
use anyhow::Error; | ||
use std::sync::Arc; | ||
|
||
pub mod constraints; | ||
use constraints::{Constraint, ConstraintsMessage, SignedConstraints}; | ||
|
||
pub struct MevBoost { | ||
_rpc_client: RpcClient, | ||
rpc_client: RpcClient, | ||
validator_index: u64, | ||
} | ||
|
||
impl MevBoost { | ||
pub fn new(rpc_url: &str) -> Self { | ||
pub fn new(rpc_url: &str, validator_index: u64) -> Self { | ||
let rpc_client = RpcClient::new(rpc_url); | ||
Self { | ||
_rpc_client: rpc_client, | ||
rpc_client, | ||
validator_index, | ||
} | ||
} | ||
|
||
pub fn send_transaction(&self, _tx: &[u8], _validator_index: u64, _slot: u64) { | ||
//TODO: implement | ||
pub async fn force_inclusion( | ||
&self, | ||
constraints: Vec<Constraint>, | ||
ethereum_l1: Arc<EthereumL1>, | ||
) -> Result<(), Error> { | ||
// Prepare the message | ||
// TODO check slot id value | ||
let slot_id = ethereum_l1.slot_clock.get_current_slot()?; | ||
|
||
let message = ConstraintsMessage::new(self.validator_index, slot_id, constraints); | ||
|
||
let data_to_sign: Vec<u8> = message.clone().into(); | ||
|
||
// Sign the message | ||
// TODO: Determine if the transaction data needs to be signed as a JSON string. | ||
let signature = ethereum_l1 | ||
.execution_layer | ||
.sign_message_with_private_ecdsa_key(&data_to_sign)?; | ||
|
||
// Prepare data to send | ||
let signed_constraints = | ||
SignedConstraints::new(message, format!("0x{}", hex::encode(signature))); | ||
let json_data = serde_json::to_value(&signed_constraints).unwrap(); | ||
|
||
// https://chainbound.github.io/bolt-docs/api/builder#ethv1builderconstraints | ||
let method = "/eth/v1/builder/constraints"; | ||
// Make rpc request | ||
self.rpc_client | ||
.call_method(method, vec![json_data]) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.