Skip to content

Commit 7cc822b

Browse files
authored
Merge pull request #503 from EspressoSystems/tw/submit2
Submit batches of certified blocks
2 parents 4fe7f9b + 58860b3 commit 7cc822b

File tree

8 files changed

+228
-275
lines changed

8 files changed

+228
-275
lines changed

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ test-contract-deploy *ARGS:
171171
scripts/test-contract-deploy {{ARGS}}
172172

173173
test-all: build_release build-test-utils
174-
env RUST_LOG=block_checker=info,warn target/release/run \
174+
env RUST_LOG=timeboost_builder::submit=debug,block_checker=info,warn target/release/run \
175175
--verbose \
176176
--timeout 120 \
177177
--spawn "1:anvil --port 8545" \

robusta/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::time::Duration;
99

1010
use either::Either;
1111
use espresso_types::{Header, NamespaceId, Transaction};
12-
use multisig::{Unchecked, Validated};
12+
use multisig::Validated;
1313
use reqwest::{StatusCode, Url};
1414
use serde::{Serialize, de::DeserializeOwned};
1515
use serde_json as json;
@@ -18,7 +18,9 @@ use timeboost_types::{BlockNumber, CertifiedBlock};
1818
use tokio::time::sleep;
1919
use tracing::{debug, warn};
2020

21-
use crate::types::{TX, TaggedBase64, TransactionsWithProof, VidCommonResponse};
21+
use crate::types::{
22+
RecvBody, SendBody, TX, TaggedBase64, TransactionsWithProof, VidCommonResponse,
23+
};
2224

2325
pub use crate::multiwatcher::Multiwatcher;
2426
pub use crate::types::Height;
@@ -58,11 +60,15 @@ impl Client {
5860
self.get_with_retry(u).await
5961
}
6062

61-
pub async fn submit<N>(&self, nsid: N, cb: &CertifiedBlock<Validated>) -> Result<(), Error>
63+
pub async fn submit<N>(
64+
&self,
65+
nsid: N,
66+
blocks: &[CertifiedBlock<Validated>],
67+
) -> Result<(), Error>
6268
where
6369
N: Into<NamespaceId>,
6470
{
65-
let trx = Transaction::new(nsid.into(), minicbor::to_vec(cb)?);
71+
let trx = Transaction::new(nsid.into(), minicbor::to_vec(SendBody { blocks })?);
6672
let url = self.config.base_url.join("submit/submit")?;
6773
self.post_with_retry::<_, TaggedBase64<TX>>(url, &trx)
6874
.await?;
@@ -102,9 +108,9 @@ impl Client {
102108
warn!(node = %self.config.label, a = %nsid, b = %ns, height = %hdr.height(), "namespace mismatch");
103109
return Either::Left(empty());
104110
}
105-
Either::Right(trxs.into_iter().filter_map(move |t| {
106-
match minicbor::decode::<CertifiedBlock<Unchecked>>(t.payload()) {
107-
Ok(b) => {
111+
Either::Right(trxs.into_iter().flat_map(move |t| {
112+
match minicbor::decode::<RecvBody>(t.payload()) {
113+
Ok(body) => Either::Right(body.blocks.into_iter().filter_map(|b| {
108114
let Some(c) = cvec.get(b.committee()) else {
109115
warn!(
110116
node = %self.config.label,
@@ -120,16 +126,16 @@ impl Client {
120126
warn!(node = %self.config.label, height = %hdr.height(), "invalid block");
121127
None
122128
}
123-
}
129+
})),
124130
Err(err) => {
125131
warn!(
126132
node = %self.config.label,
127133
nsid = %nsid,
128134
height = %hdr.height(),
129135
err = %err,
130-
"could not deserialize block"
136+
"could not decode transaction payload"
131137
);
132-
None
138+
Either::Left(empty())
133139
}
134140
}
135141
}))

robusta/src/types.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use bon::Builder;
88
use data_encoding::BASE64URL_NOPAD;
99
use espresso_types::{NsProof, Transaction};
1010
use hotshot_query_service::VidCommon;
11+
use minicbor::{Decode, Encode};
12+
use multisig::{Unchecked, Validated};
1113
use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
14+
use timeboost_types::CertifiedBlock;
1215

1316
#[derive(Debug, Deserialize, Serialize, Builder)]
1417
pub(crate) struct TransactionsWithProof {
@@ -21,6 +24,20 @@ pub(crate) struct VidCommonResponse {
2124
pub(crate) common: VidCommon,
2225
}
2326

27+
#[derive(Debug, Decode)]
28+
#[cbor(map)]
29+
pub(crate) struct RecvBody {
30+
#[cbor(n(0))]
31+
pub(crate) blocks: Vec<CertifiedBlock<Unchecked>>,
32+
}
33+
34+
#[derive(Debug, Encode)]
35+
#[cbor(map)]
36+
pub(crate) struct SendBody<'a> {
37+
#[cbor(n(0))]
38+
pub(crate) blocks: &'a [CertifiedBlock<Validated>],
39+
}
40+
2441
macro_rules! Primitive {
2542
($name:ident, $t:ty) => {
2643
#[derive(

timeboost-builder/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ pub use robusta;
88
pub use certifier::{Certifier, CertifierDown, CertifierError, Handle};
99
pub use config::{CertifierConfig, CertifierConfigBuilder};
1010
pub use config::{SubmitterConfig, SubmitterConfigBuilder};
11-
pub use submit::Submitter;
11+
pub use submit::{SenderTaskDown, Submitter};

timeboost-builder/src/metrics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use metrics::{Gauge, Metrics, NoMetrics};
1+
use metrics::{Counter, Metrics, NoMetrics};
22

33
#[derive(Debug)]
44
#[non_exhaustive]
55
pub struct BuilderMetrics {
6-
pub block_submit: Box<dyn Gauge>,
7-
pub submit_tasks: Box<dyn Gauge>,
6+
pub blocks_submitted: Box<dyn Counter>,
7+
pub blocks_verified: Box<dyn Counter>,
88
}
99

1010
impl Default for BuilderMetrics {
@@ -16,8 +16,8 @@ impl Default for BuilderMetrics {
1616
impl BuilderMetrics {
1717
pub fn new<M: Metrics>(m: &M) -> Self {
1818
Self {
19-
block_submit: m.create_gauge("block_submit", None),
20-
submit_tasks: m.create_gauge("submit_tasks", None),
19+
blocks_submitted: m.create_counter("blocks_submitted", None),
20+
blocks_verified: m.create_counter("blocks_verified", None),
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)