Updating sealing when new transactions are received
This commit is contained in:
		
							parent
							
								
									de484b2495
								
							
						
					
					
						commit
						b684bc9ba0
					
				@ -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>>;
 | 
			
		||||
 | 
			
		||||
@ -93,13 +93,28 @@ impl Miner {
 | 
			
		||||
	pub fn set_minimal_gas_price(&self, min_gas_price: U256) {
 | 
			
		||||
		self.transaction_queue.lock().unwrap().set_minimal_gas_price(min_gas_price);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/// 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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
@ -121,18 +136,10 @@ impl MinerService for Miner {
 | 
			
		||||
		transaction_queue.pending_hashes()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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;
 | 
			
		||||
	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>> {
 | 
			
		||||
@ -199,8 +206,6 @@ impl MinerService for Miner {
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
 | 
			
		||||
			self.prepare_sealing(chain);
 | 
			
		||||
		}
 | 
			
		||||
		self.update_sealing(chain);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -54,7 +54,7 @@ impl MinerService for TestMinerService {
 | 
			
		||||
	fn chain_new_blocks(&self, _chain: &BlockChainClient, _imported: &[H256], _invalid: &[H256], _enacted: &[H256], _retracted: &[H256]) { unimplemented!(); }
 | 
			
		||||
 | 
			
		||||
	/// New chain head event. Restart mining operation.
 | 
			
		||||
	fn prepare_sealing(&self, _chain: &BlockChainClient) { unimplemented!(); }
 | 
			
		||||
	fn update_sealing(&self, _chain: &BlockChainClient) { unimplemented!(); }
 | 
			
		||||
 | 
			
		||||
	/// 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>> {
 | 
			
		||||
 | 
			
		||||
@ -403,7 +403,7 @@ impl ChainSync {
 | 
			
		||||
							self.remove_downloaded_blocks(number + 1);
 | 
			
		||||
						}
 | 
			
		||||
						if self.have_common_block && number < self.current_base_block() + 1 {
 | 
			
		||||
							// unkown header 
 | 
			
		||||
							// unkown header
 | 
			
		||||
							debug!(target: "sync", "Old block header {:?} ({}) is unknown, restarting sync", hash, number);
 | 
			
		||||
							self.restart(io);
 | 
			
		||||
							return Ok(());
 | 
			
		||||
@ -947,7 +947,10 @@ impl ChainSync {
 | 
			
		||||
		}
 | 
			
		||||
		let chain = io.chain();
 | 
			
		||||
		let fetch_nonce = |a: &Address| chain.nonce(a);
 | 
			
		||||
		let _ = self.miner.import_transactions(transactions, fetch_nonce);
 | 
			
		||||
		let res = self.miner.import_transactions(transactions, fetch_nonce);
 | 
			
		||||
		if res.is_ok() {
 | 
			
		||||
			self.miner.update_sealing(io.chain());
 | 
			
		||||
		}
 | 
			
		||||
 		Ok(())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -1287,7 +1290,7 @@ impl ChainSync {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pub fn chain_new_head(&mut self, io: &mut SyncIo) {
 | 
			
		||||
		self.miner.prepare_sealing(io.chain());
 | 
			
		||||
		self.miner.update_sealing(io.chain());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user