diff --git a/sync/src/inbound_connection.rs b/sync/src/inbound_connection.rs index 6ba483fd..cd7fba09 100644 --- a/sync/src/inbound_connection.rs +++ b/sync/src/inbound_connection.rs @@ -1,4 +1,4 @@ -use chain::{IndexedTransaction, IndexedBlock}; +use chain::{IndexedTransaction, IndexedBlock, IndexedBlockHeader}; use message::types; use p2p::{InboundSyncConnection, InboundSyncConnectionRef, InboundSyncConnectionStateRef}; use types::{PeersRef, LocalNodeRef, PeerIndex, RequestId}; @@ -103,7 +103,8 @@ impl InboundSyncConnection for InboundConnection { return; } - self.node.on_headers(self.peer_index, message); + let headers = message.headers.into_iter().map(IndexedBlockHeader::from_raw).collect(); + self.node.on_headers(self.peer_index, headers); } fn on_mempool(&self, message: types::MemPool) { diff --git a/sync/src/local_node.rs b/sync/src/local_node.rs index 51abbf1b..7f1e2861 100644 --- a/sync/src/local_node.rs +++ b/sync/src/local_node.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use parking_lot::{Mutex, Condvar}; use time; use futures::{lazy, finished}; -use chain::{IndexedTransaction, IndexedBlock}; +use chain::{IndexedTransaction, IndexedBlock, IndexedBlockHeader}; use keys::Address; use message::types; use miner::BlockAssembler; @@ -94,9 +94,9 @@ impl LocalNode where U: Server, V: Client { } /// When headers message is received - pub fn on_headers(&self, peer_index: PeerIndex, message: types::Headers) { - trace!(target: "sync", "Got `headers` message from peer#{}. Headers len: {}", peer_index, message.headers.len()); - self.client.on_headers(peer_index, message); + pub fn on_headers(&self, peer_index: PeerIndex, headers: Vec) { + trace!(target: "sync", "Got `headers` message from peer#{}. Headers len: {}", peer_index, headers.len()); + self.client.on_headers(peer_index, headers); } /// When transaction is received diff --git a/sync/src/synchronization_client.rs b/sync/src/synchronization_client.rs index 6ad1184b..f65ef474 100644 --- a/sync/src/synchronization_client.rs +++ b/sync/src/synchronization_client.rs @@ -1,6 +1,6 @@ use std::sync::Arc; use parking_lot::Mutex; -use chain::{IndexedTransaction, IndexedBlock}; +use chain::{IndexedTransaction, IndexedBlock, IndexedBlockHeader}; use message::types; use synchronization_executor::TaskExecutor; use synchronization_verifier::{Verifier, TransactionVerificationSink}; @@ -124,7 +124,7 @@ pub trait Client : Send + Sync + 'static { fn on_connect(&self, peer_index: PeerIndex); fn on_disconnect(&self, peer_index: PeerIndex); fn on_inventory(&self, peer_index: PeerIndex, message: types::Inv); - fn on_headers(&self, peer_index: PeerIndex, message: types::Headers); + fn on_headers(&self, peer_index: PeerIndex, headers: Vec); fn on_block(&self, peer_index: PeerIndex, block: IndexedBlock); fn on_transaction(&self, peer_index: PeerIndex, transaction: IndexedTransaction); fn on_notfound(&self, peer_index: PeerIndex, message: types::NotFound); @@ -160,8 +160,8 @@ impl Client for SynchronizationClient where T: TaskExecutor, U: Veri self.core.lock().on_inventory(peer_index, message); } - fn on_headers(&self, peer_index: PeerIndex, message: types::Headers) { - let headers_to_verify = self.core.lock().on_headers(peer_index, message); + fn on_headers(&self, peer_index: PeerIndex, headers: Vec) { + let headers_to_verify = self.core.lock().on_headers(peer_index, headers); if let Some(headers_to_verify) = headers_to_verify { self.light_verifier.verify_headers(peer_index, headers_to_verify); } diff --git a/sync/src/synchronization_client_core.rs b/sync/src/synchronization_client_core.rs index 8a6a1008..5ee72c36 100644 --- a/sync/src/synchronization_client_core.rs +++ b/sync/src/synchronization_client_core.rs @@ -72,7 +72,7 @@ pub trait ClientCore { fn on_connect(&mut self, peer_index: PeerIndex); fn on_disconnect(&mut self, peer_index: PeerIndex); fn on_inventory(&self, peer_index: PeerIndex, message: types::Inv); - fn on_headers(&mut self, peer_index: PeerIndex, message: types::Headers) -> Option>; + fn on_headers(&mut self, peer_index: PeerIndex, headers: Vec) -> Option>; fn on_block(&mut self, peer_index: PeerIndex, block: IndexedBlock) -> Option>; fn on_transaction(&mut self, peer_index: PeerIndex, transaction: IndexedTransaction) -> Option>; fn on_notfound(&mut self, peer_index: PeerIndex, message: types::NotFound); @@ -254,11 +254,8 @@ impl ClientCore for SynchronizationClientCore where T: TaskExecutor { } /// Try to queue synchronization of unknown blocks when blocks headers are received. - fn on_headers(&mut self, peer_index: PeerIndex, message: types::Headers) -> Option> { - assert!(!message.headers.is_empty(), "This must be checked in incoming connection"); - - // transform to indexed headers - let headers: Vec<_> = message.headers.into_iter().map(IndexedBlockHeader::from_raw).collect(); + fn on_headers(&mut self, peer_index: PeerIndex, headers: Vec) -> Option> { + assert!(! headers.is_empty(), "This must be checked in incoming connection"); // update peers to select next tasks self.peers_tasks.on_headers_received(peer_index);