Skip to content

Commit

Permalink
Forwarding of encoded tx to the mev boost module
Browse files Browse the repository at this point in the history
  • Loading branch information
mskrzypkows committed Jul 3, 2024
1 parent 288bd76 commit 752e169
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
9 changes: 7 additions & 2 deletions Node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ async fn main() -> Result<(), Error> {
let (node_tx, node_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
let p2p = p2p_network::AVSp2p::new(node_tx.clone(), avs_p2p_rx);
p2p.start();
let ethereum_l1 = ethereum_l1::EthereumL1::new("http://localhost:8545", "private_key")?;
let node = node::Node::new(node_rx, avs_p2p_tx, ethereum_l1);
let taiko = taiko::Taiko::new("http://127.0.0.1:1234", "http://127.0.0.1:1235");
let ethereum_l1 = ethereum_l1::EthereumL1::new(
"http://localhost:8545",
"0x4c0883a69102937d6231471b5dbb6204fe512961708279f2e3e8a5d4b8e3e3e8",
)?;
let mev_boost = mev_boost::MevBoost::new("http://localhost:8545");
let node = node::Node::new(node_rx, avs_p2p_tx, taiko, ethereum_l1, mev_boost);
node.entrypoint().await?;
Ok(())
}
Expand Down
17 changes: 17 additions & 0 deletions Node/src/mev_boost/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
use crate::utils::rpc_client::RpcClient;

pub struct MevBoost {
_rpc_client: RpcClient,
}

impl MevBoost {
pub fn new(rpc_url: &str) -> Self {
let rpc_client = RpcClient::new(rpc_url);
Self {
_rpc_client: rpc_client,
}
}

pub fn send_transaction(&self, _tx: &[u8], _validator_index: u64, _slot: u64) {
//TODO: implement
}
}
24 changes: 20 additions & 4 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::ethereum_l1::EthereumL1;
use crate::taiko::Taiko;
use crate::{ethereum_l1::EthereumL1, mev_boost::MevBoost, taiko::Taiko};
use anyhow::{anyhow as any_err, Error, Ok};
use tokio::sync::mpsc::{Receiver, Sender};

Expand All @@ -9,21 +8,24 @@ pub struct Node {
avs_p2p_tx: Sender<String>,
gas_used: u64,
ethereum_l1: EthereumL1,
mev_boost: MevBoost,
}

impl Node {
pub fn new(
node_rx: Receiver<String>,
avs_p2p_tx: Sender<String>,
taiko: Taiko,
ethereum_l1: EthereumL1,
mev_boost: MevBoost,
) -> Self {
let taiko = Taiko::new("http://127.0.0.1:1234", "http://127.0.0.1:1235");
Self {
taiko,
node_rx: Some(node_rx),
avs_p2p_tx,
gas_used: 0,
ethereum_l1,
mev_boost,
}
}

Expand Down Expand Up @@ -74,12 +76,26 @@ impl Node {
.get_pending_l2_tx_lists()
.await
.map_err(Error::from)?;
if pending_tx_lists.tx_list_bytes.len() == 0 {
return Ok(());
}

self.commit_to_the_tx_lists();
self.send_preconfirmations_to_the_avs_p2p().await?;
self.taiko
.advance_head_to_new_l2_block(pending_tx_lists.tx_lists, self.gas_used)
.await?;
// self.ethereum_l1.propose_new_block(pending_tx_lists).await?;
let tx = self
.ethereum_l1
.create_propose_new_block_tx(
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
.parse()
.unwrap(),
pending_tx_lists.tx_list_bytes[0].clone(), //TODO: handle rest tx lists
pending_tx_lists.parent_meta_hash,
)
.await?;
self.mev_boost.send_transaction(&tx, 1, 1);
Ok(())
}

Expand Down
26 changes: 24 additions & 2 deletions Node/src/taiko/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,33 @@ impl Taiko {

pub async fn get_pending_l2_tx_lists(&self) -> Result<l2_tx_lists::RPCReplyL2TxLists, Error> {
tracing::debug!("Getting L2 tx lists");
l2_tx_lists::decompose_pending_lists_json(
let result = l2_tx_lists::decompose_pending_lists_json(
self.rpc_proposer
.call_method("RPC.GetL2TxLists", vec![])
.await?,
)
)?;

if result.tx_list_bytes.len() > 0 {
Self::print_number_of_received_txs(&result);
}

Ok(result)
}

fn print_number_of_received_txs(result: &l2_tx_lists::RPCReplyL2TxLists) {
if let Some(tx_lists) = result.tx_lists.as_array() {
let mut hashes = Vec::new();
for (_, tx_list) in tx_lists.iter().enumerate() {
if let Some(tx_list_array) = tx_list.as_array() {
for (_, tx) in tx_list_array.iter().enumerate() {
if let Some(hash) = tx.get("hash") {
hashes.push(hash.as_str().unwrap_or("").get(0..8).unwrap_or(""));
}
}
}
}
tracing::debug!("Received L2 txs: [{}]", hashes.join(" "));
}
}

pub async fn advance_head_to_new_l2_block(
Expand Down

0 comments on commit 752e169

Please sign in to comment.