From 364f98d49af79a9622f431a813e62ae773517c61 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Fri, 29 Sep 2023 11:42:38 +0900 Subject: [PATCH] refactor Signed-off-by: Naohiro Yoshida --- light-client/src/header/eth_headers.rs | 34 +++++++++----------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/light-client/src/header/eth_headers.rs b/light-client/src/header/eth_headers.rs index 0d216be..12f65b0 100644 --- a/light-client/src/header/eth_headers.rs +++ b/light-client/src/header/eth_headers.rs @@ -31,18 +31,13 @@ impl ETHHeaders { } // Ensure valid seals - let checkpoint = checkpoint(previous_validators); - if self.target.number % BLOCKS_PER_EPOCH >= checkpoint { - for h in self.all.iter() { + let epoch = self.target.number / BLOCKS_PER_EPOCH; + let checkpoint = epoch * BLOCKS_PER_EPOCH + checkpoint(previous_validators); + for h in self.all.iter() { + if h.number >= checkpoint { h.verify_seal(current_validators, chain_id)?; - } - } else { - for h in self.all.iter() { - if h.number % BLOCKS_PER_EPOCH >= checkpoint { - h.verify_seal(current_validators, chain_id)?; - } else { - h.verify_seal(previous_validators, chain_id)?; - } + } else { + h.verify_seal(previous_validators, chain_id)?; } } @@ -51,19 +46,12 @@ impl ETHHeaders { // Ensure BLS signature is collect // At the just checkpoint BLS signature uses previous validator set. - if self.target.number % BLOCKS_PER_EPOCH > checkpoint { - for h in headers_for_finalize { - let vote = h.get_vote_attestation()?; + for h in headers_for_finalize { + let vote = h.get_vote_attestation()?; + if h.number > checkpoint { vote.verify(h.number, current_validators)?; - } - } else { - for h in headers_for_finalize { - let vote = h.get_vote_attestation()?; - if h.number % BLOCKS_PER_EPOCH > checkpoint { - vote.verify(h.number, current_validators)?; - } else { - vote.verify(h.number, previous_validators)?; - } + } else { + vote.verify(h.number, previous_validators)?; } } Ok(())