Skip to content

Commit c50e5cd

Browse files
Giwook-Hansfroment
andauthored
feat: send proof though msgio crate (#254)
* chore: batch propagation Signed-off-by: Sacha Froment <[email protected]> * chore: -- Signed-off-by: Sacha Froment <[email protected]> * feat: add simple runner Signed-off-by: Sacha Froment <[email protected]> * fix: run need to be mutable * fix: msgio reorganize * feat: use commiter in sequencer * chore: format Signed-off-by: Sacha Froment <[email protected]> * feat: make prover send proof though Q * mod: rm unnecessary filed in message header && change some coment * mod: submitter use enveloped message * mod: chagne committer use enveloped msg && change tests prover context * fix: just fix * mod: modification deprecated funtion && just fix && cargo clippy && cargo test * fix: copilot feedback * chore: remove useless comment Signed-off-by: Sacha Froment <[email protected]> * mod: change keccak computaion to use util function * fix: dep order * chore: just fix Signed-off-by: Sacha Froment <[email protected]> * fix: copilot --------- Signed-off-by: Sacha Froment <[email protected]> Co-authored-by: Sacha Froment <[email protected]>
1 parent 0ad5c08 commit c50e5cd

File tree

19 files changed

+157
-44
lines changed

19 files changed

+157
-44
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ Cargo.toml.bak
2828

2929
bitcoin/regtest
3030
bitcoin/testnet4
31+
32+
.mojave

Cargo.lock

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/batch-submitter/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ documentation = { workspace = true }
1111
[dependencies]
1212
mojave-msgio = { workspace = true }
1313
mojave-task = { workspace = true }
14+
mojave-utils = { workspace = true }
1415

1516
ethrex-common = { workspace = true }
1617
ethrex-p2p = { workspace = true }
@@ -20,6 +21,7 @@ bitcoin = { workspace = true, features = ["std", "secp-recovery"] }
2021
bytes = { workspace = true }
2122

2223
bitcoincore-rpc = { workspace = true }
24+
hex = { workspace = true }
2325
rand = { workspace = true }
2426
# TODO: make sure when we update bitcoin that this is still needed
2527
# this is mandatory to handle 2 version of secp256k1 as bitcoin lib await this version right now

crates/batch-submitter/src/committer.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use ethrex_common::types::batch::Batch;
33
use ethrex_p2p::{
44
network::P2PContext,
55
rlpx::{
6-
Message,
6+
message::Message as RlpxMessage,
77
mojave::messages::{MojaveBatch, MojaveMessage},
88
},
99
};
10-
use mojave_msgio::types::Publisher;
10+
use mojave_msgio::types::{self, Publisher};
1111
use mojave_task::Service;
12+
use mojave_utils::hash;
1213
use tokio::sync::broadcast;
1314

1415
use crate::error::{Error, Result};
@@ -50,14 +51,28 @@ where
5051

5152
self.commit_next_batch_to_l1(batch.clone())?;
5253

53-
let data = bincode::serialize(&batch)?;
54+
// didn't check about dedup here
55+
let msg_id = hex::encode(hash::compute_keccak(&batch.number.to_le_bytes()));
56+
57+
let msg = types::Message {
58+
header: types::MessageHeader {
59+
version: 1,
60+
kind: types::MessageKind::BatchSubmit,
61+
message_id: msg_id,
62+
// Only one message is sent per batch, so sequence number is always 1.
63+
seq: 1,
64+
},
65+
body: &batch,
66+
};
67+
68+
let data = bincode::serialize(&msg)?;
5469
let data = Bytes::from(data);
5570
self.queue.publish(data).await?;
5671

5772
self.p2p_context
58-
.broadcast_mojave_message(Message::Mojave(MojaveMessage::Batch(MojaveBatch::new(
59-
batch,
60-
))))?;
73+
.broadcast_mojave_message(RlpxMessage::Mojave(MojaveMessage::Batch(
74+
MojaveBatch::new(batch),
75+
)))?;
6176

6277
Ok(())
6378
}

crates/client/src/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ impl JobId {
3838
pub fn is_empty(&self) -> bool {
3939
self.0.is_empty()
4040
}
41+
42+
pub fn as_str(&self) -> &str {
43+
self.0.as_str()
44+
}
4145
}
4246

4347
impl Borrow<str> for JobId {

crates/msgio/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ documentation = { workspace = true }
1212
[dependencies]
1313
async-trait = { workspace = true }
1414
bytes = { workspace = true }
15+
serde = { workspace = true }
1516
thiserror = { workspace = true }
1617

1718
[dev-dependencies]

crates/msgio/src/types.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
use async_trait::async_trait;
22
use bytes::Bytes;
3+
use serde::{Deserialize, Serialize};
34

45
use crate::error::Result;
56

67
#[async_trait]
78
pub trait Publisher: Send + Sync + 'static {
89
async fn publish(&self, msg: Bytes) -> Result<()>;
910
}
11+
12+
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
13+
pub enum MessageKind {
14+
ProofResponse,
15+
BatchSubmit,
16+
}
17+
18+
#[derive(Clone, Debug, Serialize, Deserialize)]
19+
pub struct MessageHeader {
20+
pub version: u8,
21+
pub kind: MessageKind,
22+
pub message_id: String,
23+
pub seq: u64,
24+
}
25+
26+
#[derive(Clone, Debug, Serialize, Deserialize)]
27+
pub struct Message<T> {
28+
pub header: MessageHeader,
29+
pub body: T,
30+
}

crates/prover/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ documentation = { workspace = true }
1010

1111
[dependencies]
1212
mojave-client = { workspace = true }
13+
mojave-msgio = { workspace = true }
1314
mojave-rpc-core = { workspace = true }
1415
mojave-rpc-macros = { workspace = true }
1516
mojave-rpc-server = { workspace = true }
@@ -25,7 +26,6 @@ hex = { workspace = true }
2526
reqwest = { workspace = true }
2627
serde = { workspace = true, features = ["derive"] }
2728
serde_json = { workspace = true }
28-
tiny-keccak = { workspace = true }
2929
tokio = { workspace = true }
3030
tracing = { workspace = true }
3131

crates/prover/src/rpc/api.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ use crate::{
55
use mojave_rpc_server::{RpcRegistry, RpcService};
66
use mojave_utils::rpc::error::{Error, Result};
77

8-
use std::sync::Arc;
9-
use tokio::{net::TcpListener, sync::mpsc};
8+
use std::{collections::HashSet, sync::Arc};
9+
use tokio::{
10+
net::TcpListener,
11+
sync::{Mutex, mpsc},
12+
};
1013
use tracing::info;
1114

1215
pub async fn start_api(
@@ -16,10 +19,18 @@ pub async fn start_api(
1619
queue_capacity: usize,
1720
) -> Result<()> {
1821
let (job_sender, job_receiver) = mpsc::channel::<JobRecord>(queue_capacity);
22+
// use dummy publisher for now
23+
let publisher = Arc::new(
24+
mojave_msgio::dummy::Dummy::new()
25+
.await
26+
.map_err(|e| Error::Internal(e.to_string()))?,
27+
);
1928
let context = Arc::new(ProverRpcContext {
2029
aligned_mode,
2130
job_store: JobStore::default(),
2231
sender: job_sender,
32+
publisher,
33+
sent_ids: Mutex::new(HashSet::new()),
2334
});
2435
tracing::info!(aligned_mode = %aligned_mode, "Prover RPC context initialized");
2536

crates/prover/src/rpc/context.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
use tokio::sync::mpsc;
1+
use std::{collections::HashSet, sync::Arc};
2+
3+
use mojave_msgio::types::Publisher;
4+
use tokio::sync::{Mutex, mpsc};
25

36
use crate::{job::JobStore, rpc::types::JobRecord};
47

58
pub struct ProverRpcContext {
69
pub aligned_mode: bool,
710
pub job_store: JobStore,
811
pub sender: mpsc::Sender<JobRecord>,
12+
pub publisher: Arc<dyn Publisher>,
13+
pub sent_ids: Mutex<HashSet<String>>,
914
}

0 commit comments

Comments
 (0)