[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:
parent
b6415c6196
commit
19184e8529
@ -4,26 +4,27 @@ name = "ethcore-sync"
|
||||
version = "1.12.0"
|
||||
license = "GPL-3.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
bytes = { package = "parity-bytes", version = "0.1" }
|
||||
client-traits = { path = "../client-traits" }
|
||||
common-types = { path = "../types" }
|
||||
devp2p = { package = "ethcore-network-devp2p", path = "../../util/network-devp2p" }
|
||||
enum_primitive = "0.1.1"
|
||||
ethcore-io = { path = "../../util/io" }
|
||||
ethcore-light = { path = "../light" }
|
||||
ethcore-network = { path = "../../util/network" }
|
||||
ethcore-network-devp2p = { path = "../../util/network-devp2p" }
|
||||
ethcore-private-tx = { path = "../private-tx" }
|
||||
ethereum-types = "0.6.0"
|
||||
ethkey = { path = "../../accounts/ethkey" }
|
||||
fastmap = { path = "../../util/fastmap" }
|
||||
futures = "0.1"
|
||||
keccak-hash = "0.2.0"
|
||||
light = { package = "ethcore-light", path = "../light" }
|
||||
log = "0.4"
|
||||
macros = { path = "../../util/macros" }
|
||||
parity-bytes = "0.1"
|
||||
network = { package = "ethcore-network", path = "../../util/network" }
|
||||
parity-runtime = { path = "../../util/runtime" }
|
||||
parity-util-mem = "0.2.0"
|
||||
parking_lot = "0.8"
|
||||
|
@ -19,46 +19,54 @@ use std::collections::{HashMap, BTreeMap};
|
||||
use std::io;
|
||||
use std::ops::RangeInclusive;
|
||||
use std::time::Duration;
|
||||
use bytes::Bytes;
|
||||
use devp2p::NetworkService;
|
||||
use network::{NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
|
||||
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error,
|
||||
ConnectionFilter};
|
||||
use network::client_version::ClientVersion;
|
||||
use ethereum_types::{H256, H512, U256};
|
||||
use futures::sync::mpsc as futures_mpsc;
|
||||
use futures::Stream;
|
||||
use io::{TimerToken};
|
||||
use ethkey::Secret;
|
||||
use client_traits::{BlockChainClient, ChainNotify};
|
||||
use snapshot::SnapshotService;
|
||||
use ethcore_private_tx::PrivateStateDB;
|
||||
use types::BlockNumber;
|
||||
use sync_io::NetSyncIo;
|
||||
use chain::{ChainSyncApi, SyncStatus as EthSyncStatus};
|
||||
use std::net::{SocketAddr, AddrParseError};
|
||||
use std::str::FromStr;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
use chain::{ETH_PROTOCOL_VERSION_63, ETH_PROTOCOL_VERSION_62,
|
||||
PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2, PAR_PROTOCOL_VERSION_3, PAR_PROTOCOL_VERSION_4, SyncState};
|
||||
use chain::sync_packet::SyncPacket::{PrivateTransactionPacket, SignedPrivateTransactionPacket};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use crate::sync_io::NetSyncIo;
|
||||
use crate::light_sync::{self, SyncInfo};
|
||||
use crate::private_tx::PrivateTxHandler;
|
||||
use crate::chain::{
|
||||
sync_packet::SyncPacket::{PrivateTransactionPacket, SignedPrivateTransactionPacket},
|
||||
ChainSyncApi, SyncState, SyncStatus as EthSyncStatus, ETH_PROTOCOL_VERSION_62,
|
||||
ETH_PROTOCOL_VERSION_63, PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_2,
|
||||
PAR_PROTOCOL_VERSION_3, PAR_PROTOCOL_VERSION_4,
|
||||
};
|
||||
|
||||
use bytes::Bytes;
|
||||
use client_traits::{BlockChainClient, ChainNotify};
|
||||
use devp2p::NetworkService;
|
||||
use ethcore_io::TimerToken;
|
||||
use ethcore_private_tx::PrivateStateDB;
|
||||
use ethereum_types::{H256, H512, U256};
|
||||
use ethkey::Secret;
|
||||
use futures::sync::mpsc as futures_mpsc;
|
||||
use futures::Stream;
|
||||
use light::client::AsLightClient;
|
||||
use light::Provider;
|
||||
use light::net::{
|
||||
self as light_net, LightProtocol, Params as LightParams,
|
||||
Capabilities, Handler as LightHandler, EventContext, SampleStore,
|
||||
};
|
||||
use log::{trace, warn};
|
||||
use macros::hash_map;
|
||||
use network::{
|
||||
client_version::ClientVersion,
|
||||
NetworkProtocolHandler, NetworkContext, PeerId, ProtocolId,
|
||||
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, Error,
|
||||
ConnectionFilter, IpFilter
|
||||
};
|
||||
use snapshot::SnapshotService;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
use parity_runtime::Executor;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use network::IpFilter;
|
||||
use private_tx::PrivateTxHandler;
|
||||
use types::{
|
||||
use trace_time::trace_time;
|
||||
use common_types::{
|
||||
BlockNumber,
|
||||
chain_notify::{NewBlocks, ChainMessageType},
|
||||
pruning_info::PruningInfo,
|
||||
transaction::UnverifiedTransaction,
|
||||
};
|
||||
|
||||
use super::light_sync::SyncInfo;
|
||||
|
||||
/// Parity sync protocol
|
||||
pub const WARP_SYNC_PROTOCOL_ID: ProtocolId = *b"par";
|
||||
@ -646,14 +654,14 @@ impl ChainNotify for EthSync {
|
||||
struct TxRelay(Arc<dyn BlockChainClient>);
|
||||
|
||||
impl LightHandler for TxRelay {
|
||||
fn on_transactions(&self, ctx: &dyn EventContext, relay: &[::types::transaction::UnverifiedTransaction]) {
|
||||
fn on_transactions(&self, ctx: &dyn EventContext, relay: &[UnverifiedTransaction]) {
|
||||
trace!(target: "pip", "Relaying {} transactions from peer {}", relay.len(), ctx.peer());
|
||||
self.0.queue_transactions(relay.iter().map(|tx| ::rlp::encode(tx)).collect(), ctx.peer())
|
||||
self.0.queue_transactions(relay.iter().map(|tx| rlp::encode(tx)).collect(), ctx.peer())
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for managing network
|
||||
pub trait ManageNetwork : Send + Sync {
|
||||
pub trait ManageNetwork: Send + Sync {
|
||||
/// Set to allow unreserved peers to connect
|
||||
fn accept_unreserved_peers(&self);
|
||||
/// Set to deny unreserved peers to connect
|
||||
@ -945,15 +953,15 @@ impl LightSync {
|
||||
|
||||
}
|
||||
|
||||
impl ::std::ops::Deref for LightSync {
|
||||
type Target = dyn (::light_sync::SyncInfo);
|
||||
impl std::ops::Deref for LightSync {
|
||||
type Target = dyn (light_sync::SyncInfo);
|
||||
|
||||
fn deref(&self) -> &Self::Target { &*self.sync }
|
||||
}
|
||||
|
||||
|
||||
impl LightNetworkDispatcher for LightSync {
|
||||
fn with_context<F, T>(&self, f: F) -> Option<T> where F: FnOnce(&dyn (::light::net::BasicContext)) -> T {
|
||||
fn with_context<F, T>(&self, f: F) -> Option<T> where F: FnOnce(&dyn (light::net::BasicContext)) -> T {
|
||||
self.network.with_context_eval(
|
||||
self.subprotocol_name,
|
||||
move |ctx| self.proto.with_context(&ctx, f),
|
||||
|
@ -20,20 +20,24 @@
|
||||
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::cmp;
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
|
||||
use crate::{
|
||||
blocks::{BlockCollection, SyncBody, SyncHeader},
|
||||
chain::BlockSet,
|
||||
sync_io::SyncIo
|
||||
};
|
||||
|
||||
use ethereum_types::H256;
|
||||
use rlp::{self, Rlp};
|
||||
use types::{
|
||||
use log::{debug, trace};
|
||||
use network::{client_version::ClientCapabilities, PeerId};
|
||||
use rlp::Rlp;
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use common_types::{
|
||||
BlockNumber,
|
||||
block_status::BlockStatus,
|
||||
ids::BlockId,
|
||||
errors::{EthcoreError, BlockError, ImportError},
|
||||
};
|
||||
use sync_io::SyncIo;
|
||||
use blocks::{BlockCollection, SyncBody, SyncHeader};
|
||||
use chain::BlockSet;
|
||||
use network::PeerId;
|
||||
use network::client_version::ClientCapabilities;
|
||||
|
||||
const MAX_HEADERS_TO_REQUEST: usize = 128;
|
||||
const MAX_BODIES_TO_REQUEST_LARGE: usize = 128;
|
||||
@ -635,18 +639,23 @@ fn all_expected<A, B, F>(values: &[A], expected_values: &[B], is_expected: F) ->
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::{
|
||||
BlockSet, BlockDownloader, BlockDownloaderImportError, DownloadAction, SyncIo, H256,
|
||||
MAX_HEADERS_TO_REQUEST, MAX_USELESS_HEADERS_PER_ROUND, SUBCHAIN_SIZE, State, Rlp, VecDeque
|
||||
};
|
||||
|
||||
use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService};
|
||||
|
||||
use ethcore::test_helpers::TestBlockChainClient;
|
||||
use spec;
|
||||
use ethkey::{Generator, Random};
|
||||
use hash::keccak;
|
||||
use ethkey::{Random, Generator};
|
||||
use keccak_hash::keccak;
|
||||
use parking_lot::RwLock;
|
||||
use rlp::{encode_list, RlpStream};
|
||||
use tests::helpers::TestIo;
|
||||
use tests::snapshot::TestSnapshotService;
|
||||
use types::transaction::{Transaction, SignedTransaction};
|
||||
use triehash_ethereum::ordered_trie_root;
|
||||
use types::header::Header as BlockHeader;
|
||||
use common_types::{
|
||||
transaction::{Transaction, SignedTransaction},
|
||||
header::Header as BlockHeader,
|
||||
};
|
||||
|
||||
fn dummy_header(number: u64, parent_hash: H256) -> BlockHeader {
|
||||
let mut header = BlockHeader::new();
|
||||
@ -680,7 +689,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn import_headers_in_chain_head_state() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let spec = spec::new_test();
|
||||
let genesis_hash = spec.genesis_header().hash();
|
||||
@ -752,7 +761,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn import_headers_in_blocks_state() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let mut chain = TestBlockChainClient::new();
|
||||
let snapshot_service = TestSnapshotService::new();
|
||||
@ -802,7 +811,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn import_bodies() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let mut chain = TestBlockChainClient::new();
|
||||
let snapshot_service = TestSnapshotService::new();
|
||||
@ -870,7 +879,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn import_receipts() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let mut chain = TestBlockChainClient::new();
|
||||
let snapshot_service = TestSnapshotService::new();
|
||||
@ -929,7 +938,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn reset_after_multiple_sets_of_useless_headers() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let spec = spec::new_test();
|
||||
let genesis_hash = spec.genesis_header().hash();
|
||||
@ -969,7 +978,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn dont_reset_after_multiple_sets_of_useless_headers_for_chain_head() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
|
||||
let spec = spec::new_test();
|
||||
let genesis_hash = spec.genesis_header().hash();
|
||||
|
@ -15,14 +15,15 @@
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::collections::{HashSet, HashMap, hash_map};
|
||||
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use ethereum_types::H256;
|
||||
use triehash_ethereum::ordered_trie_root;
|
||||
|
||||
use bytes::Bytes;
|
||||
use ethereum_types::H256;
|
||||
use keccak_hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||
use log::{trace, warn};
|
||||
use parity_util_mem::MallocSizeOf;
|
||||
use rlp::{Rlp, RlpStream, DecoderError};
|
||||
use network;
|
||||
use types::{
|
||||
use triehash_ethereum::ordered_trie_root;
|
||||
use common_types::{
|
||||
transaction::UnverifiedTransaction,
|
||||
header::Header as BlockHeader,
|
||||
verification::Unverified,
|
||||
@ -40,7 +41,7 @@ pub struct SyncHeader {
|
||||
impl SyncHeader {
|
||||
pub fn from_rlp(bytes: Bytes) -> Result<Self, DecoderError> {
|
||||
let result = SyncHeader {
|
||||
header: ::rlp::decode(&bytes)?,
|
||||
header: rlp::decode(&bytes)?,
|
||||
bytes,
|
||||
};
|
||||
|
||||
@ -151,18 +152,7 @@ pub struct BlockCollection {
|
||||
impl BlockCollection {
|
||||
/// Create a new instance.
|
||||
pub fn new(download_receipts: bool) -> BlockCollection {
|
||||
BlockCollection {
|
||||
need_receipts: download_receipts,
|
||||
blocks: HashMap::new(),
|
||||
header_ids: HashMap::new(),
|
||||
receipt_ids: HashMap::new(),
|
||||
heads: Vec::new(),
|
||||
parents: HashMap::new(),
|
||||
head: None,
|
||||
downloading_headers: HashSet::new(),
|
||||
downloading_bodies: HashSet::new(),
|
||||
downloading_receipts: HashSet::new(),
|
||||
}
|
||||
Self { need_receipts: download_receipts, ..Default::default() }
|
||||
}
|
||||
|
||||
/// Clear everything.
|
||||
@ -545,12 +535,12 @@ mod test {
|
||||
use super::{BlockCollection, SyncHeader};
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore::test_helpers::{TestBlockChainClient, EachBlockWith};
|
||||
use types::{
|
||||
use common_types::{
|
||||
ids::BlockId,
|
||||
BlockNumber,
|
||||
verification::Unverified,
|
||||
};
|
||||
use rlp::*;
|
||||
use rlp::Rlp;
|
||||
|
||||
fn is_empty(bc: &BlockCollection) -> bool {
|
||||
bc.heads.is_empty() &&
|
||||
|
@ -14,22 +14,38 @@
|
||||
// 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 api::WARP_SYNC_PROTOCOL_ID;
|
||||
use block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction};
|
||||
use bytes::Bytes;
|
||||
use enum_primitive::FromPrimitive;
|
||||
use ethereum_types::{H256, U256};
|
||||
use hash::keccak;
|
||||
use network::PeerId;
|
||||
use network::client_version::ClientVersion;
|
||||
use rlp::Rlp;
|
||||
use std::time::Instant;
|
||||
use std::{mem, cmp};
|
||||
|
||||
use crate::{
|
||||
snapshot_sync::ChunkType,
|
||||
sync_io::SyncIo,
|
||||
api::WARP_SYNC_PROTOCOL_ID,
|
||||
block_sync::{BlockDownloaderImportError as DownloaderImportError, DownloadAction},
|
||||
chain::{
|
||||
sync_packet::{
|
||||
PacketInfo,
|
||||
SyncPacket::{
|
||||
self, BlockBodiesPacket, BlockHeadersPacket, NewBlockHashesPacket, NewBlockPacket,
|
||||
PrivateStatePacket, PrivateTransactionPacket, ReceiptsPacket, SignedPrivateTransactionPacket,
|
||||
SnapshotDataPacket, SnapshotManifestPacket, StatusPacket,
|
||||
}
|
||||
},
|
||||
BlockSet, ChainSync, ForkConfirmation, PacketDecodeError, PeerAsking, PeerInfo, SyncRequester,
|
||||
SyncState, ETH_PROTOCOL_VERSION_62, ETH_PROTOCOL_VERSION_63, MAX_NEW_BLOCK_AGE, MAX_NEW_HASHES,
|
||||
PAR_PROTOCOL_VERSION_1, PAR_PROTOCOL_VERSION_3, PAR_PROTOCOL_VERSION_4,
|
||||
}
|
||||
};
|
||||
use std::time::Instant;
|
||||
use std::{mem, cmp};
|
||||
use types::{
|
||||
|
||||
use bytes::Bytes;
|
||||
use enum_primitive::FromPrimitive;
|
||||
use ethereum_types::{H256, U256};
|
||||
use keccak_hash::keccak;
|
||||
use network::PeerId;
|
||||
use network::client_version::ClientVersion;
|
||||
use log::{debug, trace, error};
|
||||
use rlp::Rlp;
|
||||
use common_types::{
|
||||
BlockNumber,
|
||||
block_status::BlockStatus,
|
||||
ids::BlockId,
|
||||
@ -38,38 +54,6 @@ use types::{
|
||||
snapshot::{ManifestData, RestorationStatus},
|
||||
};
|
||||
|
||||
use super::sync_packet::{PacketInfo, SyncPacket};
|
||||
use super::sync_packet::SyncPacket::{
|
||||
StatusPacket,
|
||||
NewBlockHashesPacket,
|
||||
BlockHeadersPacket,
|
||||
BlockBodiesPacket,
|
||||
NewBlockPacket,
|
||||
ReceiptsPacket,
|
||||
SnapshotManifestPacket,
|
||||
SnapshotDataPacket,
|
||||
PrivateTransactionPacket,
|
||||
SignedPrivateTransactionPacket,
|
||||
PrivateStatePacket,
|
||||
};
|
||||
|
||||
use super::{
|
||||
BlockSet,
|
||||
ChainSync,
|
||||
ForkConfirmation,
|
||||
PacketDecodeError,
|
||||
PeerAsking,
|
||||
PeerInfo,
|
||||
SyncRequester,
|
||||
SyncState,
|
||||
ETH_PROTOCOL_VERSION_62,
|
||||
ETH_PROTOCOL_VERSION_63,
|
||||
MAX_NEW_BLOCK_AGE,
|
||||
MAX_NEW_HASHES,
|
||||
PAR_PROTOCOL_VERSION_1,
|
||||
PAR_PROTOCOL_VERSION_3,
|
||||
PAR_PROTOCOL_VERSION_4,
|
||||
};
|
||||
|
||||
/// The Chain Sync Handler: handles responses from peers
|
||||
pub struct SyncHandler;
|
||||
@ -800,21 +784,19 @@ impl SyncHandler {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use super::{
|
||||
super::tests::{dummy_sync_with_peer, get_dummy_block, get_dummy_blocks, get_dummy_hashes},
|
||||
SyncHandler
|
||||
};
|
||||
|
||||
use crate::tests::{helpers::TestIo, snapshot::TestSnapshotService};
|
||||
|
||||
use client_traits::ChainInfo;
|
||||
use ethcore::test_helpers::{EachBlockWith, TestBlockChainClient};
|
||||
use parking_lot::RwLock;
|
||||
use rlp::Rlp;
|
||||
use std::collections::VecDeque;
|
||||
use tests::helpers::TestIo;
|
||||
use tests::snapshot::TestSnapshotService;
|
||||
|
||||
use super::*;
|
||||
use super::super::tests::{
|
||||
dummy_sync_with_peer,
|
||||
get_dummy_block,
|
||||
get_dummy_blocks,
|
||||
get_dummy_hashes,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn handles_peer_new_hashes() {
|
||||
|
@ -88,38 +88,41 @@
|
||||
//! All other messages are ignored.
|
||||
|
||||
mod handler;
|
||||
pub mod sync_packet;
|
||||
mod propagator;
|
||||
mod requester;
|
||||
mod supplier;
|
||||
|
||||
pub mod sync_packet;
|
||||
|
||||
use std::sync::{Arc, mpsc};
|
||||
use std::collections::{HashSet, HashMap, BTreeMap};
|
||||
use std::cmp;
|
||||
use std::time::{Duration, Instant};
|
||||
use hash::keccak;
|
||||
use parity_util_mem::MallocSizeOfExt;
|
||||
use futures::sync::mpsc as futures_mpsc;
|
||||
use api::Notification;
|
||||
use ethereum_types::{H256, U256};
|
||||
use fastmap::{H256FastMap, H256FastSet};
|
||||
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
|
||||
use bytes::Bytes;
|
||||
use rlp::{RlpStream, DecoderError};
|
||||
use network::{self, PeerId, PacketId};
|
||||
use network::client_version::ClientVersion;
|
||||
use client_traits::BlockChainClient;
|
||||
|
||||
use crate::{
|
||||
EthProtocolInfo as PeerInfoDigest, PriorityTask, SyncConfig, WarpSync, WARP_SYNC_PROTOCOL_ID,
|
||||
api::{Notification, PRIORITY_TIMER_INTERVAL},
|
||||
block_sync::{BlockDownloader, DownloadAction},
|
||||
sync_io::SyncIo,
|
||||
snapshot_sync::Snapshot,
|
||||
transactions_stats::{TransactionsStats, Stats as TransactionStats},
|
||||
private_tx::PrivateTxHandler,
|
||||
};
|
||||
use super::{WarpSync, SyncConfig};
|
||||
use block_sync::{BlockDownloader, DownloadAction};
|
||||
|
||||
use bytes::Bytes;
|
||||
use client_traits::BlockChainClient;
|
||||
use ethereum_types::{H256, U256};
|
||||
use fastmap::{H256FastMap, H256FastSet};
|
||||
use futures::sync::mpsc as futures_mpsc;
|
||||
use keccak_hash::keccak;
|
||||
use log::{error, trace, debug};
|
||||
use network::client_version::ClientVersion;
|
||||
use network::{self, PeerId, PacketId};
|
||||
use parity_util_mem::{MallocSizeOfExt, malloc_size_of_is_0};
|
||||
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
|
||||
use rand::{Rng, seq::SliceRandom};
|
||||
use api::{EthProtocolInfo as PeerInfoDigest, WARP_SYNC_PROTOCOL_ID, PriorityTask};
|
||||
use private_tx::PrivateTxHandler;
|
||||
use transactions_stats::{TransactionsStats, Stats as TransactionStats};
|
||||
use types::{
|
||||
use rlp::{RlpStream, DecoderError};
|
||||
use common_types::{
|
||||
BlockNumber,
|
||||
ids::BlockId,
|
||||
transaction::UnverifiedTransaction,
|
||||
@ -434,7 +437,7 @@ impl ChainSyncApi {
|
||||
}
|
||||
|
||||
/// Returns transactions propagation statistics
|
||||
pub fn transactions_stats(&self) -> BTreeMap<H256, ::TransactionStats> {
|
||||
pub fn transactions_stats(&self) -> BTreeMap<H256, crate::api::TransactionStats> {
|
||||
self.sync.read().transactions_stats()
|
||||
.iter()
|
||||
.map(|(hash, stats)| (*hash, stats.into()))
|
||||
@ -463,7 +466,7 @@ impl ChainSyncApi {
|
||||
}
|
||||
|
||||
// deadline to get the task from the queue
|
||||
let deadline = Instant::now() + ::api::PRIORITY_TIMER_INTERVAL;
|
||||
let deadline = Instant::now() + PRIORITY_TIMER_INTERVAL;
|
||||
let mut work = || {
|
||||
let task = {
|
||||
let tasks = self.priority_tasks.try_lock_until(deadline)?;
|
||||
@ -1405,22 +1408,27 @@ impl ChainSync {
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use std::collections::{VecDeque};
|
||||
use ethkey;
|
||||
use network::PeerId;
|
||||
use tests::helpers::TestIo;
|
||||
use tests::snapshot::TestSnapshotService;
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use parking_lot::RwLock;
|
||||
use std::{collections::VecDeque, time::Instant};
|
||||
|
||||
use super::{
|
||||
BlockId, BlockQueueInfo, ChainSync, ClientVersion, PeerInfo, PeerAsking,
|
||||
SyncHandler, SyncState, SyncStatus, SyncPropagator, UnverifiedTransaction
|
||||
};
|
||||
|
||||
use crate::{
|
||||
api::SyncConfig,
|
||||
tests::{helpers::TestIo, snapshot::TestSnapshotService},
|
||||
};
|
||||
|
||||
use bytes::Bytes;
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use super::*;
|
||||
use ::SyncConfig;
|
||||
use super::{PeerInfo, PeerAsking};
|
||||
use ethcore::test_helpers::{EachBlockWith, TestBlockChainClient};
|
||||
use client_traits::{BlockInfo, BlockChainClient, ChainInfo};
|
||||
use ethcore::test_helpers::{EachBlockWith, TestBlockChainClient};
|
||||
use ethcore::miner::{MinerService, PendingOrdering};
|
||||
use types::header::Header;
|
||||
use ethereum_types::{H256, U256, Address};
|
||||
use network::PeerId;
|
||||
use parking_lot::RwLock;
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use common_types::header::Header;
|
||||
|
||||
pub fn get_dummy_block(order: u32, parent_hash: H256) -> Bytes {
|
||||
let mut header = Header::new();
|
||||
|
@ -17,19 +17,18 @@
|
||||
use std::cmp;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::{sync_io::SyncIo, chain::sync_packet::SyncPacket};
|
||||
|
||||
use bytes::Bytes;
|
||||
use ethereum_types::H256;
|
||||
use fastmap::H256FastSet;
|
||||
use log::{debug, error, trace};
|
||||
use network::client_version::ClientCapabilities;
|
||||
use network::PeerId;
|
||||
use rand::RngCore;
|
||||
use rlp::{Encodable, RlpStream};
|
||||
use sync_io::SyncIo;
|
||||
use types::transaction::SignedTransaction;
|
||||
use types::BlockNumber;
|
||||
use types::blockchain_info::BlockChainInfo;
|
||||
use common_types::{blockchain_info::BlockChainInfo, transaction::SignedTransaction, BlockNumber};
|
||||
|
||||
use super::sync_packet::SyncPacket;
|
||||
use super::sync_packet::SyncPacket::{
|
||||
NewBlockHashesPacket,
|
||||
TransactionsPacket,
|
||||
@ -335,17 +334,26 @@ impl SyncPropagator {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use client_traits::{BlockInfo, ChainInfo};
|
||||
use ethcore::test_helpers::{EachBlockWith, TestBlockChainClient};
|
||||
use parking_lot::RwLock;
|
||||
use rlp::Rlp;
|
||||
use std::collections::VecDeque;
|
||||
use tests::{
|
||||
helpers::TestIo,
|
||||
snapshot::TestSnapshotService,
|
||||
use std::{collections::VecDeque, time::Instant};
|
||||
|
||||
use crate::{
|
||||
api::SyncConfig,
|
||||
chain::{ChainSync, ForkConfirmation, PeerAsking, PeerInfo},
|
||||
tests::{helpers::TestIo, snapshot::TestSnapshotService},
|
||||
};
|
||||
|
||||
use super::{*, super::{*, tests::*}};
|
||||
use super::{
|
||||
super::tests::{dummy_sync_with_peer, insert_dummy_peer},
|
||||
SyncPropagator,
|
||||
};
|
||||
|
||||
use client_traits::{BlockChainClient, BlockInfo, ChainInfo};
|
||||
use ethcore::test_helpers::{EachBlockWith, TestBlockChainClient};
|
||||
use ethereum_types::{H256, U256};
|
||||
use network::client_version::ClientVersion;
|
||||
use parking_lot::RwLock;
|
||||
use rlp::Rlp;
|
||||
use common_types::{ids::BlockId, transaction::UnverifiedTransaction};
|
||||
|
||||
#[test]
|
||||
fn sends_new_hashes_to_lagging_peer() {
|
||||
|
@ -14,14 +14,19 @@
|
||||
// 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 block_sync::BlockRequest;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::{
|
||||
block_sync::BlockRequest,
|
||||
sync_io::SyncIo
|
||||
};
|
||||
|
||||
use bytes::Bytes;
|
||||
use ethereum_types::H256;
|
||||
use log::{debug, trace, warn};
|
||||
use network::{PeerId};
|
||||
use rlp::RlpStream;
|
||||
use std::time::Instant;
|
||||
use sync_io::SyncIo;
|
||||
use types::BlockNumber;
|
||||
use common_types::BlockNumber;
|
||||
|
||||
use super::sync_packet::SyncPacket;
|
||||
use super::sync_packet::SyncPacket::{
|
||||
|
@ -14,17 +14,18 @@
|
||||
// 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 std::cmp;
|
||||
|
||||
use crate::sync_io::SyncIo;
|
||||
|
||||
use bytes::Bytes;
|
||||
use enum_primitive::FromPrimitive;
|
||||
use ethereum_types::H256;
|
||||
use log::{debug, trace};
|
||||
use network::{self, PeerId};
|
||||
use parking_lot::RwLock;
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use std::cmp;
|
||||
use types::BlockNumber;
|
||||
use types::ids::BlockId;
|
||||
|
||||
use sync_io::SyncIo;
|
||||
use common_types::{ids::BlockId, BlockNumber};
|
||||
|
||||
use super::sync_packet::{PacketInfo, SyncPacket};
|
||||
use super::sync_packet::SyncPacket::{
|
||||
@ -394,18 +395,27 @@ impl SyncSupplier {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::VecDeque;
|
||||
use tests::helpers::TestIo;
|
||||
use tests::snapshot::TestSnapshotService;
|
||||
use ethereum_types::H256;
|
||||
use parking_lot::RwLock;
|
||||
use std::{collections::VecDeque, str::FromStr};
|
||||
|
||||
use crate::{
|
||||
blocks::SyncHeader,
|
||||
chain::RlpResponseResult,
|
||||
tests::{helpers::TestIo, snapshot::TestSnapshotService}
|
||||
};
|
||||
|
||||
use super::{
|
||||
SyncPacket::{GetReceiptsPacket, GetNodeDataPacket},
|
||||
BlockNumber, BlockId, SyncSupplier, PacketInfo
|
||||
};
|
||||
|
||||
use super::super::tests::dummy_sync_with_peer;
|
||||
|
||||
use bytes::Bytes;
|
||||
use rlp::{Rlp, RlpStream};
|
||||
use super::{*, super::tests::*};
|
||||
use blocks::SyncHeader;
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore::test_helpers::{EachBlockWith, TestBlockChainClient};
|
||||
use std::str::FromStr;
|
||||
use ethereum_types::H256;
|
||||
use parking_lot::RwLock;
|
||||
use rlp::{Rlp, RlpStream};
|
||||
|
||||
#[test]
|
||||
fn return_block_headers() {
|
||||
@ -426,7 +436,8 @@ mod test {
|
||||
rlp.append(&if reverse {1u32} else {0u32});
|
||||
rlp.out()
|
||||
}
|
||||
fn to_header_vec(rlp: ::chain::RlpResponseResult) -> Vec<SyncHeader> {
|
||||
|
||||
fn to_header_vec(rlp: RlpResponseResult) -> Vec<SyncHeader> {
|
||||
Rlp::new(&rlp.unwrap().unwrap().1.out()).iter().map(|r| SyncHeader::from_rlp(r.as_raw().to_vec()).unwrap()).collect()
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,10 @@
|
||||
//! to convert to/from the packet id values transmitted over the
|
||||
//! wire.
|
||||
|
||||
use api::{ETH_PROTOCOL, WARP_SYNC_PROTOCOL_ID};
|
||||
use crate::api::{ETH_PROTOCOL, WARP_SYNC_PROTOCOL_ID};
|
||||
use self::SyncPacket::*;
|
||||
|
||||
use enum_primitive::{enum_from_primitive, enum_from_primitive_impl, enum_from_primitive_impl_ty};
|
||||
use network::{PacketId, ProtocolId};
|
||||
|
||||
enum_from_primitive! {
|
||||
@ -60,12 +63,14 @@ enum_from_primitive! {
|
||||
}
|
||||
}
|
||||
|
||||
use self::SyncPacket::*;
|
||||
|
||||
/// Provide both subprotocol and packet id information within the
|
||||
/// same object.
|
||||
pub trait PacketInfo {
|
||||
/// Get packet id
|
||||
fn id(&self) -> PacketId;
|
||||
|
||||
/// Get protocol id
|
||||
fn protocol(&self) -> ProtocolId;
|
||||
}
|
||||
|
||||
@ -113,7 +118,6 @@ impl PacketInfo for SyncPacket {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use enum_primitive::FromPrimitive;
|
||||
|
||||
#[test]
|
||||
|
@ -21,47 +21,10 @@
|
||||
//! https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol
|
||||
//!
|
||||
|
||||
extern crate client_traits;
|
||||
extern crate common_types as types;
|
||||
extern crate ethcore_io as io;
|
||||
extern crate ethcore_light as light;
|
||||
extern crate ethcore_network as network;
|
||||
extern crate ethcore_network_devp2p as devp2p;
|
||||
extern crate ethcore_private_tx;
|
||||
extern crate ethereum_types;
|
||||
extern crate ethkey;
|
||||
extern crate fastmap;
|
||||
extern crate futures;
|
||||
extern crate keccak_hash as hash;
|
||||
extern crate parity_bytes as bytes;
|
||||
extern crate parity_runtime;
|
||||
extern crate parking_lot;
|
||||
extern crate rand;
|
||||
extern crate rlp;
|
||||
extern crate snapshot;
|
||||
extern crate triehash_ethereum;
|
||||
|
||||
#[cfg(test)] extern crate engine;
|
||||
#[cfg(test)] extern crate env_logger;
|
||||
#[cfg(test)] extern crate ethcore;
|
||||
#[cfg(test)] extern crate kvdb_memorydb;
|
||||
#[cfg(test)] extern crate machine;
|
||||
#[cfg(test)] extern crate rand_xorshift;
|
||||
#[cfg(test)] extern crate rustc_hex;
|
||||
#[cfg(test)] extern crate spec;
|
||||
|
||||
#[macro_use]
|
||||
extern crate enum_primitive;
|
||||
#[macro_use]
|
||||
extern crate macros;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate parity_util_mem;
|
||||
#[macro_use]
|
||||
extern crate parity_util_mem as malloc_size_of;
|
||||
#[macro_use]
|
||||
extern crate trace_time;
|
||||
// needed to make the procedural macro `MallocSizeOf` to work
|
||||
#[macro_use] extern crate parity_util_mem as malloc_size_of;
|
||||
|
||||
mod api;
|
||||
mod chain;
|
||||
mod blocks;
|
||||
mod block_sync;
|
||||
@ -75,8 +38,6 @@ pub mod light_sync;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
mod api;
|
||||
|
||||
pub use api::*;
|
||||
pub use chain::{SyncStatus, SyncState};
|
||||
pub use devp2p::validate_node_url;
|
||||
|
@ -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;
|
||||
|
@ -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(),
|
||||
}
|
||||
|
@ -14,21 +14,22 @@
|
||||
// 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 snapshot::SnapshotService;
|
||||
use ethereum_types::H256;
|
||||
use hash::keccak;
|
||||
use types::snapshot::ManifestData;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
use ethereum_types::H256;
|
||||
use keccak_hash::keccak;
|
||||
use log::trace;
|
||||
use snapshot::SnapshotService;
|
||||
use common_types::snapshot::ManifestData;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum ChunkType {
|
||||
State(H256),
|
||||
Block(H256),
|
||||
}
|
||||
|
||||
#[derive(MallocSizeOf)]
|
||||
#[derive(Default, MallocSizeOf)]
|
||||
pub struct Snapshot {
|
||||
pending_state_chunks: Vec<H256>,
|
||||
pending_block_chunks: Vec<H256>,
|
||||
@ -41,16 +42,8 @@ pub struct Snapshot {
|
||||
|
||||
impl Snapshot {
|
||||
/// Create a new instance.
|
||||
pub fn new() -> Snapshot {
|
||||
Snapshot {
|
||||
pending_state_chunks: Vec::new(),
|
||||
pending_block_chunks: Vec::new(),
|
||||
downloading_chunks: HashSet::new(),
|
||||
completed_chunks: HashSet::new(),
|
||||
snapshot_hash: None,
|
||||
bad_hashes: HashSet::new(),
|
||||
initialized: false,
|
||||
}
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
/// Sync the Snapshot completed chunks with the Snapshot Service
|
||||
@ -176,10 +169,11 @@ impl Snapshot {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use hash::keccak;
|
||||
use super::{ChunkType, H256, Snapshot};
|
||||
|
||||
use bytes::Bytes;
|
||||
use super::*;
|
||||
use types::snapshot::ManifestData;
|
||||
use keccak_hash::keccak;
|
||||
use common_types::snapshot::ManifestData;
|
||||
|
||||
fn is_empty(snapshot: &Snapshot) -> bool {
|
||||
snapshot.pending_block_chunks.is_empty() &&
|
||||
|
@ -16,15 +16,17 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use chain::sync_packet::{PacketInfo, SyncPacket};
|
||||
use network::{NetworkContext, PeerId, PacketId, Error, SessionInfo, ProtocolId};
|
||||
use network::client_version::ClientVersion;
|
||||
|
||||
use crate::chain::sync_packet::{PacketInfo, SyncPacket};
|
||||
|
||||
use bytes::Bytes;
|
||||
use client_traits::BlockChainClient;
|
||||
use ethcore_private_tx::PrivateStateDB;
|
||||
use types::BlockNumber;
|
||||
use snapshot::SnapshotService;
|
||||
use network::client_version::ClientVersion;
|
||||
use network::{NetworkContext, PeerId, PacketId, Error, SessionInfo, ProtocolId};
|
||||
use parking_lot::RwLock;
|
||||
use snapshot::SnapshotService;
|
||||
use common_types::BlockNumber;
|
||||
|
||||
/// IO interface for the syncing handler.
|
||||
/// Provides peer connection management and an interface to the blockchain client.
|
||||
|
@ -15,18 +15,20 @@
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use types::ids::BlockId;
|
||||
use client_traits::{BlockChainClient, ChainInfo};
|
||||
|
||||
use crate::{
|
||||
api::{SyncConfig, WarpSync},
|
||||
chain::SyncState,
|
||||
tests::helpers::TestNet,
|
||||
};
|
||||
|
||||
use client_traits::{BlockChainClient, BlockInfo, ChainInfo};
|
||||
use common_types::ids::BlockId;
|
||||
use ethcore::test_helpers::{TestBlockChainClient, EachBlockWith};
|
||||
use client_traits::BlockInfo;
|
||||
use chain::SyncState;
|
||||
use super::helpers::*;
|
||||
use {SyncConfig, WarpSync};
|
||||
use spec;
|
||||
|
||||
#[test]
|
||||
fn two_peers() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(3);
|
||||
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||
@ -37,7 +39,7 @@ fn two_peers() {
|
||||
|
||||
#[test]
|
||||
fn long_chain() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(2);
|
||||
net.peer(1).chain.add_blocks(50000, EachBlockWith::Nothing);
|
||||
net.sync();
|
||||
@ -47,7 +49,7 @@ fn long_chain() {
|
||||
|
||||
#[test]
|
||||
fn status_after_sync() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(3);
|
||||
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||
@ -67,7 +69,7 @@ fn takes_few_steps() {
|
||||
|
||||
#[test]
|
||||
fn empty_blocks() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(3);
|
||||
for n in 0..200 {
|
||||
let with = if n % 2 == 0 { EachBlockWith::Nothing } else { EachBlockWith::Uncle };
|
||||
@ -81,7 +83,7 @@ fn empty_blocks() {
|
||||
|
||||
#[test]
|
||||
fn forked() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(3);
|
||||
net.peer(0).chain.add_blocks(30, EachBlockWith::Uncle);
|
||||
net.peer(1).chain.add_blocks(30, EachBlockWith::Uncle);
|
||||
@ -102,7 +104,7 @@ fn forked() {
|
||||
|
||||
#[test]
|
||||
fn forked_with_misbehaving_peer() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(3);
|
||||
|
||||
let mut alt_spec = spec::new_test();
|
||||
@ -126,7 +128,7 @@ fn forked_with_misbehaving_peer() {
|
||||
|
||||
#[test]
|
||||
fn net_hard_fork() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let ref_client = TestBlockChainClient::new();
|
||||
ref_client.add_blocks(50, EachBlockWith::Uncle);
|
||||
{
|
||||
@ -145,7 +147,7 @@ fn net_hard_fork() {
|
||||
|
||||
#[test]
|
||||
fn restart() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(3);
|
||||
net.peer(1).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||
net.peer(2).chain.add_blocks(1000, EachBlockWith::Uncle);
|
||||
@ -229,7 +231,7 @@ fn propagate_blocks() {
|
||||
|
||||
#[test]
|
||||
fn restart_on_malformed_block() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(2);
|
||||
net.peer(1).chain.add_blocks(5, EachBlockWith::Nothing);
|
||||
net.peer(1).chain.add_block(EachBlockWith::Nothing, |mut header| {
|
||||
@ -255,7 +257,7 @@ fn reject_on_broken_chain() {
|
||||
|
||||
#[test]
|
||||
fn disconnect_on_unrelated_chain() {
|
||||
::env_logger::try_init().ok();
|
||||
env_logger::try_init().ok();
|
||||
let mut net = TestNet::new(2);
|
||||
net.peer(0).chain.set_history(Some(20));
|
||||
net.peer(1).chain.set_history(Some(20));
|
||||
|
@ -15,21 +15,24 @@
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use ethereum_types::{U256, Address};
|
||||
use io::{IoHandler, IoChannel};
|
||||
|
||||
use crate::{
|
||||
api::SyncConfig,
|
||||
tests::helpers::{TestIoHandler, TestNet},
|
||||
};
|
||||
|
||||
use client_traits::ChainInfo;
|
||||
use engine::signer;
|
||||
use spec;
|
||||
use ethcore::client::Client;
|
||||
use ethcore::miner::{self, MinerService};
|
||||
use ethcore_io::{IoHandler, IoChannel};
|
||||
use ethereum_types::{U256, Address};
|
||||
use ethkey::{KeyPair, Secret};
|
||||
use types::{
|
||||
use keccak_hash::keccak;
|
||||
use common_types::{
|
||||
io_message::ClientIoMessage,
|
||||
transaction::{Action, PendingTransaction, Transaction}
|
||||
};
|
||||
use super::helpers::*;
|
||||
use SyncConfig;
|
||||
|
||||
fn new_tx(secret: &Secret, nonce: U256, chain_id: u64) -> PendingTransaction {
|
||||
let signed = Transaction {
|
||||
|
@ -16,36 +16,42 @@
|
||||
|
||||
use std::collections::{VecDeque, HashSet, HashMap};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
api::{SyncConfig, WARP_SYNC_PROTOCOL_ID},
|
||||
chain::{
|
||||
sync_packet::{
|
||||
PacketInfo,
|
||||
SyncPacket::{self, PrivateTransactionPacket, SignedPrivateTransactionPacket}
|
||||
},
|
||||
ChainSync, SyncSupplier, ETH_PROTOCOL_VERSION_63, PAR_PROTOCOL_VERSION_4
|
||||
},
|
||||
private_tx::SimplePrivateTxHandler,
|
||||
sync_io::SyncIo,
|
||||
tests::snapshot::TestSnapshotService,
|
||||
};
|
||||
|
||||
use client_traits::{BlockChainClient, ChainNotify};
|
||||
use common_types::{
|
||||
chain_notify::{NewBlocks, ChainMessageType},
|
||||
io_message::ClientIoMessage,
|
||||
BlockNumber,
|
||||
};
|
||||
use ethcore::{
|
||||
client::{Client as EthcoreClient, ClientConfig},
|
||||
test_helpers::{self, TestBlockChainClient},
|
||||
};
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore_io::{IoChannel, IoContext, IoHandler};
|
||||
use ethcore_private_tx::PrivateStateDB;
|
||||
use ethereum_types::H256;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
use bytes::Bytes;
|
||||
use network::{self, PeerId, ProtocolId, PacketId, SessionInfo};
|
||||
use network::client_version::ClientVersion;
|
||||
use tests::snapshot::*;
|
||||
use types::{
|
||||
chain_notify::{NewBlocks, ChainMessageType},
|
||||
io_message::ClientIoMessage,
|
||||
};
|
||||
use client_traits::{BlockChainClient, ChainNotify};
|
||||
use ethcore::{
|
||||
client::{Client as EthcoreClient, ClientConfig},
|
||||
test_helpers::TestBlockChainClient
|
||||
};
|
||||
use log::trace;
|
||||
use snapshot::SnapshotService;
|
||||
use spec::{self, Spec};
|
||||
use ethcore_private_tx::PrivateStateDB;
|
||||
use ethcore::miner::Miner;
|
||||
use ethcore::test_helpers;
|
||||
use sync_io::SyncIo;
|
||||
use io::{IoChannel, IoContext, IoHandler};
|
||||
use api::WARP_SYNC_PROTOCOL_ID;
|
||||
use chain::{ChainSync, SyncSupplier, ETH_PROTOCOL_VERSION_63, PAR_PROTOCOL_VERSION_4};
|
||||
use chain::sync_packet::{PacketInfo, SyncPacket};
|
||||
use chain::sync_packet::SyncPacket::{PrivateTransactionPacket, SignedPrivateTransactionPacket};
|
||||
|
||||
use SyncConfig;
|
||||
use private_tx::SimplePrivateTxHandler;
|
||||
use types::BlockNumber;
|
||||
use spec::Spec;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
|
||||
pub trait FlushingBlockChainClient: BlockChainClient {
|
||||
fn flush(&self) {}
|
||||
@ -123,7 +129,7 @@ impl<'p, C> SyncIo for TestIo<'p, C> where C: FlushingBlockChainClient, C: 'p {
|
||||
|
||||
fn send(&mut self,peer_id: PeerId, packet_id: SyncPacket, data: Vec<u8>) -> Result<(), network::Error> {
|
||||
self.packets.push(TestPacket {
|
||||
data: data,
|
||||
data,
|
||||
packet_id: packet_id.id(),
|
||||
recipient: peer_id,
|
||||
});
|
||||
@ -135,11 +141,10 @@ impl<'p, C> SyncIo for TestIo<'p, C> where C: FlushingBlockChainClient, C: 'p {
|
||||
}
|
||||
|
||||
fn peer_version(&self, peer_id: PeerId) -> ClientVersion {
|
||||
let client_id = self.peers_info.get(&peer_id)
|
||||
self.peers_info.get(&peer_id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| peer_id.to_string());
|
||||
|
||||
ClientVersion::from(client_id)
|
||||
.unwrap_or_else(|| peer_id.to_string())
|
||||
.into()
|
||||
}
|
||||
|
||||
fn snapshot_service(&self) -> &dyn SnapshotService {
|
||||
|
@ -15,32 +15,38 @@
|
||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use io::{IoHandler, IoChannel};
|
||||
use types::transaction::{Transaction, Action};
|
||||
use types::{
|
||||
|
||||
use crate::{
|
||||
api::SyncConfig,
|
||||
tests::helpers::{TestIoHandler, TestNet}
|
||||
};
|
||||
|
||||
use client_traits::BlockChainClient;
|
||||
use common_types::{
|
||||
ids::BlockId,
|
||||
io_message::ClientIoMessage,
|
||||
transaction::{Transaction, Action},
|
||||
};
|
||||
use client_traits::BlockChainClient;
|
||||
use engine::signer;
|
||||
use ethcore::{
|
||||
client::Client,
|
||||
miner::{self, MinerService},
|
||||
test_helpers::{CreateContractAddress, push_block_with_transactions, new_db},
|
||||
};
|
||||
use ethcore_private_tx::{Provider, ProviderConfig, NoopEncryptor, Importer, SignedPrivateTransaction, StoringKeyProvider};
|
||||
use ethcore_io::{IoHandler, IoChannel};
|
||||
use ethcore_private_tx::{
|
||||
Provider, ProviderConfig, NoopEncryptor, Importer, SignedPrivateTransaction, StoringKeyProvider
|
||||
};
|
||||
use ethkey::KeyPair;
|
||||
use keccak_hash::keccak;
|
||||
use machine::executive::contract_address;
|
||||
use tests::helpers::{TestNet, TestIoHandler};
|
||||
use rustc_hex::FromHex;
|
||||
use rlp::Rlp;
|
||||
use spec::Spec;
|
||||
use SyncConfig;
|
||||
|
||||
fn seal_spec() -> Spec {
|
||||
let spec_data = include_str!("../res/private_spec.json");
|
||||
Spec::load(&::std::env::temp_dir(), spec_data.as_bytes()).unwrap()
|
||||
Spec::load(&std::env::temp_dir(), spec_data.as_bytes()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -16,37 +16,35 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use ethereum_types::H256;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use crate::{
|
||||
api::{SyncConfig, WarpSync},
|
||||
tests::helpers::TestNet
|
||||
};
|
||||
|
||||
use bytes::Bytes;
|
||||
use snapshot::SnapshotService;
|
||||
use ethcore::test_helpers::EachBlockWith;
|
||||
use types::{
|
||||
use ethereum_types::H256;
|
||||
use keccak_hash::keccak;
|
||||
use parking_lot::Mutex;
|
||||
use snapshot::SnapshotService;
|
||||
use common_types::{
|
||||
BlockNumber,
|
||||
snapshot::{ManifestData, RestorationStatus},
|
||||
};
|
||||
use super::helpers::*;
|
||||
use {SyncConfig, WarpSync};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TestSnapshotService {
|
||||
manifest: Option<ManifestData>,
|
||||
chunks: HashMap<H256, Bytes>,
|
||||
|
||||
restoration_manifest: Mutex<Option<ManifestData>>,
|
||||
state_restoration_chunks: Mutex<HashMap<H256, Bytes>>,
|
||||
block_restoration_chunks: Mutex<HashMap<H256, Bytes>>,
|
||||
}
|
||||
|
||||
impl TestSnapshotService {
|
||||
pub fn new() -> TestSnapshotService {
|
||||
TestSnapshotService {
|
||||
manifest: None,
|
||||
chunks: HashMap::new(),
|
||||
restoration_manifest: Mutex::new(None),
|
||||
state_restoration_chunks: Mutex::new(HashMap::new()),
|
||||
block_restoration_chunks: Mutex::new(HashMap::new()),
|
||||
}
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn new_with_snapshot(num_chunks: usize, block_hash: H256, block_number: BlockNumber) -> TestSnapshotService {
|
||||
|
@ -14,12 +14,14 @@
|
||||
// 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 api::TransactionStats;
|
||||
use std::hash::BuildHasher;
|
||||
use std::collections::{HashSet, HashMap};
|
||||
|
||||
use crate::api::TransactionStats;
|
||||
|
||||
use ethereum_types::{H256, H512};
|
||||
use fastmap::H256FastMap;
|
||||
use types::BlockNumber;
|
||||
use common_types::BlockNumber;
|
||||
|
||||
type NodeId = H512;
|
||||
|
||||
@ -89,9 +91,9 @@ impl TransactionsStats {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use super::{Stats, TransactionsStats, NodeId, H256};
|
||||
use macros::hash_map;
|
||||
|
||||
#[test]
|
||||
fn should_keep_track_of_propagations() {
|
||||
|
Loading…
Reference in New Issue
Block a user