Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submit new l2 blocks using RPC #28

Merged
merged 7 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jsonrpsee = { version = "0.23", features = ["http-client", "server"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4"
anyhow = "1.0.86"
anyhow = "1.0.86"
5 changes: 3 additions & 2 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ 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
72 changes: 62 additions & 10 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> {
Copy link
Collaborator

@smartprogrammer93 smartprogrammer93 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets call this method advance_head_to_new_l2_block or just advance_head because submit might be confused with submit to block to L1

tracing::debug!("Submitting new L2 blocks");

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

Expand All @@ -35,22 +39,70 @@ mod test {
async fn test_get_pending_l2_tx_lists() {
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 (mut rpc_server, taiko) = setup_rpc_server_and_taiko(3030).await;
let json = taiko.get_pending_l2_tx_lists().await.unwrap();

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() {
let (mut rpc_server, taiko) = setup_rpc_server_and_taiko(3040).await;
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;
}

async fn setup_rpc_server_and_taiko(port: u16) -> (RpcServer, Taiko) {
// Start the RPC server
let mut rpc_server = RpcServer::new();
let addr: SocketAddr = format!("127.0.0.1:{}", port).parse().unwrap();
rpc_server.start_test_responses(addr).await.unwrap();

let taiko = Taiko::new(&format!("http://127.0.0.1:{}", port));
(rpc_server, taiko)
}
}
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