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

Upgrade time window #175

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default-run = "nomic"
[dependencies]
bitcoin = { version = "0.29.2", features = ["serde", "rand"] }
bitcoind = { version = "0.27.0", features = ["22_0"], optional = true }
orga = { git = "https://github.com/nomic-io/orga.git", rev = "19d6718a574e882922418da293e4dcd82d800184", features = ["merk-verify"] }
orga = { git = "https://github.com/nomic-io/orga.git", rev = "c5e44ab1b1c008212c175c6c6c47aecaa5948307", features = ["merk-verify"] }
thiserror = "1.0.30"
ed = { git = "https://github.com/nomic-io/ed", rev = "9c0e206ffdb59dacb90f083e004e8080713e6ad8" }
clap = { version = "3.2.16", features = ["derive"], optional = true }
Expand Down
28 changes: 25 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,11 @@ mod abci {

impl BeginBlock for InnerApp {
fn begin_block(&mut self, ctx: &BeginBlockCtx) -> Result<()> {
self.upgrade
.step(&vec![Self::CONSENSUS_VERSION].try_into().unwrap())?;
let now = ctx.header.time.as_ref().unwrap().seconds;
self.upgrade.step(
&vec![Self::CONSENSUS_VERSION].try_into().unwrap(),
in_upgrade_window(now),
)?;
self.staking.begin_block(ctx)?;

#[cfg(feature = "testnet")]
Expand All @@ -389,7 +392,6 @@ mod abci {

self.bitcoin.begin_block(ctx)?;

let now = ctx.header.time.as_ref().unwrap().seconds;
let has_nbtc_rewards = self.bitcoin.reward_pool.amount > 0;
if self.reward_timer.tick(now) && has_stake && has_nbtc_rewards {
let reward_rate = (Amount::new(1) / Amount::new(2377))?; // ~0.00042069
Expand Down Expand Up @@ -962,3 +964,23 @@ impl RewardTimer {
true
}
}

fn in_upgrade_window(now_seconds: i64) -> bool {
use chrono::prelude::*;
let now = Utc.timestamp_opt(now_seconds, 0).unwrap();

// Monday - Friday, 17:00 - 17:10 UTC
now.weekday().num_days_from_monday() < 5 && now.hour() == 17 && now.minute() < 10
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn upgrade_date() {
assert!(in_upgrade_window(1690218300)); // Monday 17:05 UTC
assert!(!in_upgrade_window(1690219200)); // Monday 17:20 UTC
assert!(!in_upgrade_window(1690736700)); // Sunday 17:05 UTC
}
}
Loading