diff --git a/lite/src/types.rs b/lite/src/types.rs index 08148c032..8a03caa42 100644 --- a/lite/src/types.rs +++ b/lite/src/types.rs @@ -37,6 +37,7 @@ pub trait Header { /// Validator type which can be used for verifying signatures. pub trait ValidatorSet { type Validator: Validator; + type ValidatorIter: ExactSizeIterator; /// Hash of the validator set. fn hash(&self) -> Hash; @@ -45,8 +46,7 @@ pub trait ValidatorSet { fn total_power(&self) -> u64; /// For iterating over the underlying validators. - /// TODO: make this iter() - fn into_vec(&self) -> Vec; + fn iter(&self) -> Self::ValidatorIter; } /// ValidatorSetLookup allows validator to be fetched via their ID @@ -68,6 +68,7 @@ pub trait Validator { /// for verification. pub trait Commit { type Vote: Vote; + type VoteIter: ExactSizeIterator>; /// Hash of the header this commit is for. fn header_hash(&self) -> Hash; @@ -77,7 +78,7 @@ pub trait Commit { /// we ignore absent votes and votes for nil here. /// NOTE: we may want to check signatures for nil votes, /// and thus use an ternary enum here instead of the binary Option. - fn into_vec(&self) -> Vec>; + fn iter(&self) -> Self::VoteIter; } /// Vote contains the data to verify a validator voted correctly in the commit. diff --git a/lite/src/verifier.rs b/lite/src/verifier.rs index 8619e534d..91d0ebe6a 100644 --- a/lite/src/verifier.rs +++ b/lite/src/verifier.rs @@ -99,18 +99,16 @@ where let total_power = vals.total_power(); let mut signed_power: u64 = 0; - let vals_vec = vals.into_vec(); - let commit_vec = commit.into_vec(); + let vals_iter = vals.iter(); + let commit_iter = commit.iter(); - if vals_vec.len() != commit_vec.len() { + if vals_iter.len() != commit_iter.len() { return Err(Error::InvalidCommitLength); } // The vals and commit have a 1-to-1 correspondance. // This means we don't need the validator IDs or to do any lookup, // we can just zip the iterators. - let vals_iter = vals_vec.iter(); - let commit_iter = commit_vec.iter(); for (val, vote_opt) in vals_iter.zip(commit_iter) { // skip absent and nil votes // NOTE: do we want to check the validity of votes @@ -151,8 +149,7 @@ where // NOTE we don't know the validators that committed this block, // so we have to check for each vote if its validator is already known. - let commit_vec = commit.into_vec(); - let commit_iter = commit_vec.iter(); + let commit_iter = commit.iter(); for vote_opt in commit_iter { // skip absent and nil votes // NOTE: do we want to check the validity of votes