fn do_check_finality_proof<Block: BlockT<Hash=H256>, C, J>(
	check_execution_proof: C,
	parent_header: Block::Header,
	block: (NumberFor<Block>, Block::Hash),
	set_id: u64,
	remote_proof: Vec<u8>,
) -> ClientResult<Vec<Block::Header>>
	where
		NumberFor<Block>: grandpa::BlockNumberOps,
		C: Fn(&RemoteCallRequest<Block::Header>) -> ClientResult<Vec<u8>>,
		J: ProvableJustification<Block::Header>,
{
	// decode finality proof
	let proof = FinalityProof::<Block::Header, J>::decode(&mut &remote_proof[..])
		.ok_or_else(|| ClientErrorKind::BadJustification("failed to decode finality proof".into()))?;

	// check that the first header in finalization path is the block itself
	{
		let finalized_header = proof.finalization_path.first()
			.ok_or_else(|| ClientError::from(ClientErrorKind::BadJustification(
				"finality proof: finalized path is empty".into()
			)))?;
		if *finalized_header.number() != block.0 || finalized_header.hash() != block.1 {
			return Err(ClientErrorKind::BadJustification(
				"finality proof: block is not a part of finalized path".into()
			).into());
		}
	}

	// check that the last header in finalization path is the justification target block
	let just_block = proof.justification.target_block();
	{
		let finalized_header = proof.finalization_path.last()
			.expect("checked above that proof.finalization_path is not empty; qed");
		if *finalized_header.number() != just_block.0 || finalized_header.hash() != just_block.1 {
			return Err(ClientErrorKind::BadJustification(
				"finality proof: target justification block is not a part of finalized path".into()
			).into());
		}
	}

	// check authorities set proof && get grandpa authorities that should have signed justification
	let grandpa_authorities = check_execution_proof(&RemoteCallRequest {
		block: just_block.1,
		header: parent_header,
		method: "GrandpaApi_grandpa_authorities".into(),
		call_data: vec![],
		retry_count: None,
	})?;
	let grandpa_authorities: Vec<(AuthorityId, u64)> = Decode::decode(&mut &grandpa_authorities[..])
		.ok_or_else(|| ClientErrorKind::BadJustification("failed to decode GRANDPA authorities set proof".into()))?;

	// and now check justification
	proof.justification.verify(set_id, &grandpa_authorities.into_iter().collect())?;

	telemetry!(CONSENSUS_INFO; "afg.finality_proof_ok";
		"set_id" => ?set_id, "finalized_header_hash" => ?block.1);
	Ok(proof.finalization_path)
}
/// Check proof-of-finality using given justification type.
Check proof-of-finality using given justification type.
Check proof - of - finality using given justification type .
fn do_check_finality_proof<Block: BlockT<Hash=H256>, C, J>(
	check_execution_proof: C,
	parent_header: Block::Header,
	block: (NumberFor<Block>, Block::Hash),
	set_id: u64,
	remote_proof: Vec<u8>,
) -> ClientResult<Vec<Block::Header>>
	where
		NumberFor<Block>: grandpa::BlockNumberOps,
		C: Fn(&RemoteCallRequest<Block::Header>) -> ClientResult<Vec<u8>>,
		J: ProvableJustification<Block::Header>,
{
	// decode finality proof
	let proof = FinalityProof::<Block::Header, J>::decode(&mut &remote_proof[..])
		.ok_or_else(|| ClientErrorKind::BadJustification("failed to decode finality proof".into()))?;
	// check that the first header in finalization path is the block itself
	{
		let finalized_header = proof.finalization_path.first()
			.ok_or_else(|| ClientError::from(ClientErrorKind::BadJustification(
				"finality proof: finalized path is empty".into()
			)))?;
		if *finalized_header.number() != block.0 || finalized_header.hash() != block.1 {
			return Err(ClientErrorKind::BadJustification(
				"finality proof: block is not a part of finalized path".into()
			).into());
		}
	}
	// check that the last header in finalization path is the justification target block
	let just_block = proof.justification.target_block();
	{
		let finalized_header = proof.finalization_path.last()
			.expect("checked above that proof.finalization_path is not empty; qed");
		if *finalized_header.number() != just_block.0 || finalized_header.hash() != just_block.1 {
			return Err(ClientErrorKind::BadJustification(
				"finality proof: target justification block is not a part of finalized path".into()
			).into());
		}
	}
	// check authorities set proof && get grandpa authorities that should have signed justification
	let grandpa_authorities = check_execution_proof(&RemoteCallRequest {
		block: just_block.1,
		header: parent_header,
		method: "GrandpaApi_grandpa_authorities".into(),
		call_data: vec![],
		retry_count: None,
	})?;
	let grandpa_authorities: Vec<(AuthorityId, u64)> = Decode::decode(&mut &grandpa_authorities[..])
		.ok_or_else(|| ClientErrorKind::BadJustification("failed to decode GRANDPA authorities set proof".into()))?;
	// and now check justification
	proof.justification.verify(set_id, &grandpa_authorities.into_iter().collect())?;
	telemetry!(CONSENSUS_INFO; "afg.finality_proof_ok";
		"set_id" => ?set_id, "finalized_header_hash" => ?block.1);
	Ok(proof.finalization_path)
}
fn do_check_finality_proof < Block : BlockT < Hash = H256 > , C , J > ( check_execution_proof : C , parent_header : Block :: Header , block : ( NumberFor < Block > , Block :: Hash ) , set_id : u64 , remote_proof : Vec < u8 > , ) -> ClientResult < Vec < Block :: Header > > where NumberFor < Block > : grandpa :: BlockNumberOps , C : Fn ( & RemoteCallRequest < Block :: Header > ) -> ClientResult < Vec < u8 > > , J : ProvableJustification < Block :: Header > , { // decode finality proof let proof = FinalityProof :: < Block :: Header , J > :: decode ( & mut & remote_proof [ .. ] ) . ok_or_else ( | | ClientErrorKind :: BadJustification ( " " . into ( ) ) ) ? ; // check that the first header in finalization path is the block itself { let finalized_header = proof . finalization_path . first ( ) . ok_or_else ( | | ClientError :: from ( ClientErrorKind :: BadJustification ( " " . into ( ) ) ) ) ? ; if * finalized_header . number ( ) != block . 0 || finalized_header . hash ( ) != block . 1 { return Err ( ClientErrorKind :: BadJustification ( " " . into ( ) ) . into ( ) ) ; } } // check that the last header in finalization path is the justification target block let just_block = proof . justification . target_block ( ) ; { let finalized_header = proof . finalization_path . last ( ) . expect ( " " ) ; if * finalized_header . number ( ) != just_block . 0 || finalized_header . hash ( ) != just_block . 1 { return Err ( ClientErrorKind :: BadJustification ( " " . into ( ) ) . into ( ) ) ; } } // check authorities set proof && get grandpa authorities that should have signed justification let grandpa_authorities = check_execution_proof ( & RemoteCallRequest { block : just_block . 1 , header : parent_header , method : " " . into ( ) , call_data : vec ! [ ] , retry_count : None , } ) ? ; let grandpa_authorities : Vec < ( AuthorityId , u64 ) > = Decode :: decode ( & mut & grandpa_authorities [ .. ] ) . ok_or_else ( | | ClientErrorKind :: BadJustification ( " " . into ( ) ) ) ? ; // and now check justification proof . justification . verify ( set_id , & grandpa_authorities . into_iter ( ) . collect ( ) ) ? ; telemetry ! ( CONSENSUS_INFO " " " " set_id " " block 1 ) ; Ok ( proof . finalization_path ) }
Check proof-of-finality using given justification type.
Check proof - of - finality using given justification type .
check_execution_proof
C
parent_header
Block::Header
block
(NumberFor<Block>, Block::Hash)
set_id
u64
remote_proof
Vec<u8>
check_execution_proof
C
parent_header
Block::Header
block
(NumberFor<Block>, Block::Hash)
set_id
u64
remote_proof
Vec<u8>