pub fn process_block(&self, b: Block, opts: Options) -> Result<Option<Tip>, Error> {
		let head = self.store
			.head()
			.map_err(|e| Error::StoreErr(e, "chain load head".to_owned()))?;
		let height = head.height;
		let ctx = self.ctx_from_head(head, opts);

		let res = pipe::process_block(&b, ctx);

		match res {
			Ok(Some(ref tip)) => {
				// block got accepted and extended the head, updating our head
				let chain_head = self.head.clone();
				{
					let mut head = chain_head.lock().unwrap();
					*head = tip.clone();
				}

				// notifying other parts of the system of the update
				if !opts.intersects(SYNC) {
					// broadcast the block
					let adapter = self.adapter.clone();
					adapter.block_accepted(&b);
				}
				self.check_orphans();
			}
			Ok(None) => {}
			Err(Error::Orphan) => {
				// TODO - Do we want to check that orphan height is > current height?
				// TODO - Just check heights here? Or should we be checking total_difficulty as well?
				let block_hash = b.hash();
				if b.header.height < height + (MAX_ORPHANS as u64) {
					let mut orphans = self.orphans.lock().unwrap();
					orphans.push_front((opts, b));
					orphans.truncate(MAX_ORPHANS);
					debug!(
						LOGGER,
						"process_block: orphan: {:?}, # orphans {}",
						block_hash,
						orphans.len(),
					);
				} else {
					debug!(
						LOGGER,
						"process_block: orphan: {:?}, (dropping, height {} vs {})",
						block_hash,
						b.header.height,
						height,
					);
				}
			},
			Err(Error::Unfit(ref msg)) => {
				debug!(
					LOGGER,
					"Block {} at {} is unfit at this time: {}",
					b.hash(),
					b.header.height,
					msg
				);
			}
			Err(ref e) => {
				info!(
					LOGGER,
					"Rejected block {} at {}: {:?}",
					b.hash(),
					b.header.height,
					e
				);
			}
		}

		res
	}
/// Attempt to add a new block to the chain. Returns the new chain tip if it
/// has been added to the longest chain, None if it's added to an (as of
/// now) orphan chain.
Attempt to add a new block to the chain. Returns the new chain tip if it
has been added to the longest chain, None if it's added to an (as of
now) orphan chain.
Attempt to add a new block to the chain . Returns the new chain tip if it has been added to the longest chain None if it ' s added to an ( as of now ) orphan chain .
pub fn process_block(&self, b: Block, opts: Options) -> Result<Option<Tip>, Error> {
		let head = self.store
			.head()
			.map_err(|e| Error::StoreErr(e, "chain load head".to_owned()))?;
		let height = head.height;
		let ctx = self.ctx_from_head(head, opts);
		let res = pipe::process_block(&b, ctx);
		match res {
			Ok(Some(ref tip)) => {
				// block got accepted and extended the head, updating our head
				let chain_head = self.head.clone();
				{
					let mut head = chain_head.lock().unwrap();
					*head = tip.clone();
				}
				// notifying other parts of the system of the update
				if !opts.intersects(SYNC) {
					// broadcast the block
					let adapter = self.adapter.clone();
					adapter.block_accepted(&b);
				}
				self.check_orphans();
			}
			Ok(None) => {}
			Err(Error::Orphan) => {
				// TODO - Do we want to check that orphan height is > current height?
				// TODO - Just check heights here? Or should we be checking total_difficulty as well?
				let block_hash = b.hash();
				if b.header.height < height + (MAX_ORPHANS as u64) {
					let mut orphans = self.orphans.lock().unwrap();
					orphans.push_front((opts, b));
					orphans.truncate(MAX_ORPHANS);
					debug!(
						LOGGER,
						"process_block: orphan: {:?}, # orphans {}",
						block_hash,
						orphans.len(),
					);
				} else {
					debug!(
						LOGGER,
						"process_block: orphan: {:?}, (dropping, height {} vs {})",
						block_hash,
						b.header.height,
						height,
					);
				}
			},
			Err(Error::Unfit(ref msg)) => {
				debug!(
					LOGGER,
					"Block {} at {} is unfit at this time: {}",
					b.hash(),
					b.header.height,
					msg
				);
			}
			Err(ref e) => {
				info!(
					LOGGER,
					"Rejected block {} at {}: {:?}",
					b.hash(),
					b.header.height,
					e
				);
			}
		}
		res
	}
pub fn process_block ( & self , b : Block , opts : Options ) -> Result < Option < Tip > , Error > { let head = self . store . head ( ) . map_err ( | e | Error :: StoreErr ( e , " " . to_owned ( ) ) ) ? ; let height = head . height ; let ctx = self . ctx_from_head ( head , opts ) ; let res = pipe :: process_block ( & b , ctx ) ; match res { Ok ( Some ( ref tip ) ) => { // block got accepted and extended the head, updating our head let chain_head = self . head . clone ( ) ; { let mut head = chain_head . lock ( ) . unwrap ( ) ; * head = tip . clone ( ) ; } // notifying other parts of the system of the update if ! opts . intersects ( SYNC ) { // broadcast the block let adapter = self . adapter . clone ( ) ; adapter . block_accepted ( & b ) ; } self . check_orphans ( ) ; } Ok ( None ) => { } Err ( Error :: Orphan ) => { // TODO - Do we want to check that orphan height is > current height? // TODO - Just check heights here? Or should we be checking total_difficulty as well? let block_hash = b . hash ( ) ; if b . header . height < height + ( MAX_ORPHANS as u64 ) { let mut orphans = self . orphans . lock ( ) . unwrap ( ) ; orphans . push_front ( ( opts , b ) ) ; orphans . truncate ( MAX_ORPHANS ) ; debug ! ( LOGGER " " block_hash orphans len ( ) ) ; } else { debug ! ( LOGGER " " block_hash b header height height ) ; } } , Err ( Error :: Unfit ( ref msg ) ) => { debug ! ( LOGGER " " b hash ( ) b header height msg ) ; } Err ( ref e ) => { info ! ( LOGGER " " b hash ( ) b header height e ) ; } } res }
Attempt to add a new block to the chain.
Attempt to add a new block to the chain .
&self
b
Block
opts
Options