Skip to content

Commit e9f098b

Browse files
authored
Merge pull request #511 from EspressoSystems/tw/submit-randomly
Submit to random client.
2 parents 5c001db + fcaa45f commit e9f098b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

timeboost-builder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ metrics = { path = "../metrics" }
1717
minicbor = { workspace = true }
1818
multisig = { path = "../multisig" }
1919
parking_lot = { workspace = true }
20+
rand = { workspace = true }
2021
robusta = { path = "../robusta" }
2122
serde = { workspace = true }
2223
smallvec = { workspace = true }
@@ -28,5 +29,4 @@ tokio-util = { workspace = true }
2829
tracing = { workspace = true }
2930

3031
[dev-dependencies]
31-
rand = { workspace = true }
3232
tracing-subscriber = { workspace = true }

timeboost-builder/src/submit.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use std::{
77

88
use bon::Builder;
99
use multisig::{Committee, PublicKey, Validated};
10-
use robusta::{Client, espresso_types::NamespaceId};
10+
use rand::seq::IndexedRandom;
11+
use robusta::{Client, Config, espresso_types::NamespaceId};
1112
use timeboost_types::{
1213
CertifiedBlock,
1314
sailfish::{CommitteeVec, Empty},
@@ -49,27 +50,26 @@ impl Submitter {
4950
where
5051
M: ::metrics::Metrics,
5152
{
52-
let client = Client::new(cfg.robusta.0.clone());
5353
let verified = Verified::default();
5454
let committees = Arc::new(Mutex::new(CommitteeVec::new(cfg.committee.clone())));
5555
let metrics = Arc::new(BuilderMetrics::new(metrics));
5656
let verifier = Verifier::builder()
5757
.label(cfg.pubkey)
5858
.nsid(cfg.namespace)
5959
.committees(committees.clone())
60-
.client(client.clone())
60+
.client(Client::new(cfg.robusta.0.clone()))
6161
.verified(verified.clone())
6262
.metrics(metrics.clone())
6363
.build();
6464
let (tx, rx) = mpsc::channel(10_000);
6565
let sender = Sender::builder()
6666
.label(cfg.pubkey)
6767
.nsid(cfg.namespace)
68-
.client(client)
6968
.verified(verified.clone())
7069
.receiver(rx)
7170
.clock(Instant::now())
7271
.size_limit(cfg.max_transaction_size)
72+
.config(cfg.robusta.0.clone())
7373
.build();
7474
let mut configs = vec![cfg.robusta.0.clone()];
7575
configs.extend(cfg.robusta.1.iter().cloned());
@@ -79,8 +79,8 @@ impl Submitter {
7979
committees,
8080
metrics,
8181
sender: tx,
82-
verify_task: spawn(verifier.verify(configs)),
83-
sender_task: spawn(sender.go()),
82+
verify_task: spawn(verifier.verify(configs.clone())),
83+
sender_task: spawn(sender.send(configs)),
8484
}
8585
}
8686

@@ -109,17 +109,20 @@ pub struct SenderTaskDown(());
109109
struct Sender {
110110
label: PublicKey,
111111
nsid: NamespaceId,
112-
client: Client,
113112
verified: Verified<15_000>,
114113
receiver: mpsc::Receiver<CertifiedBlock<Validated>>,
115114
clock: Instant,
116115
#[builder(default)]
117116
pending: BTreeMap<Instant, Vec<CertifiedBlock<Validated>>>,
118117
size_limit: usize,
118+
config: Config,
119119
}
120120

121121
impl Sender {
122-
async fn go(mut self) {
122+
async fn send(mut self, configs: Vec<Config>) {
123+
let clients: Vec<Client> = configs.into_iter().map(Client::new).collect();
124+
assert!(!clients.is_empty());
125+
123126
// Blocks we receive from the application:
124127
let mut inbox = Vec::new();
125128
// Blocks scheduled for submission:
@@ -131,6 +134,12 @@ impl Sender {
131134
v.retain(|b| !self.verified.contains(b.cert().data().num()));
132135
};
133136

137+
let random_client = || {
138+
clients
139+
.choose(&mut rand::rng())
140+
.expect("Vec<Client> is non-empty")
141+
};
142+
134143
let mut checkpoints = interval(Duration::from_secs(1));
135144
checkpoints.set_missed_tick_behavior(MissedTickBehavior::Skip);
136145

@@ -186,9 +195,9 @@ impl Sender {
186195

187196
debug!(node = %self.label, blocks = %transaction.len(), %size, "submitting blocks");
188197

189-
let mut delays = self.client.config().delay_iter();
198+
let mut delays = self.config.delay_iter();
190199

191-
while let Err(err) = self.client.submit(self.nsid, &transaction).await {
200+
while let Err(err) = random_client().submit(self.nsid, &transaction).await {
192201
warn!(node= %self.label, %err, "error submitting blocks");
193202
let d = delays.next().expect("delay iterator repeats");
194203
sleep(d).await;

0 commit comments

Comments
 (0)