Updating sealing when new transactions are received
This commit is contained in:
@@ -92,7 +92,7 @@ pub trait MinerService : Send + Sync {
|
||||
fn chain_new_blocks(&self, chain: &BlockChainClient, imported: &[H256], invalid: &[H256], enacted: &[H256], retracted: &[H256]);
|
||||
|
||||
/// New chain head event. Restart mining operation.
|
||||
fn prepare_sealing(&self, chain: &BlockChainClient);
|
||||
fn update_sealing(&self, chain: &BlockChainClient);
|
||||
|
||||
/// Grab the `ClosedBlock` that we want to be sealed. Comes as a mutex that you have to lock.
|
||||
fn sealing_block(&self, chain: &BlockChainClient) -> &Mutex<Option<ClosedBlock>>;
|
||||
|
||||
@@ -95,10 +95,26 @@ impl Miner {
|
||||
self.transaction_queue.lock().unwrap().set_minimal_gas_price(min_gas_price);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
fn update_gas_limit(&self, chain: &BlockChainClient) {
|
||||
let gas_limit = HeaderView::new(&chain.best_block_header()).gas_limit();
|
||||
let mut queue = self.transaction_queue.lock().unwrap();
|
||||
queue.set_gas_limit(gas_limit);
|
||||
=======
|
||||
/// Prepares new block for sealing including top transactions from queue.
|
||||
pub fn prepare_sealing(&self, chain: &BlockChainClient) {
|
||||
let no_of_transactions = 128;
|
||||
// TODO: should select transactions orm queue according to gas limit of block.
|
||||
let transactions = self.transaction_queue.lock().unwrap().top_transactions(no_of_transactions);
|
||||
|
||||
let b = chain.prepare_sealing(
|
||||
self.author(),
|
||||
self.gas_floor_target(),
|
||||
self.extra_data(),
|
||||
transactions,
|
||||
);
|
||||
*self.sealing_block.lock().unwrap() = b;
|
||||
>>>>>>> b684bc9... Updating sealing when new transactions are received
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +122,7 @@ impl MinerService for Miner {
|
||||
|
||||
fn clear_and_reset(&self, chain: &BlockChainClient) {
|
||||
self.transaction_queue.lock().unwrap().clear();
|
||||
self.prepare_sealing(chain);
|
||||
self.update_sealing(chain);
|
||||
}
|
||||
|
||||
fn status(&self) -> MinerStatus {
|
||||
@@ -130,26 +146,10 @@ impl MinerService for Miner {
|
||||
transaction_queue.pending_hashes()
|
||||
}
|
||||
|
||||
fn prepare_sealing(&self, chain: &BlockChainClient) {
|
||||
let transactions = self.transaction_queue.lock().unwrap().top_transactions();
|
||||
let b = chain.prepare_sealing(
|
||||
self.author(),
|
||||
self.gas_floor_target(),
|
||||
self.extra_data(),
|
||||
transactions,
|
||||
);
|
||||
|
||||
*self.sealing_block.lock().unwrap() = b.map(|(block, invalid_transactions)| {
|
||||
let mut queue = self.transaction_queue.lock().unwrap();
|
||||
queue.remove_all(
|
||||
&invalid_transactions.into_iter().collect::<Vec<H256>>(),
|
||||
|a: &Address| AccountDetails {
|
||||
nonce: chain.nonce(a),
|
||||
balance: chain.balance(a),
|
||||
}
|
||||
);
|
||||
block
|
||||
});
|
||||
fn update_sealing(&self, chain: &BlockChainClient) {
|
||||
if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||
self.prepare_sealing(chain);
|
||||
}
|
||||
}
|
||||
|
||||
fn sealing_block(&self, chain: &BlockChainClient) -> &Mutex<Option<ClosedBlock>> {
|
||||
@@ -239,9 +239,6 @@ impl MinerService for Miner {
|
||||
});
|
||||
}
|
||||
|
||||
// Update mined block
|
||||
if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||
self.prepare_sealing(chain);
|
||||
}
|
||||
self.update_sealing(chain);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user