[sync]: rust 2018 (#11067)
* [sync]: rust 2018 * fix(grumble): explicit use for RlpResponseResult * fix(grumble): types -> common_types * fix: bad rebase * fix: wildcard import * fix(grumble): rename crate hash to `keccak_hash`
This commit is contained in:
@@ -38,15 +38,20 @@ use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
use types::encoded;
|
||||
use crate::{
|
||||
api::Notification,
|
||||
chain::SyncState as ChainSyncState,
|
||||
};
|
||||
|
||||
use common_types::encoded;
|
||||
use light::client::{AsLightClient, LightChainClient};
|
||||
use light::net::{
|
||||
PeerStatus, Announcement, Handler, BasicContext,
|
||||
EventContext, Capabilities, ReqId, Status,
|
||||
Error as NetError,
|
||||
};
|
||||
use chain::SyncState as ChainSyncState;
|
||||
use light::request::{self, CompleteHeadersRequest as HeadersRequest};
|
||||
use log::{debug, trace};
|
||||
use network::PeerId;
|
||||
use ethereum_types::{H256, U256};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
@@ -54,7 +59,6 @@ use rand::{rngs::OsRng, seq::SliceRandom};
|
||||
use futures::sync::mpsc;
|
||||
|
||||
use self::sync_round::{AbortReason, SyncRound, ResponseContext};
|
||||
use api::Notification;
|
||||
|
||||
mod response;
|
||||
mod sync_round;
|
||||
@@ -78,13 +82,13 @@ struct ChainInfo {
|
||||
}
|
||||
|
||||
impl PartialOrd for ChainInfo {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<::std::cmp::Ordering> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
self.head_td.partial_cmp(&other.head_td)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for ChainInfo {
|
||||
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
self.head_td.cmp(&other.head_td)
|
||||
}
|
||||
}
|
||||
@@ -102,14 +106,20 @@ impl Peer {
|
||||
}
|
||||
}
|
||||
|
||||
// search for a common ancestor with the best chain.
|
||||
/// Search for a common ancestor with the best chain.
|
||||
#[derive(Debug)]
|
||||
enum AncestorSearch {
|
||||
Queued(u64), // queued to search for blocks starting from here.
|
||||
Awaiting(ReqId, u64, HeadersRequest), // awaiting response for this request.
|
||||
Prehistoric, // prehistoric block found. TODO: start to roll back CHTs.
|
||||
FoundCommon(u64, H256), // common block found.
|
||||
Genesis, // common ancestor is the genesis.
|
||||
/// Queued to search for blocks starting from here.
|
||||
Queued(u64), //
|
||||
/// Awaiting response for this request.
|
||||
Awaiting(ReqId, u64, HeadersRequest),
|
||||
/// Pre-historic block found.
|
||||
// TODO: start to roll back CHTs.
|
||||
Prehistoric,
|
||||
/// Common block found.
|
||||
FoundCommon(u64, H256),
|
||||
/// Common ancestor is the genesis.
|
||||
Genesis,
|
||||
}
|
||||
|
||||
impl AncestorSearch {
|
||||
@@ -493,7 +503,7 @@ impl<L: AsLightClient> LightSync<L> {
|
||||
|
||||
// handles request dispatch, block import, state machine transitions, and timeouts.
|
||||
fn maintain_sync(&self, ctx: &dyn BasicContext) {
|
||||
use types::errors::{EthcoreError, ImportError};
|
||||
use common_types::errors::{EthcoreError, ImportError};
|
||||
|
||||
const DRAIN_AMOUNT: usize = 128;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Helpers for decoding and verifying responses for headers.
|
||||
|
||||
use types::{encoded, header::Header};
|
||||
use common_types::{encoded, header::Header};
|
||||
use ethereum_types::H256;
|
||||
use light::request::{HashOrNumber, CompleteHeadersRequest as HeadersRequest};
|
||||
use rlp::DecoderError;
|
||||
@@ -153,8 +153,8 @@ impl Constraint for Max {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use types::encoded;
|
||||
use types::header::Header;
|
||||
use common_types::encoded;
|
||||
use common_types::header::Header;
|
||||
use light::request::CompleteHeadersRequest as HeadersRequest;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -20,11 +20,11 @@ use std::cmp::Ordering;
|
||||
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
|
||||
use std::fmt;
|
||||
|
||||
use types::encoded;
|
||||
use types::header::Header;
|
||||
use common_types::{encoded, header::Header};
|
||||
|
||||
use light::net::ReqId;
|
||||
use light::request::CompleteHeadersRequest as HeadersRequest;
|
||||
use log::trace;
|
||||
|
||||
use network::PeerId;
|
||||
use ethereum_types::H256;
|
||||
@@ -37,7 +37,7 @@ const SCAFFOLD_ATTEMPTS: usize = 3;
|
||||
/// Context for a headers response.
|
||||
pub trait ResponseContext {
|
||||
/// Get the peer who sent this response.
|
||||
fn responder(&self) -> PeerId;
|
||||
fn responder(&self) -> PeerId;
|
||||
/// Get the request ID this response corresponds to.
|
||||
fn req_id(&self) -> &ReqId;
|
||||
/// Get the (unverified) response data.
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use tests::helpers::TestNet;
|
||||
use crate::tests::helpers::TestNet;
|
||||
|
||||
use ethcore::test_helpers::EachBlockWith;
|
||||
use client_traits::BlockInfo;
|
||||
use types::ids::BlockId;
|
||||
use common_types::ids::BlockId;
|
||||
|
||||
mod test_net;
|
||||
|
||||
|
||||
@@ -18,26 +18,27 @@
|
||||
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use light_sync::*;
|
||||
use tests::helpers::{TestNet, Peer as PeerLike, TestPacket};
|
||||
use crate::{
|
||||
light_sync::LightSync,
|
||||
tests::helpers::{TestNet, Peer as PeerLike, TestPacket}
|
||||
};
|
||||
|
||||
use ethcore::test_helpers::TestBlockChainClient;
|
||||
use spec;
|
||||
use io::IoChannel;
|
||||
use kvdb_memorydb;
|
||||
use light::client::fetch::{self, Unavailable};
|
||||
use light::net::{LightProtocol, IoContext, Capabilities, Params as LightParams};
|
||||
use light::provider::LightProvider;
|
||||
use ethcore_io::IoChannel;
|
||||
use light::{
|
||||
cache::Cache,
|
||||
client::fetch::{self, Unavailable},
|
||||
net::{LightProtocol, IoContext, Capabilities, Params as LightParams},
|
||||
provider::LightProvider
|
||||
};
|
||||
use network::{NodeId, PeerId};
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use std::time::Duration;
|
||||
use light::cache::Cache;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
|
||||
const NETWORK_ID: u64 = 0xcafebabe;
|
||||
|
||||
pub type LightClient = ::light::client::Client<Unavailable>;
|
||||
pub type LightClient = light::client::Client<Unavailable>;
|
||||
|
||||
struct TestIoContext<'a> {
|
||||
queue: &'a RwLock<VecDeque<TestPacket>>,
|
||||
@@ -49,7 +50,7 @@ impl<'a> IoContext for TestIoContext<'a> {
|
||||
fn send(&self, peer: PeerId, packet_id: u8, packet_body: Vec<u8>) {
|
||||
self.queue.write().push_back(TestPacket {
|
||||
data: packet_body,
|
||||
packet_id: packet_id,
|
||||
packet_id,
|
||||
recipient: peer,
|
||||
})
|
||||
}
|
||||
@@ -64,11 +65,21 @@ impl<'a> IoContext for TestIoContext<'a> {
|
||||
self.to_disconnect.write().insert(peer);
|
||||
}
|
||||
|
||||
fn disable_peer(&self, peer: PeerId) { self.disconnect_peer(peer) }
|
||||
fn protocol_version(&self, _peer: PeerId) -> Option<u8> { Some(::light::net::MAX_PROTOCOL_VERSION) }
|
||||
fn disable_peer(&self, peer: PeerId) {
|
||||
self.disconnect_peer(peer)
|
||||
}
|
||||
|
||||
fn persistent_peer_id(&self, _peer: PeerId) -> Option<NodeId> { unimplemented!() }
|
||||
fn is_reserved_peer(&self, _peer: PeerId) -> bool { false }
|
||||
fn protocol_version(&self, _peer: PeerId) -> Option<u8> {
|
||||
Some(light::net::MAX_PROTOCOL_VERSION)
|
||||
}
|
||||
|
||||
fn persistent_peer_id(&self, _peer: PeerId) -> Option<NodeId> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn is_reserved_peer(&self, _peer: PeerId) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// peer-specific data.
|
||||
@@ -219,7 +230,7 @@ impl TestNet<Peer> {
|
||||
pub fn light(n_light: usize, n_full: usize) -> Self {
|
||||
let mut peers = Vec::with_capacity(n_light + n_full);
|
||||
for _ in 0..n_light {
|
||||
let mut config = ::light::client::Config::default();
|
||||
let mut config = light::client::Config::default();
|
||||
|
||||
// skip full verification because the blocks are bad.
|
||||
config.verify_full = false;
|
||||
@@ -242,8 +253,8 @@ impl TestNet<Peer> {
|
||||
peers.push(Arc::new(Peer::new_full(Arc::new(TestBlockChainClient::new()))))
|
||||
}
|
||||
|
||||
TestNet {
|
||||
peers: peers,
|
||||
Self {
|
||||
peers,
|
||||
started: false,
|
||||
disconnect_events: Vec::new(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user