implemented get_block_template in local_node
This commit is contained in:
parent
b5035d6092
commit
b564770037
|
@ -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};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<T, U, V> LocalNode<T, U, V> 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<H256> {
|
||||
inventory.iter()
|
||||
.filter(|item| item.inv_type == InventoryType::MessageTx)
|
||||
|
|
|
@ -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<TransactionVerificationSink>) -> 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<TransactionVerificationSink>) -> Result<VecDeque<(H256, Transaction)>, String>;
|
||||
fn get_block_template(&self) -> BlockTemplate;
|
||||
fn execute_synchronization_tasks(&mut self, forced_blocks_requests: Option<Vec<H256>>, final_blocks_requests: Option<Vec<H256>>);
|
||||
fn try_switch_to_saturated_state(&mut self) -> bool;
|
||||
fn on_block_verification_success(&mut self, block: IndexedBlock) -> Option<Vec<VerificationTask>>;
|
||||
|
@ -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<T, U> Client for SynchronizationClient<T, U> where T: TaskExecutor, U: Veri
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_block_template(&self) -> BlockTemplate {
|
||||
self.core.lock().get_block_template()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> SynchronizationClient<T, U> where T: TaskExecutor, U: Verifier {
|
||||
|
@ -838,6 +848,14 @@ impl<T> ClientCore for SynchronizationClientCore<T> 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<Vec<H256>>, final_blocks_requests: Option<Vec<H256>>) {
|
||||
let mut tasks: Vec<Task> = Vec::new();
|
||||
|
|
Loading…
Reference in New Issue