Forgotten testnet1 cherries (#475)

* Very quick peer banning endpoint, helps with #406
* Ping heights (#407)
* add height to ping/ping
* reformat output
* fix p2p test
* Fix orphan handling, not related to current head. Fixes #412
* Check before borrow, fixes #267
* Not finding an output commit in pos is an AlreadySpent
* Fix race condition, sending before conn is ready
* Explicit error for unknown pos of a forked block
* Remove config outdated tests. Fix #333
* Check ref and try before borrow, fix #400
* We do not want to sync with old peers anyway
* Hide cargo compiler warning for unused NoopAdapter and unused test code. Add TODOs
This commit is contained in:
Simon B
2017-12-13 22:52:21 +01:00
committed by Ignotus Peverell
parent bffd955c26
commit 17d5898677
15 changed files with 126 additions and 73 deletions
+8 -3
View File
@@ -44,6 +44,9 @@ impl NetAdapter for DummyAdapter {
fn total_difficulty(&self) -> Difficulty {
Difficulty::one()
}
fn total_height(&self) -> u64 {
0
}
fn transaction_received(&self, _: core::Transaction) {}
fn block_received(&self, _: core::Block, _: SocketAddr) {}
fn headers_received(&self, _: Vec<core::BlockHeader>, _:SocketAddr) {}
@@ -58,7 +61,7 @@ impl NetAdapter for DummyAdapter {
}
fn peer_addrs_received(&self, _: Vec<SocketAddr>) {}
fn peer_connected(&self, _: &PeerInfo) {}
fn peer_difficulty(&self, _: SocketAddr, _: Difficulty) {}
fn peer_difficulty(&self, _: SocketAddr, _: Difficulty, _:u64) {}
}
/// P2P server implementation, handling bootstrapping to find and connect to
@@ -189,7 +192,8 @@ impl Server {
.interval(Duration::new(20, 0))
.fold((), move |_, _| {
let total_diff = adapter.total_difficulty();
check_peers(peers_inner.clone(), total_diff);
let total_height = adapter.total_height();
check_peers(peers_inner.clone(), total_diff, total_height);
Ok(())
});
@@ -507,12 +511,13 @@ where
fn check_peers(
peers: Arc<RwLock<HashMap<SocketAddr, Arc<RwLock<Peer>>>>>,
total_difficulty: Difficulty,
height: u64
) {
let peers_map = peers.read().unwrap();
for p in peers_map.values() {
let p = p.read().unwrap();
if p.is_connected() {
let _ = p.send_ping(total_difficulty.clone());
let _ = p.send_ping(total_difficulty.clone(), height);
}
}
}