Merge remote-tracking branch 'parity/master' into bft

Conflicts:
	ethcore/src/client/client.rs
	sync/src/api.rs
This commit is contained in:
keorn
2016-09-30 12:44:52 +01:00
99 changed files with 2515 additions and 897 deletions

View File

@@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::sync::Arc;
use std::str;
use network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId,
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, NetworkError};
use util::{U256, H256};
@@ -31,9 +32,9 @@ use std::str::FromStr;
use parking_lot::RwLock;
/// Ethereum sync protocol
pub const ETH_PROTOCOL: &'static str = "eth";
pub const ETH_PROTOCOL: [u8; 3] = *b"eth";
/// Infinity protocol
pub const INF_PROTOCOL: &'static str = "inf";
pub const INF_PROTOCOL: [u8; 3] = *b"inf";
/// Sync configuration
#[derive(Debug, Clone, Copy)]
@@ -42,6 +43,8 @@ pub struct SyncConfig {
pub max_download_ahead_blocks: usize,
/// Network ID
pub network_id: U256,
/// Main "eth" subprotocol name.
pub subprotocol_name: [u8; 3],
/// Fork block to check
pub fork_block: Option<(BlockNumber, H256)>,
}
@@ -51,6 +54,7 @@ impl Default for SyncConfig {
SyncConfig {
max_download_ahead_blocks: 20000,
network_id: U256::from(1),
subprotocol_name: ETH_PROTOCOL,
fork_block: None,
}
}
@@ -73,6 +77,8 @@ pub struct EthSync {
eth_handler: Arc<SyncProtocolHandler>,
/// Infinity Protocol handler
inf_handler: Arc<InfProtocolHandler>,
/// The main subprotocol name
subprotocol_name: [u8; 3],
}
impl EthSync {
@@ -85,6 +91,7 @@ impl EthSync {
network: service,
eth_handler: Arc::new(SyncProtocolHandler { sync: RwLock::new(chain_sync), chain: chain.clone(), snapshot_service: snapshot_service.clone() }),
inf_handler: Arc::new(InfProtocolHandler { sync: RwLock::new(inf_sync), chain: chain, snapshot_service: snapshot_service }),
subprotocol_name: config.subprotocol_name,
});
Ok(sync)
@@ -171,7 +178,7 @@ impl ChainNotify for EthSync {
sealed: Vec<H256>,
_duration: u64)
{
self.network.with_context(ETH_PROTOCOL, |context| {
self.network.with_context(self.subprotocol_name, |context| {
let mut sync_io = NetSyncIo::new(context, &*self.eth_handler.chain, &*self.eth_handler.snapshot_service);
self.eth_handler.sync.write().chain_new_blocks(
&mut sync_io,
@@ -185,7 +192,7 @@ impl ChainNotify for EthSync {
fn start(&self) {
self.network.start().unwrap_or_else(|e| warn!("Error starting network: {:?}", e));
self.network.register_protocol(self.eth_handler.clone(), ETH_PROTOCOL, &[62u8, 63u8, 64u8])
self.network.register_protocol(self.eth_handler.clone(), self.subprotocol_name, &[62u8, 63u8, 64u8])
.unwrap_or_else(|e| warn!("Error registering ethereum protocol: {:?}", e));
self.network.register_protocol(self.inf_handler.clone(), INF_PROTOCOL, &[1u8])
.unwrap_or_else(|e| warn!("Error registering infinity protocol: {:?}", e));
@@ -249,7 +256,7 @@ impl ManageNetwork for EthSync {
}
fn stop_network(&self) {
self.network.with_context(ETH_PROTOCOL, |context| {
self.network.with_context(self.subprotocol_name, |context| {
let mut sync_io = NetSyncIo::new(context, &*self.eth_handler.chain, &*self.eth_handler.snapshot_service);
self.eth_handler.sync.write().abort(&mut sync_io);
});