Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save validator set hash in ExtraData for non-neighboring epoch verification #47

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tweak
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
  • Loading branch information
Naohiro Yoshida committed May 7, 2024
commit 8791eb24b97f328eb210a43854f62da137cf7662
16 changes: 6 additions & 10 deletions light-client/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ pub enum Error {
UnexpectedValidatorsHashSize(Vec<u8>),

// Header error
MissingPreviousEpochValidators(BlockNumber),
MissingCurrentEpochOrTrustedForNonNeighboringEpochValidators(BlockNumber),
MissingPreviousValidators(BlockNumber),
MissingCurrentValidators(BlockNumber),
OutOfTrustingPeriod(Time, Time),
HeaderFromFuture(Time, core::time::Duration, Time),
MissingTrustedHeight,
Expand Down Expand Up @@ -254,15 +254,11 @@ impl core::fmt::Display for Error {
Error::MissingValidatorInEpochBlock(e1) => {
write!(f, "MissingValidatorInEpochBlock : {:?}", e1)
}
Error::MissingPreviousEpochValidators(e1) => {
write!(f, "MissingPreviousEpochValidators : {:?}", e1)
Error::MissingPreviousValidators(e1) => {
write!(f, "MissingPreviousValidators : {:?}", e1)
}
Error::MissingCurrentEpochOrTrustedForNonNeighboringEpochValidators(e1) => {
write!(
f,
"MissingCurrentEpochOrTrustedForNonNeighboringEpochValidators : {:?}",
e1
)
Error::MissingCurrentValidators(e1) => {
write!(f, "MissingCurrentValidators : {:?}", e1)
}
Error::UnexpectedMixHash(e1) => {
write!(f, "UnexpectedMixHash : {:?}", e1)
Expand Down
16 changes: 7 additions & 9 deletions light-client/src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ impl Header {
self.previous_validators.hash
}

/// In non-adjacent epochs, current_validators contains the validator set of trusted_height,
/// so you need to use the validator set of extra_data of target.
pub fn current_epoch_validators_hash(&self) -> Result<Hash, Error> {
if self.headers.target.is_epoch() {
return Ok(self.headers.target.get_validator_set()?.hash);
Expand All @@ -88,7 +90,7 @@ impl Header {
) -> Result<(), Error> {
if self.is_non_neighboring_epoch() {
let n_val = self.headers.target.get_validator_set()?;
// 'current_validators' are trusted validators in non non-neighboring epoch verification.
// 'current_validators' are trusted validators in non-neighboring epoch verification.
let t_val = &self.current_validators;
let (t_val, n_val) = verify_validator_set_non_neighboring_epoch(
consensus_state,
Expand Down Expand Up @@ -251,15 +253,11 @@ impl TryFrom<RawHeader> for Header {
}

if value.previous_validators.is_empty() {
return Err(Error::MissingPreviousEpochValidators(headers.target.number));
return Err(Error::MissingPreviousValidators(headers.target.number));
}

if value.current_validators.is_empty() {
return Err(
Error::MissingCurrentEpochOrTrustedForNonNeighboringEpochValidators(
headers.target.number,
),
);
return Err(Error::MissingCurrentValidators(headers.target.number));
}

Ok(Self {
Expand Down Expand Up @@ -373,7 +371,7 @@ pub(crate) mod test {
};
let err = Header::try_from(raw).unwrap_err();
match err {
Error::MissingPreviousEpochValidators(number) => {
Error::MissingPreviousValidators(number) => {
assert_eq!(number, h.number);
}
err => unreachable!("{:?}", err),
Expand All @@ -396,7 +394,7 @@ pub(crate) mod test {
};
let err = Header::try_from(raw).unwrap_err();
match err {
Error::MissingCurrentEpochOrTrustedForNonNeighboringEpochValidators(number) => {
Error::MissingCurrentValidators(number) => {
assert_eq!(number, h.number);
}
err => unreachable!("{:?}", err),
Expand Down
Loading