zebra-network tweaks. (#877)
* network: move gossiped peer selection logic into address book. * network: return BoxService from init. * zebrad: add note on why we truncate thegossiped peer list Co-authored-by: Jane Lusby <jlusby42@gmail.com> * Remove unused .rustfmt.toml Many of these options are never actually loaded by our CI because of a channel mismatch, where they're not applied on stable but only on nightly (see the logs from a rustfmt job). This means that we can get different settings when running `cargo fmt` on the nightly and stable channels, which was causing a CI failure on this PR. Reverting back to the default rustfmt settings avoids this problem and keeps us in line with upstream rustfmt. There's no loss to us since we were using the defaults anyways. Co-authored-by: Jane Lusby <jlusby42@gmail.com>
This commit is contained in:
parent
945b019739
commit
299afe13df
|
@ -1,66 +0,0 @@
|
||||||
max_width = 100
|
|
||||||
hard_tabs = false
|
|
||||||
tab_spaces = 4
|
|
||||||
newline_style = "Auto"
|
|
||||||
use_small_heuristics = "Default"
|
|
||||||
indent_style = "Block"
|
|
||||||
wrap_comments = false
|
|
||||||
format_code_in_doc_comments = false
|
|
||||||
comment_width = 80
|
|
||||||
normalize_comments = false
|
|
||||||
normalize_doc_attributes = false
|
|
||||||
#license_template_path = ""
|
|
||||||
format_strings = false
|
|
||||||
format_macro_matchers = false
|
|
||||||
format_macro_bodies = true
|
|
||||||
empty_item_single_line = true
|
|
||||||
struct_lit_single_line = true
|
|
||||||
fn_single_line = false
|
|
||||||
where_single_line = false
|
|
||||||
imports_indent = "Block"
|
|
||||||
imports_layout = "Mixed"
|
|
||||||
merge_imports = false
|
|
||||||
reorder_imports = true
|
|
||||||
reorder_modules = true
|
|
||||||
reorder_impl_items = false
|
|
||||||
type_punctuation_density = "Wide"
|
|
||||||
space_before_colon = false
|
|
||||||
space_after_colon = true
|
|
||||||
spaces_around_ranges = false
|
|
||||||
binop_separator = "Front"
|
|
||||||
remove_nested_parens = true
|
|
||||||
combine_control_expr = true
|
|
||||||
overflow_delimited_expr = false
|
|
||||||
struct_field_align_threshold = 0
|
|
||||||
enum_discrim_align_threshold = 0
|
|
||||||
match_arm_blocks = true
|
|
||||||
force_multiline_blocks = false
|
|
||||||
fn_args_layout = "Tall"
|
|
||||||
brace_style = "SameLineWhere"
|
|
||||||
control_brace_style = "AlwaysSameLine"
|
|
||||||
trailing_semicolon = true
|
|
||||||
trailing_comma = "Vertical"
|
|
||||||
match_block_trailing_comma = false
|
|
||||||
blank_lines_upper_bound = 1
|
|
||||||
blank_lines_lower_bound = 0
|
|
||||||
edition = "2018"
|
|
||||||
version = "One"
|
|
||||||
inline_attribute_width = 0
|
|
||||||
merge_derives = true
|
|
||||||
use_try_shorthand = false
|
|
||||||
use_field_init_shorthand = false
|
|
||||||
force_explicit_abi = true
|
|
||||||
condense_wildcard_suffixes = false
|
|
||||||
color = "Auto"
|
|
||||||
#required_version = "1.3.0"
|
|
||||||
unstable_features = false
|
|
||||||
disable_all_formatting = false
|
|
||||||
skip_children = false
|
|
||||||
hide_parse_errors = false
|
|
||||||
error_on_line_overflow = false
|
|
||||||
error_on_unformatted = false
|
|
||||||
report_todo = "Never"
|
|
||||||
report_fixme = "Never"
|
|
||||||
ignore = []
|
|
||||||
emit_mode = "Files"
|
|
||||||
make_backup = false
|
|
|
@ -35,6 +35,14 @@ impl AddressBook {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the contents of `self` in random order with sanitized timestamps.
|
||||||
|
pub fn sanitized(&self) -> Vec<MetaAddr> {
|
||||||
|
use rand::seq::SliceRandom;
|
||||||
|
let mut peers = self.peers().map(MetaAddr::sanitize).collect::<Vec<_>>();
|
||||||
|
peers.shuffle(&mut rand::thread_rng());
|
||||||
|
peers
|
||||||
|
}
|
||||||
|
|
||||||
/// Check consistency of the address book invariants or panic, doing work
|
/// Check consistency of the address book invariants or panic, doing work
|
||||||
/// quadratic in the address book size.
|
/// quadratic in the address book size.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::{
|
||||||
|
|
||||||
use futures::{
|
use futures::{
|
||||||
channel::mpsc,
|
channel::mpsc,
|
||||||
future::{self, Future, FutureExt},
|
future::{self, FutureExt},
|
||||||
sink::SinkExt,
|
sink::SinkExt,
|
||||||
stream::{FuturesUnordered, StreamExt},
|
stream::{FuturesUnordered, StreamExt},
|
||||||
};
|
};
|
||||||
|
@ -19,6 +19,7 @@ use tower::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
discover::{Change, ServiceStream},
|
discover::{Change, ServiceStream},
|
||||||
layer::Layer,
|
layer::Layer,
|
||||||
|
util::BoxService,
|
||||||
Service, ServiceExt,
|
Service, ServiceExt,
|
||||||
};
|
};
|
||||||
use tower_load::{peak_ewma::PeakEwmaDiscover, NoInstrument};
|
use tower_load::{peak_ewma::PeakEwmaDiscover, NoInstrument};
|
||||||
|
@ -40,14 +41,7 @@ pub async fn init<S>(
|
||||||
config: Config,
|
config: Config,
|
||||||
inbound_service: S,
|
inbound_service: S,
|
||||||
) -> (
|
) -> (
|
||||||
impl Service<
|
Buffer<BoxService<Request, Response, BoxedStdError>, Request>,
|
||||||
Request,
|
|
||||||
Response = Response,
|
|
||||||
Error = BoxedStdError,
|
|
||||||
Future = impl Future<Output = Result<Response, BoxedStdError>> + Send,
|
|
||||||
> + Send
|
|
||||||
+ Clone
|
|
||||||
+ 'static,
|
|
||||||
Arc<Mutex<AddressBook>>,
|
Arc<Mutex<AddressBook>>,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
@ -91,7 +85,7 @@ where
|
||||||
demand_tx.clone(),
|
demand_tx.clone(),
|
||||||
handle_rx,
|
handle_rx,
|
||||||
);
|
);
|
||||||
let peer_set = Buffer::new(peer_set, constants::PEERSET_BUFFER_SIZE);
|
let peer_set = Buffer::new(BoxService::new(peer_set), constants::PEERSET_BUFFER_SIZE);
|
||||||
|
|
||||||
// Connect the tx end to the 3 peer sources:
|
// Connect the tx end to the 3 peer sources:
|
||||||
|
|
||||||
|
|
|
@ -72,21 +72,10 @@ impl Service<Request> for SeedService {
|
||||||
|
|
||||||
let response = match req {
|
let response = match req {
|
||||||
Request::Peers => {
|
Request::Peers => {
|
||||||
// Collect a list of known peers from the address book
|
debug!("selecting peers to gossip");
|
||||||
// and sanitize their timestamps.
|
let mut peers = address_book.lock().unwrap().sanitized();
|
||||||
let mut peers = address_book
|
// truncate the list so that we do not trivially reveal our entire peer set.
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.peers()
|
|
||||||
.map(|addr| addr.sanitize())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
// The peers are still ordered by recency, so shuffle them.
|
|
||||||
use rand::seq::SliceRandom;
|
|
||||||
peers.shuffle(&mut rand::thread_rng());
|
|
||||||
// Finally, truncate the list so that we do not trivially
|
|
||||||
// reveal our entire peer set.
|
|
||||||
peers.truncate(50);
|
peers.truncate(50);
|
||||||
debug!(peers.len = peers.len());
|
|
||||||
Ok(Response::Peers(peers))
|
Ok(Response::Peers(peers))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
Loading…
Reference in New Issue