client.rs 35 KiB
Newer Older
Nikolay Volf's avatar
Nikolay Volf committed
			&self.vm_factory,
			self.trie_factory.clone(),
Nikolay Volf's avatar
Nikolay Volf committed
			false,	// TODO: this will need to be parameterised once we want to do immediate mining insertion.
gregg dourgarian's avatar
gregg dourgarian committed
			&self.chain.block_header(&h).expect("h is best block hash: so its header must exist: qed"),
Nikolay Volf's avatar
Nikolay Volf committed
			self.build_last_hashes(h.clone()),
			author,
Gav Wood's avatar
Gav Wood committed
			gas_range_target,
Nikolay Volf's avatar
Nikolay Volf committed
			extra_data,
Gav Wood's avatar
Gav Wood committed
		).expect("OpenBlock::new only fails if parent state root invalid; state root of best block's header is never invalid; qed");
Nikolay Volf's avatar
Nikolay Volf committed

		// Add uncles
		self.chain
			.find_uncle_headers(&h, engine.maximum_uncle_age())
			.unwrap()
			.into_iter()
			.take(engine.maximum_uncle_count())
			.foreach(|h| {
Marek Kotewicz's avatar
Marek Kotewicz committed
				open_block.push_uncle(h).unwrap();
Nikolay Volf's avatar
Nikolay Volf committed
			});

Marek Kotewicz's avatar
Marek Kotewicz committed
		open_block
Nikolay Volf's avatar
Nikolay Volf committed
	}
NikVolf's avatar
NikVolf committed

	fn vm_factory(&self) -> &EvmFactory {
		&self.vm_factory
	}

	fn import_sealed_block(&self, block: SealedBlock) -> ImportResult {
		let _import_lock = self.import_lock.lock();
		let _timer = PerfTimer::new("import_sealed_block");

		let original_best = self.chain_info().best_block_hash;

		let h = block.header().hash();
		let number = block.header().number();

		let block_data = block.rlp_bytes();
		let route = self.commit_block(block, &h, &block_data);
		trace!(target: "client", "Imported sealed block #{} ({})", number, h);

		{
			let (enacted, retracted) = self.calculate_enacted_retracted(&[route]);
			self.miner.chain_new_blocks(self, &[h.clone()], &[], &enacted, &retracted);

			if let Some(notify) = self.notify() {
				notify.new_blocks(
					vec![h.clone()],
					vec![],
					enacted,
					retracted,
					vec![h.clone()],
				);
			}
		}

		if self.chain_info().best_block_hash != original_best {
			self.miner.update_sealing(self);
		}

		Ok(h)
	}
Tomusdrw's avatar
Tomusdrw committed
impl MayPanic for Client {
	fn on_panic<F>(&self, closure: F) where F: OnPanicListener {