From cbf846b41537ffeac3a1f425c79eff06ddbc8884 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 20 May 2021 02:09:13 +0300 Subject: [PATCH] Avoid hashing headers twice in verify_justification (#973) --- bridges/primitives/header-chain/src/justification.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bridges/primitives/header-chain/src/justification.rs b/bridges/primitives/header-chain/src/justification.rs index 139b430324391..e3bff85e504c3 100644 --- a/bridges/primitives/header-chain/src/justification.rs +++ b/bridges/primitives/header-chain/src/justification.rs @@ -109,12 +109,8 @@ where } } - let ancestry_hashes = justification - .votes_ancestries - .iter() - .map(|h: &Header| h.hash()) - .collect(); - if visited_hashes != ancestry_hashes { + // both iterators are `BTree*` iterators, so have the same order => safe to compare + if !visited_hashes.iter().eq(ancestry_chain.ancestry.keys()) { return Err(Error::InvalidPrecommitAncestries); }