mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
Explain why we defer signature verification (#668)
This commit is contained in:
committed by
Bastian Köcher
parent
0f56f18778
commit
5847020fdf
@@ -63,23 +63,25 @@ pub fn verify_justification<Header: HeaderT>(
|
|||||||
where
|
where
|
||||||
Header::Number: finality_grandpa::BlockNumberOps,
|
Header::Number: finality_grandpa::BlockNumberOps,
|
||||||
{
|
{
|
||||||
// decode justification first
|
// Decode justification first
|
||||||
let justification =
|
let justification =
|
||||||
GrandpaJustification::<Header>::decode(&mut &raw_justification[..]).map_err(|_| Error::JustificationDecode)?;
|
GrandpaJustification::<Header>::decode(&mut &raw_justification[..]).map_err(|_| Error::JustificationDecode)?;
|
||||||
|
|
||||||
// ensure that it is justification for the expected header
|
// Ensure that it is justification for the expected header
|
||||||
if (justification.commit.target_hash, justification.commit.target_number) != finalized_target {
|
if (justification.commit.target_hash, justification.commit.target_number) != finalized_target {
|
||||||
return Err(Error::InvalidJustificationTarget);
|
return Err(Error::InvalidJustificationTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate commit of the justification (it just assumes all signatures are valid)
|
// Validate commit of the justification. Note that `validate_commit()` assumes that all
|
||||||
|
// signatures are valid. We'll check the validity of the signatures later since they're more
|
||||||
|
// resource intensive to verify.
|
||||||
let ancestry_chain = AncestryChain::new(&justification.votes_ancestries);
|
let ancestry_chain = AncestryChain::new(&justification.votes_ancestries);
|
||||||
match finality_grandpa::validate_commit(&justification.commit, &authorities_set, &ancestry_chain) {
|
match finality_grandpa::validate_commit(&justification.commit, &authorities_set, &ancestry_chain) {
|
||||||
Ok(ref result) if result.ghost().is_some() => {}
|
Ok(ref result) if result.ghost().is_some() => {}
|
||||||
_ => return Err(Error::InvalidJustificationCommit),
|
_ => return Err(Error::InvalidJustificationCommit),
|
||||||
}
|
}
|
||||||
|
|
||||||
// now that we know that the commit is correct, check authorities signatures
|
// Now that we know that the commit is correct, check authorities signatures
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let mut visited_hashes = BTreeSet::new();
|
let mut visited_hashes = BTreeSet::new();
|
||||||
for signed in &justification.commit.precommits {
|
for signed in &justification.commit.precommits {
|
||||||
|
|||||||
Reference in New Issue
Block a user