Skip to content

Commit

Permalink
submit_new_l2_blocks implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
mskrzypkows committed Jun 24, 2024
1 parent 463204c commit 2629a6b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl Node {
}

async fn main_block_preconfirmation_step(&self) -> Result<(), Error> {
self.taiko
let pending_tx_lists = self.taiko
.get_pending_l2_tx_lists()
.await
.context("Failed to get pending l2 tx lists")?;
self.commit_to_the_tx_lists();
self.send_preconfirmations_to_the_avs_p2p().await?;
self.taiko.submit_new_l2_blocks();
self.taiko.submit_new_l2_blocks(pending_tx_lists).await?;
Ok(())
}

Expand Down
59 changes: 55 additions & 4 deletions Node/src/taiko/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ impl Taiko {
.await
}

pub fn submit_new_l2_blocks(&self) {
pub async fn submit_new_l2_blocks(&self, value: Value) -> Result<Value, Error> {
tracing::debug!("Submitting new L2 blocks");

self.rpc_client
.call_method("RPC.AdvanceL2ChainHeadWithNewBlocks", vec![value])
.await
}
}

Expand All @@ -46,11 +50,58 @@ mod test {
assert_eq!(json["result"]["TxLists"].as_array().unwrap().len(), 1);
assert_eq!(json["result"]["TxLists"][0].as_array().unwrap().len(), 3);
assert_eq!(json["result"]["TxLists"][0][0]["type"], "0x0");
assert_eq!(json["result"]["TxLists"][0][0]["hash"], "0x7c76b9906579e54df54fe77ad1706c47aca706b3eb5cfd8a30ccc3c5a19e8ecd");
assert_eq!(
json["result"]["TxLists"][0][0]["hash"],
"0x7c76b9906579e54df54fe77ad1706c47aca706b3eb5cfd8a30ccc3c5a19e8ecd"
);
assert_eq!(json["result"]["TxLists"][0][1]["type"], "0x2");
assert_eq!(json["result"]["TxLists"][0][1]["hash"], "0xece2a3c6ca097cfe5d97aad4e79393240f63865210f9c763703d1136f065298b");
assert_eq!(
json["result"]["TxLists"][0][1]["hash"],
"0xece2a3c6ca097cfe5d97aad4e79393240f63865210f9c763703d1136f065298b"
);
assert_eq!(json["result"]["TxLists"][0][2]["type"], "0x2");
assert_eq!(json["result"]["TxLists"][0][2]["hash"], "0xb105d9f16e8fb913093c8a2c595bf4257328d256f218a05be8dcc626ddeb4193");
assert_eq!(
json["result"]["TxLists"][0][2]["hash"],
"0xb105d9f16e8fb913093c8a2c595bf4257328d256f218a05be8dcc626ddeb4193"
);
rpc_server.stop().await;
}

#[tokio::test]
async fn test_submit_new_l2_blocks() {
tracing_subscriber::fmt::init();

// Start the RPC server
let mut rpc_server = RpcServer::new();
let addr: SocketAddr = "127.0.0.1:3030".parse().unwrap();
rpc_server.start_test_responses(addr).await.unwrap();

let taiko = Taiko::new("http://127.0.0.1:3030");
let value = serde_json::json!({
"TxLists": [
[
{
"type": "0x0",
"chainId": "0x28c61",
"nonce": "0x1",
"to": "0xbfadd5365bb2890ad832038837115e60b71f7cbb",
"gas": "0x267ac",
"gasPrice": "0x5e76e0800",
"maxPriorityFeePerGas": null,
"maxFeePerGas": null,
"value": "0x0",
"input": "0x40d097c30000000000000000000000004cea2c7d358e313f5d0287c475f9ae943fe1a913",
"v": "0x518e6",
"r": "0xb22da5cdc4c091ec85d2dda9054aa497088e55bd9f0335f39864ae1c598dd35",
"s": "0x6eee1bcfe6a1855e89dd23d40942c90a036f273159b4c4fd217d58169493f055",
"hash": "0x7c76b9906579e54df54fe77ad1706c47aca706b3eb5cfd8a30ccc3c5a19e8ecd"
}
]
]
});

let response = taiko.submit_new_l2_blocks(value).await.unwrap();
assert_eq!(response["result"], "Request received and processed successfully");
rpc_server.stop().await;
}
}
10 changes: 10 additions & 0 deletions Node/src/utils/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ pub mod test {
module.register_async_method("RPC.GetL2TxLists", |_, _, _| async {
TX_LISTS_RESPONSE.clone()
})?;
module.register_async_method(
"RPC.AdvanceL2ChainHeadWithNewBlocks",
|_, _, _| async {
json!({
"result": "Request received and processed successfully",
"error": null,
"id": 1
})
},
)?;

let handle = server.start(module);
tokio::spawn(handle.clone().stopped());
Expand Down

0 comments on commit 2629a6b

Please sign in to comment.