Skip to content

Commit 5c753e0

Browse files
committed
Put multiple blocks into one transaction.
1 parent e69d087 commit 5c753e0

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

robusta/src/lib.rs

Lines changed: 26 additions & 24 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,7 @@ 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::{RecvBody, SendBody, TaggedBase64, TransactionsWithProof, VidCommonResponse, TX};
2222

2323
pub use crate::multiwatcher::Multiwatcher;
2424
pub use crate::types::Height;
@@ -58,11 +58,11 @@ impl Client {
5858
self.get_with_retry(u).await
5959
}
6060

61-
pub async fn submit<N>(&self, nsid: N, cb: &CertifiedBlock<Validated>) -> Result<(), Error>
61+
pub async fn submit<N>(&self, nsid: N, blocks: &[CertifiedBlock<Validated>]) -> Result<(), Error>
6262
where
6363
N: Into<NamespaceId>,
6464
{
65-
let trx = Transaction::new(nsid.into(), minicbor::to_vec(cb)?);
65+
let trx = Transaction::new(nsid.into(), minicbor::to_vec(SendBody { blocks })?);
6666
let url = self.config.base_url.join("submit/submit")?;
6767
self.post_with_retry::<_, TaggedBase64<TX>>(url, &trx)
6868
.await?;
@@ -102,34 +102,36 @@ impl Client {
102102
warn!(node = %self.config.label, a = %nsid, b = %ns, height = %hdr.height(), "namespace mismatch");
103103
return Either::Left(empty());
104104
}
105-
Either::Right(trxs.into_iter().filter_map(move |t| {
106-
match minicbor::decode::<CertifiedBlock<Unchecked>>(t.payload()) {
107-
Ok(b) => {
108-
let Some(c) = cvec.get(b.committee()) else {
109-
warn!(
110-
node = %self.config.label,
111-
height = %hdr.height(),
112-
committee = %b.committee(),
113-
"unknown committee"
114-
);
115-
return None;
116-
};
117-
if let Some(b) = b.validated(c) {
118-
Some(b.cert().data().num())
119-
} else {
120-
warn!(node = %self.config.label, height = %hdr.height(), "invalid block");
121-
None
122-
}
105+
Either::Right(trxs.into_iter().flat_map(move |t| {
106+
match minicbor::decode::<RecvBody>(t.payload()) {
107+
Ok(body) => {
108+
Either::Right(body.blocks.into_iter().filter_map(|b| {
109+
let Some(c) = cvec.get(b.committee()) else {
110+
warn!(
111+
node = %self.config.label,
112+
height = %hdr.height(),
113+
committee = %b.committee(),
114+
"unknown committee"
115+
);
116+
return None;
117+
};
118+
if let Some(b) = b.validated(c) {
119+
Some(b.cert().data().num())
120+
} else {
121+
warn!(node = %self.config.label, height = %hdr.height(), "invalid block");
122+
None
123+
}
124+
}))
123125
}
124126
Err(err) => {
125127
warn!(
126128
node = %self.config.label,
127129
nsid = %nsid,
128130
height = %hdr.height(),
129131
err = %err,
130-
"could not deserialize block"
132+
"could not decode transaction payload"
131133
);
132-
None
134+
Either::Left(empty())
133135
}
134136
}
135137
}))

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(

0 commit comments

Comments
 (0)