Skip to content

Commit 31f01bb

Browse files
authored
🔧 Rust fmt (#1166)
1 parent e6438d4 commit 31f01bb

File tree

8 files changed

+254
-113
lines changed

8 files changed

+254
-113
lines changed

.github/workflows/clippy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ jobs:
2828
deny: warnings
2929
token: ${{ secrets.GITHUB_TOKEN }}
3030
options: "--all-targets --all-features"
31+
- name: Run rustfmt
32+
run: cargo fmt --all -- --check
33+
- name: Run cargo check
34+
run: cargo check --workspace

crates/hyle-net/src/metrics.rs

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl P2PMetrics {
3535
message_closed: build!(my_meter, counter, "message_closed"),
3636
handshake_connection: build!(my_meter, counter, "handshake_connection"),
3737
handshake_hello: build!(my_meter, counter, "handshake_hello"),
38-
handshake_verack: build!(my_meter, counter, "handshake_verack")
38+
handshake_verack: build!(my_meter, counter, "handshake_verack"),
3939
}
4040
}
4141

@@ -44,42 +44,102 @@ impl P2PMetrics {
4444
}
4545

4646
pub fn message_received(&self, from: String, canal: Canal) {
47-
self.message.add(1, &[KeyValue::new("from", from), KeyValue::new("canal", canal.to_string())]);
47+
self.message.add(
48+
1,
49+
&[
50+
KeyValue::new("from", from),
51+
KeyValue::new("canal", canal.to_string()),
52+
],
53+
);
4854
}
4955

5056
pub fn message_error(&self, from: String, canal: Canal) {
51-
self.message_error.add(1, &[KeyValue::new("from", from), KeyValue::new("canal", canal.to_string())]);
57+
self.message_error.add(
58+
1,
59+
&[
60+
KeyValue::new("from", from),
61+
KeyValue::new("canal", canal.to_string()),
62+
],
63+
);
5264
}
53-
65+
5466
pub fn message_closed(&self, from: String, canal: Canal) {
55-
self.message_closed.add(1, &[KeyValue::new("from", from), KeyValue::new("canal", canal.to_string())]);
67+
self.message_closed.add(
68+
1,
69+
&[
70+
KeyValue::new("from", from),
71+
KeyValue::new("canal", canal.to_string()),
72+
],
73+
);
5674
}
5775

5876
pub fn ping(&self, peer: String, canal: Canal) {
59-
self.ping.add(1, &[KeyValue::new("peer", peer), KeyValue::new("canal", canal.to_string())]);
77+
self.ping.add(
78+
1,
79+
&[
80+
KeyValue::new("peer", peer),
81+
KeyValue::new("canal", canal.to_string()),
82+
],
83+
);
6084
}
6185

6286
pub fn message_emitted(&self, to: String, canal: Canal) {
63-
self.message.add(1, &[KeyValue::new("to", to), KeyValue::new("canal", canal.to_string())]);
87+
self.message.add(
88+
1,
89+
&[
90+
KeyValue::new("to", to),
91+
KeyValue::new("canal", canal.to_string()),
92+
],
93+
);
6494
}
6595

6696
pub fn handshake_connection_emitted(&self, to: String, canal: Canal) {
67-
self.handshake_connection.add(1, &[KeyValue::new("to", to), KeyValue::new("canal", canal.to_string())])
97+
self.handshake_connection.add(
98+
1,
99+
&[
100+
KeyValue::new("to", to),
101+
KeyValue::new("canal", canal.to_string()),
102+
],
103+
)
68104
}
69-
105+
70106
pub fn handshake_hello_emitted(&self, to: String, canal: Canal) {
71-
self.handshake_hello.add(1, &[KeyValue::new("to", to), KeyValue::new("canal", canal.to_string())])
107+
self.handshake_hello.add(
108+
1,
109+
&[
110+
KeyValue::new("to", to),
111+
KeyValue::new("canal", canal.to_string()),
112+
],
113+
)
72114
}
73-
115+
74116
pub fn handshake_hello_received(&self, from: String, canal: Canal) {
75-
self.handshake_hello.add(1, &[KeyValue::new("from", from), KeyValue::new("canal", canal.to_string())])
117+
self.handshake_hello.add(
118+
1,
119+
&[
120+
KeyValue::new("from", from),
121+
KeyValue::new("canal", canal.to_string()),
122+
],
123+
)
76124
}
77125

78126
pub fn handshake_verack_emitted(&self, to: String, canal: Canal) {
79-
self.handshake_verack.add(1, &[KeyValue::new("to", to), KeyValue::new("canal", canal.to_string())])
127+
self.handshake_verack.add(
128+
1,
129+
&[
130+
KeyValue::new("to", to),
131+
KeyValue::new("canal", canal.to_string()),
132+
],
133+
)
80134
}
81135

82136
pub fn handshake_verack_received(&self, from: String, canal: Canal) {
83-
self.handshake_verack.add(1, &[KeyValue::new("from", from), KeyValue::new("canal", canal.to_string())])
137+
self.handshake_verack.add(
138+
1,
139+
&[
140+
KeyValue::new("from", from),
141+
KeyValue::new("canal", canal.to_string()),
142+
],
143+
)
84144
}
85145
}

src/mempool/block_construction.rs

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ impl super::Mempool {
5252
.and_then(|f| f.iter().find(|el| &el.0 == lane_id))
5353
.map(|el| &el.1);
5454

55-
let mut entries = Box::pin(self
56-
.lanes
57-
.get_entries_between_hashes(
58-
lane_id, // get start hash for validator
59-
from_hash.cloned(),
60-
Some(to_hash.clone()),
61-
));
55+
let mut entries = Box::pin(self.lanes.get_entries_between_hashes(
56+
lane_id, // get start hash for validator
57+
from_hash.cloned(),
58+
Some(to_hash.clone()),
59+
));
6260

6361
let mut dps = vec![];
6462

@@ -68,7 +66,7 @@ impl super::Mempool {
6866
buc.from, buc.ccp.consensus_proposal.cut
6967
))?;
7068

71-
dps.push(dp);
69+
dps.push(dp);
7270
}
7371

7472
result.push((lane_id.clone(), dps));
@@ -226,7 +224,9 @@ pub mod test {
226224
let key = ctx.validator_pubkey().clone();
227225
ctx.add_trusted_validator(&key);
228226

229-
let cut = ctx.process_cut_with_dp(&key, &dp_hash, cumul_size, 1).await?;
227+
let cut = ctx
228+
.process_cut_with_dp(&key, &dp_hash, cumul_size, 1)
229+
.await?;
230230

231231
assert_chanmsg_matches!(
232232
ctx.mempool_event_receiver,
@@ -267,22 +267,27 @@ pub mod test {
267267
.expect_err("Should not build signed block");
268268
};
269269

270-
ctx.process_cut_with_dp(&ctx_key, &dp2_hash, dp2_size, 2).await?;
270+
ctx.process_cut_with_dp(&ctx_key, &dp2_hash, dp2_size, 2)
271+
.await?;
271272
expect_nothing(&mut ctx);
272273

273-
ctx.process_cut_with_dp(&ctx_key, &dp5_hash, dp5_size, 5).await?;
274+
ctx.process_cut_with_dp(&ctx_key, &dp5_hash, dp5_size, 5)
275+
.await?;
274276
expect_nothing(&mut ctx);
275277

276278
// Process it twice to check idempotency
277-
ctx.process_cut_with_dp(&ctx_key, &dp5_hash, dp5_size, 5).await?;
279+
ctx.process_cut_with_dp(&ctx_key, &dp5_hash, dp5_size, 5)
280+
.await?;
278281
expect_nothing(&mut ctx);
279282

280283
// Process the old one again as well
281-
ctx.process_cut_with_dp(&ctx_key, &dp2_hash, dp2_size, 2).await?;
284+
ctx.process_cut_with_dp(&ctx_key, &dp2_hash, dp2_size, 2)
285+
.await?;
282286
expect_nothing(&mut ctx);
283287

284288
// Finally process two consecutive ones
285-
ctx.process_cut_with_dp(&ctx_key, &dp6_hash, dp6_size, 6).await?;
289+
ctx.process_cut_with_dp(&ctx_key, &dp6_hash, dp6_size, 6)
290+
.await?;
286291

287292
assert_chanmsg_matches!(
288293
ctx.mempool_event_receiver,
@@ -338,7 +343,8 @@ pub mod test {
338343
},
339344
certificate: AggregateSignature::default(),
340345
},
341-
)).await?;
346+
))
347+
.await?;
342348

343349
// We've received consecutive blocks so start building
344350
assert_chanmsg_matches!(
@@ -381,7 +387,8 @@ pub mod test {
381387
},
382388
certificate: AggregateSignature::default(),
383389
},
384-
)).await?;
390+
))
391+
.await?;
385392

386393
// We don't have the data so we still don't send anything.
387394
ctx.mempool_event_receiver
@@ -436,38 +443,44 @@ pub mod test {
436443

437444
// Receive the two DPs.
438445

439-
ctx.mempool.on_sync_reply(
440-
&ctx.validator_pubkey().clone(),
441-
vec![(
442-
LaneEntryMetadata {
443-
parent_data_proposal_hash: dp1.parent_data_proposal_hash.clone(),
444-
cumul_size: dp1_size,
445-
signatures: vec![ctx
446-
.mempool
447-
.crypto
448-
.sign((dp1_hash, dp1_size))
449-
.expect("should sign")],
450-
},
451-
dp1.clone(),
452-
)],
453-
).await?;
446+
ctx.mempool
447+
.on_sync_reply(
448+
&ctx.validator_pubkey().clone(),
449+
vec![(
450+
LaneEntryMetadata {
451+
parent_data_proposal_hash: dp1.parent_data_proposal_hash.clone(),
452+
cumul_size: dp1_size,
453+
signatures: vec![ctx
454+
.mempool
455+
.crypto
456+
.sign((dp1_hash, dp1_size))
457+
.expect("should sign")],
458+
},
459+
dp1.clone(),
460+
)],
461+
)
462+
.await?;
454463

455464
// We don't have the data so we still don't send anything.
456465
ctx.mempool_event_receiver
457466
.try_recv()
458467
.expect_err("Should not build signed block");
459468

460-
ctx.mempool.on_sync_reply(
461-
&crypto2.validator_pubkey().clone(),
462-
vec![(
463-
LaneEntryMetadata {
464-
parent_data_proposal_hash: dp1b.parent_data_proposal_hash.clone(),
465-
cumul_size: dp1b_size,
466-
signatures: vec![crypto2.sign((dp1b_hash, dp1b_size)).expect("should sign")],
467-
},
468-
dp1b.clone(),
469-
)],
470-
).await?;
469+
ctx.mempool
470+
.on_sync_reply(
471+
&crypto2.validator_pubkey().clone(),
472+
vec![(
473+
LaneEntryMetadata {
474+
parent_data_proposal_hash: dp1b.parent_data_proposal_hash.clone(),
475+
cumul_size: dp1b_size,
476+
signatures: vec![crypto2
477+
.sign((dp1b_hash, dp1b_size))
478+
.expect("should sign")],
479+
},
480+
dp1b.clone(),
481+
)],
482+
)
483+
.await?;
471484

472485
assert_chanmsg_matches!(
473486
ctx.mempool_event_receiver,

src/mempool/own_lane.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ impl super::Mempool {
9494

9595
// TODO: when we have a smarter system, we should probably not trigger this here
9696
// to make the event loop more efficient.
97-
self.disseminate_data_proposals(Some(data_proposal_hash)).await
97+
self.disseminate_data_proposals(Some(data_proposal_hash))
98+
.await
9899
}
99100

100101
/// If only_dp_with_hash is Some, only disseminate the DP with the specified hash. If None, disseminate any pending DPs.
@@ -113,11 +114,10 @@ impl super::Mempool {
113114
// Check for each pending DataProposal if it has enough signatures
114115
let cloned_lanes = self.lanes.clone();
115116
let own_lane_id = self.own_lane_id();
116-
let mut entries_stream = Box::pin(cloned_lanes
117-
.get_pending_entries_in_lane(&own_lane_id, last_cut));
117+
let mut entries_stream =
118+
Box::pin(cloned_lanes.get_pending_entries_in_lane(&own_lane_id, last_cut));
118119

119120
while let Some(stream_entry) = entries_stream.next().await {
120-
121121
let (entry_metadata, dp_hash) = stream_entry?;
122122
// If only_dp_with_hash is Some, we only disseminate that one, skip all others.
123123
if let Some(ref only_dp_with_hash) = only_dp_with_hash {
@@ -543,9 +543,11 @@ pub mod test {
543543
let signed_msg2 = create_data_vote(&crypto2, data_proposal.hashed(), size)?;
544544
let signed_msg3 = create_data_vote(&crypto3, data_proposal.hashed(), size)?;
545545
ctx.mempool
546-
.handle_net_message(crypto2.sign_msg_with_header(signed_msg2)?).await?;
546+
.handle_net_message(crypto2.sign_msg_with_header(signed_msg2)?)
547+
.await?;
547548
ctx.mempool
548-
.handle_net_message(crypto3.sign_msg_with_header(signed_msg3)?).await?;
549+
.handle_net_message(crypto3.sign_msg_with_header(signed_msg3)?)
550+
.await?;
549551

550552
// Assert that PoDAUpdate message is broadcasted
551553
match ctx.assert_broadcast("PoDAUpdate").await.msg {

0 commit comments

Comments
 (0)