diff --git a/miner/src/lib.rs b/miner/src/lib.rs index 73ef2ad1..27cd1bde 100644 --- a/miner/src/lib.rs +++ b/miner/src/lib.rs @@ -15,7 +15,7 @@ mod cpu_miner; mod fee; mod memory_pool; -pub use block_assembler::BlockAssembler; +pub use block_assembler::{BlockAssembler, BlockTemplate}; pub use cpu_miner::find_solution; pub use memory_pool::{MemoryPool, Information as MemoryPoolInformation, OrderingStrategy as MemoryPoolOrderingStrategy}; pub use fee::{transaction_fee, transaction_fee_rate}; diff --git a/sync/src/lib.rs b/sync/src/lib.rs index fa78b3ed..edc9dd2d 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -77,6 +77,7 @@ pub fn create_local_sync_node(handle: &Handle, network: Magic, db: db::SharedSto use synchronization_verifier::AsyncVerifier; let sync_client_config = SynchronizationConfig { + network: network, // during regtests, peer is providing us with bad blocks => we shouldn't close connection because of this close_connection_on_bad_block: network != Magic::Regtest, // TODO: remove me diff --git a/sync/src/local_node.rs b/sync/src/local_node.rs index 4c5e3d7f..fe37c73d 100644 --- a/sync/src/local_node.rs +++ b/sync/src/local_node.rs @@ -11,6 +11,7 @@ use synchronization_executor::{Task as SynchronizationTask, TaskExecutor as Sync use synchronization_server::{Server, SynchronizationServer}; use synchronization_verifier::{AsyncVerifier, TransactionVerificationSink}; use primitives::hash::H256; +use miner::BlockTemplate; // TODO: check messages before processing (filterload' filter is max 36000, nHashFunc is <= 50, etc) @@ -262,6 +263,11 @@ impl LocalNode where T: SynchronizationTaskExecutor + PeersCon sink_data.wait() } + pub fn get_block_template(&self) -> BlockTemplate { + let client = self.client.lock(); + client.get_block_template() + } + fn transactions_inventory(&self, inventory: &[InventoryVector]) -> Vec { inventory.iter() .filter(|item| item.inv_type == InventoryType::MessageTx) diff --git a/sync/src/synchronization_client.rs b/sync/src/synchronization_client.rs index 437a08ee..6f027866 100644 --- a/sync/src/synchronization_client.rs +++ b/sync/src/synchronization_client.rs @@ -32,6 +32,8 @@ use miner::transaction_fee_rate; use verification::ChainVerifier; use time; use std::time::Duration; +use miner::{BlockAssembler, BlockTemplate}; +use network::Magic; #[cfg_attr(feature="cargo-clippy", allow(doc_markdown))] ///! TODO: update with headers-first corrections @@ -215,6 +217,7 @@ pub trait Client : Send + 'static { fn on_peer_disconnected(&mut self, peer_index: usize); fn after_peer_nearly_blocks_verified(&mut self, peer_index: usize, future: EmptyBoxFuture); fn accept_transaction(&mut self, transaction: Transaction, sink: Box) -> Result<(), String>; + fn get_block_template(&self) -> BlockTemplate; } /// Synchronization client trait @@ -238,6 +241,7 @@ pub trait ClientCore { fn on_peer_disconnected(&mut self, peer_index: usize); fn after_peer_nearly_blocks_verified(&mut self, peer_index: usize, future: EmptyBoxFuture); fn accept_transaction(&mut self, transaction: Transaction, sink: Box) -> Result, String>; + fn get_block_template(&self) -> BlockTemplate; fn execute_synchronization_tasks(&mut self, forced_blocks_requests: Option>, final_blocks_requests: Option>); fn try_switch_to_saturated_state(&mut self) -> bool; fn on_block_verification_success(&mut self, block: IndexedBlock) -> Option>; @@ -250,6 +254,8 @@ pub trait ClientCore { /// Synchronization client configuration options. #[derive(Debug)] pub struct Config { + /// Network + pub network: Magic, /// If true, connection to peer who has provided us with bad block is closed pub close_connection_on_bad_block: bool, /// Number of threads to allocate in synchronization CpuPool. @@ -514,6 +520,10 @@ impl Client for SynchronizationClient where T: TaskExecutor, U: Veri } Ok(()) } + + fn get_block_template(&self) -> BlockTemplate { + self.core.lock().get_block_template() + } } impl SynchronizationClient where T: TaskExecutor, U: Verifier { @@ -838,6 +848,14 @@ impl ClientCore for SynchronizationClientCore where T: TaskExecutor { } } + fn get_block_template(&self) -> BlockTemplate { + let block_assembler = BlockAssembler::default(); + let chain = self.chain.read(); + let store = chain.storage(); + let memory_pool = chain.memory_pool(); + block_assembler.create_new_block(&store, memory_pool, time::get_time().sec as u32, self.config.network) + } + /// Schedule new synchronization tasks, if any. fn execute_synchronization_tasks(&mut self, forced_blocks_requests: Option>, final_blocks_requests: Option>) { let mut tasks: Vec = Vec::new();