[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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user