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

fixed genesis time check #5

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ pub fn round_for_time(chain_info: &ChainInfo, time: SystemTime) -> Result<u64, D
return Err(DrandClientError::RoundBeforeGenesis);
}

Ok((epoch_seconds - chain_info.genesis_time) / chain_info.period_seconds as u64)
// at genesis, the round == 1, so we add 1
Ok((epoch_seconds - chain_info.genesis_time) / chain_info.period_seconds as u64 + 1)
}

#[derive(Error, Debug, PartialEq)]
Expand Down Expand Up @@ -272,7 +273,7 @@ mod test {
chain_hash: hex::decode("8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce").unwrap(),
group_hash: hex::decode("176f93498eac9ca337150b46d21dd58673ea4e3581185f869672e59fa4cb390a").unwrap(),
// here we set genesis so it should be round 3
genesis_time: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() - 90,
genesis_time: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() - 60,
period_seconds: 30,
metadata: ChainInfoMetadata {
beacon_id: "default".to_string(),
Expand Down
Loading