Skip to content

Commit b0c5fc7

Browse files
committed
fix: run fmt on whole project
1 parent f9b1a4e commit b0c5fc7

File tree

4 files changed

+85
-36
lines changed

4 files changed

+85
-36
lines changed

common/src/upstream_cache.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ impl<S: Storage> UpstreamCacheImpl<S> {
124124

125125
pub fn write_record(&mut self, record: &UpstreamCacheRecord) -> Result<()> {
126126
self.chunk_cached.push(record.clone());
127-
self.storage.write_chunk(self.current_chunk, &self.chunk_cached).context("could not write cache record")?;
127+
self.storage
128+
.write_chunk(self.current_chunk, &self.chunk_cached)
129+
.context("could not write cache record")?;
128130

129131
self.current_record += 1;
130132
if self.current_record >= self.density {
@@ -155,7 +157,8 @@ impl Storage for FileStorage {
155157
}
156158

157159
fn write_chunk(&mut self, chunk_no: usize, data: &[UpstreamCacheRecord]) -> Result<()> {
158-
let mut file = File::create(self.get_file_name(chunk_no)).context("could not write chunk")?;
160+
let mut file =
161+
File::create(self.get_file_name(chunk_no)).context("could not write chunk")?;
159162
file.write_all(&serde_json::to_vec(data)?)?;
160163
Ok(())
161164
}

modules/peer_network_interface/src/chain_state.rs

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ impl SlotBlockData {
2121
if let Some(block) = self.blocks.iter_mut().find(|b| b.header.hash == header.hash) {
2222
block.announced_by.push(id);
2323
} else {
24-
self.blocks.push(BlockData { header, announced_by: vec![id], body: None });
24+
self.blocks.push(BlockData {
25+
header,
26+
announced_by: vec![id],
27+
body: None,
28+
});
2529
}
2630
}
2731

@@ -50,7 +54,7 @@ impl SlotBlockData {
5054
fn announcers(&self, hash: BlockHash) -> Vec<PeerId> {
5155
match self.blocks.iter().find(|b| b.header.hash == hash) {
5256
Some(b) => b.announced_by.clone(),
53-
None => vec![]
57+
None => vec![],
5458
}
5559
}
5660

@@ -180,7 +184,7 @@ impl ChainState {
180184
// queue them to be published as soon as we have their bodies
181185
let head_slot = self.published_blocks.back().map(|(s, _)| *s);
182186
if let Some(slot) = head_slot {
183-
for (slot, blocks) in self.blocks.range(slot+1..) {
187+
for (slot, blocks) in self.blocks.range(slot + 1..) {
184188
if let Some(hash) = blocks.find_announced_hash(id) {
185189
self.unpublished_blocks.push_back((*slot, hash));
186190
}
@@ -251,7 +255,7 @@ impl ChainState {
251255
pub fn block_announcers(&self, slot: u64, hash: BlockHash) -> Vec<PeerId> {
252256
match self.blocks.get(&slot) {
253257
Some(slot_blocks) => slot_blocks.announcers(hash),
254-
None => vec![]
258+
None => vec![],
255259
}
256260
}
257261
}
@@ -298,7 +302,10 @@ mod tests {
298302
state.handle_body_fetched(header.slot, header.hash, body.clone());
299303

300304
// NOW we have a new block to report
301-
assert_eq!(state.next_unpublished_block(), Some((&header, body.as_slice(), false)));
305+
assert_eq!(
306+
state.next_unpublished_block(),
307+
Some((&header, body.as_slice(), false))
308+
);
302309
state.handle_block_published();
303310
assert_eq!(state.next_unpublished_block(), None);
304311
}
@@ -329,9 +336,15 @@ mod tests {
329336
state.handle_body_fetched(h1.slot, h1.hash, b1.clone());
330337

331338
// NOW we have TWO new blocks to report
332-
assert_eq!(state.next_unpublished_block(), Some((&h1, b1.as_slice(), false)));
339+
assert_eq!(
340+
state.next_unpublished_block(),
341+
Some((&h1, b1.as_slice(), false))
342+
);
333343
state.handle_block_published();
334-
assert_eq!(state.next_unpublished_block(), Some((&h2, b2.as_slice(), false)));
344+
assert_eq!(
345+
state.next_unpublished_block(),
346+
Some((&h2, b2.as_slice(), false))
347+
);
335348
state.handle_block_published();
336349
assert_eq!(state.next_unpublished_block(), None);
337350
}
@@ -350,13 +363,19 @@ mod tests {
350363
// publish the first block
351364
assert_eq!(state.handle_roll_forward(p1, h1.clone()), vec![p1]);
352365
state.handle_body_fetched(h1.slot, h1.hash, b1.clone());
353-
assert_eq!(state.next_unpublished_block(), Some((&h1, b1.as_slice(), false)));
366+
assert_eq!(
367+
state.next_unpublished_block(),
368+
Some((&h1, b1.as_slice(), false))
369+
);
354370
state.handle_block_published();
355371

356372
// publish the second block
357373
assert_eq!(state.handle_roll_forward(p1, h2.clone()), vec![p1]);
358374
state.handle_body_fetched(h2.slot, h2.hash, b2.clone());
359-
assert_eq!(state.next_unpublished_block(), Some((&h2, b2.as_slice(), false)));
375+
assert_eq!(
376+
state.next_unpublished_block(),
377+
Some((&h2, b2.as_slice(), false))
378+
);
360379
state.handle_block_published();
361380
assert_eq!(state.next_unpublished_block(), None);
362381

@@ -367,13 +386,19 @@ mod tests {
367386
// and when we advance to the new second block, the system should report it as a rollback
368387
assert_eq!(state.handle_roll_forward(p1, h3.clone()), vec![p1]);
369388
state.handle_body_fetched(h3.slot, h3.hash, b3.clone());
370-
assert_eq!(state.next_unpublished_block(), Some((&h3, b3.as_slice(), true)));
389+
assert_eq!(
390+
state.next_unpublished_block(),
391+
Some((&h3, b3.as_slice(), true))
392+
);
371393
state.handle_block_published();
372394

373395
// and the new third block should not be a rollback
374396
assert_eq!(state.handle_roll_forward(p1, h4.clone()), vec![p1]);
375397
state.handle_body_fetched(h4.slot, h4.hash, b4.clone());
376-
assert_eq!(state.next_unpublished_block(), Some((&h4, b4.as_slice(), false)));
398+
assert_eq!(
399+
state.next_unpublished_block(),
400+
Some((&h4, b4.as_slice(), false))
401+
);
377402
state.handle_block_published();
378403
}
379404

@@ -390,7 +415,10 @@ mod tests {
390415
// publish the first block
391416
assert_eq!(state.handle_roll_forward(p1, h1.clone()), vec![p1]);
392417
state.handle_body_fetched(h1.slot, h1.hash, b1.clone());
393-
assert_eq!(state.next_unpublished_block(), Some((&h1, b1.as_slice(), false)));
418+
assert_eq!(
419+
state.next_unpublished_block(),
420+
Some((&h1, b1.as_slice(), false))
421+
);
394422
state.handle_block_published();
395423

396424
// roll forward to the second block, but pretend the body is taking a while to download
@@ -408,7 +436,10 @@ mod tests {
408436
// and when we advance to the new second block, the system should not report it as a rollback
409437
assert_eq!(state.handle_roll_forward(p1, h3.clone()), vec![p1]);
410438
state.handle_body_fetched(h3.slot, h3.hash, b3.clone());
411-
assert_eq!(state.next_unpublished_block(), Some((&h3, b3.as_slice(), false)));
439+
assert_eq!(
440+
state.next_unpublished_block(),
441+
Some((&h3, b3.as_slice(), false))
442+
);
412443
state.handle_block_published();
413444
assert_eq!(state.next_unpublished_block(), None);
414445
}
@@ -429,17 +460,26 @@ mod tests {
429460
// publish three blocks on our current chain
430461
assert_eq!(state.handle_roll_forward(p1, h1.clone()), vec![p1]);
431462
state.handle_body_fetched(h1.slot, h1.hash, b1.clone());
432-
assert_eq!(state.next_unpublished_block(), Some((&h1, b1.as_slice(), false)));
463+
assert_eq!(
464+
state.next_unpublished_block(),
465+
Some((&h1, b1.as_slice(), false))
466+
);
433467
state.handle_block_published();
434468

435469
assert_eq!(state.handle_roll_forward(p1, p1h2.clone()), vec![p1]);
436470
state.handle_body_fetched(p1h2.slot, p1h2.hash, p1b2.clone());
437-
assert_eq!(state.next_unpublished_block(), Some((&p1h2, p1b2.as_slice(), false)));
471+
assert_eq!(
472+
state.next_unpublished_block(),
473+
Some((&p1h2, p1b2.as_slice(), false))
474+
);
438475
state.handle_block_published();
439476

440477
assert_eq!(state.handle_roll_forward(p1, p1h3.clone()), vec![p1]);
441478
state.handle_body_fetched(p1h3.slot, p1h3.hash, p1b3.clone());
442-
assert_eq!(state.next_unpublished_block(), Some((&p1h3, p1b3.as_slice(), false)));
479+
assert_eq!(
480+
state.next_unpublished_block(),
481+
Some((&p1h3, p1b3.as_slice(), false))
482+
);
443483
state.handle_block_published();
444484

445485
// that other chain forked
@@ -454,11 +494,16 @@ mod tests {
454494
state.handle_new_preferred_upstream(p2);
455495

456496
// now we should publish two blocks, and the first should be marked as "rollback"
457-
assert_eq!(state.next_unpublished_block(), Some((&p2h2, p2b2.as_slice(), true)));
497+
assert_eq!(
498+
state.next_unpublished_block(),
499+
Some((&p2h2, p2b2.as_slice(), true))
500+
);
458501
state.handle_block_published();
459-
assert_eq!(state.next_unpublished_block(), Some((&p2h3, p2b3.as_slice(), false)));
502+
assert_eq!(
503+
state.next_unpublished_block(),
504+
Some((&p2h3, p2b3.as_slice(), false))
505+
);
460506
state.handle_block_published();
461507
assert_eq!(state.next_unpublished_block(), None);
462-
463508
}
464-
}
509+
}

modules/peer_network_interface/src/network.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::{
2-
collections::BTreeMap,
3-
time::Duration,
4-
};
1+
use std::{collections::BTreeMap, time::Duration};
52

63
use crate::{
7-
BlockSink, chain_state::ChainState, connection::{PeerChainSyncEvent, PeerConnection, PeerEvent}
4+
BlockSink,
5+
chain_state::ChainState,
6+
connection::{PeerChainSyncEvent, PeerConnection, PeerEvent},
87
};
98
use acropolis_common::BlockHash;
109
use anyhow::{Context as _, Result, bail};
@@ -18,10 +17,7 @@ struct PeerData {
1817
}
1918
impl PeerData {
2019
fn new(conn: PeerConnection) -> Self {
21-
Self {
22-
conn,
23-
reqs: vec![]
24-
}
20+
Self { conn, reqs: vec![] }
2521
}
2622

2723
fn find_intersect(&self, points: Vec<Point>) {
@@ -35,7 +31,10 @@ impl PeerData {
3531
return true;
3632
}
3733
if let Err(error) = self.conn.request_block(hash, slot) {
38-
warn!("could not request block from {}: {error:#}", self.conn.address);
34+
warn!(
35+
"could not request block from {}: {error:#}",
36+
self.conn.address
37+
);
3938
return false;
4039
}
4140
self.reqs.push((hash, slot));

modules/peer_network_interface/src/peer_network_interface.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ mod connection;
44
mod network;
55

66
use acropolis_common::{
7-
BlockInfo, BlockStatus, genesis_values::GenesisValues, messages::{CardanoMessage, Message, RawBlockMessage}, upstream_cache::{UpstreamCache, UpstreamCacheRecord}
7+
BlockInfo, BlockStatus,
8+
genesis_values::GenesisValues,
9+
messages::{CardanoMessage, Message, RawBlockMessage},
10+
upstream_cache::{UpstreamCache, UpstreamCacheRecord},
811
};
912
use anyhow::{Result, bail};
1013
use caryatid_sdk::{Context, Module, Subscription, module};
@@ -72,8 +75,7 @@ impl PeerNetworkInterface {
7275
upstream_cache,
7376
};
7477

75-
let mut manager =
76-
NetworkManager::new(cfg.magic_number, events, events_sender, sink);
78+
let mut manager = NetworkManager::new(cfg.magic_number, events, events_sender, sink);
7779
for address in cfg.node_addresses {
7880
manager.handle_new_connection(address, Duration::ZERO);
7981
}
@@ -94,7 +96,7 @@ impl PeerNetworkInterface {
9496
Ok(point) => manager.sync_to_point(point),
9597
Err(error) => {
9698
warn!("snapshot restoration never completed: {error:#}");
97-
return;
99+
return;
98100
}
99101
}
100102
}

0 commit comments

Comments
 (0)