-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zebrad): Refuse to run zebrad when release is too old (#6351)
* refuse to run Zebra if it is too old * update the release checklist to consider the constants * bring newline back * apply new end of support code * attempt to add tests (not working yet) * move eos to progress task * move tests * add acceptance test (not working) * fix tests * change to block height checks (ugly code) * change warn days * refactor estimated blocks per day, etc * move end of support code to its own task * change test * fix some docs * move constants * remove uneeded conversions * downgrade tracing * reduce end of support time, fix ci changing debugs to info again * update instructions * add failure messages * cargo lock update * unify releaase name constant * change info msg * clippy fixes * add a block explorer * ignore testnet in end of support task * change panic to 16 weeks * add some documentation about end of support * Tweak docs wording --------- Co-authored-by: teor <teor@riseup.net> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1f639ff
commit 58bd898
Showing
17 changed files
with
308 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//! End of support checking task. | ||
|
||
use std::time::Duration; | ||
|
||
use color_eyre::Report; | ||
use lazy_static::lazy_static; | ||
|
||
use zebra_chain::{ | ||
block::Height, | ||
chain_tip::ChainTip, | ||
parameters::{Network, NetworkUpgrade}, | ||
}; | ||
|
||
use zebra_network::constants::RELEASE_VERSION; | ||
|
||
lazy_static! { | ||
/// The name of the current Zebra release. | ||
pub static ref RELEASE_NAME: String = format!("Zebra {}", RELEASE_VERSION); | ||
} | ||
|
||
/// The estimated height that this release started to run. | ||
pub const ESTIMATED_RELEASE_HEIGHT: u32 = 2_026_000; | ||
|
||
/// The maximum number of days after `ESTIMATED_RELEASE_HEIGHT` where a Zebra server will run | ||
/// without halting. | ||
/// | ||
/// Notes: | ||
/// | ||
/// - Zebra will exit with a panic if the current tip height is bigger than the `ESTIMATED_RELEASE_HEIGHT` | ||
/// plus this number of days. | ||
pub const EOS_PANIC_AFTER: u32 = 112; | ||
|
||
/// The number of days before the end of support where Zebra will display warnings. | ||
pub const EOS_WARN_AFTER: u32 = EOS_PANIC_AFTER - 14; | ||
|
||
/// A string which is part of the panic that will be displayed if Zebra halts. | ||
pub const EOS_PANIC_MESSAGE_HEADER: &str = "Zebra refuses to run"; | ||
|
||
/// A string which is part of the warning that will be displayed if Zebra release is close to halting. | ||
pub const EOS_WARN_MESSAGE_HEADER: &str = "Your Zebra release is too old and it will stop running"; | ||
|
||
/// The amount of time between end of support checks. | ||
const CHECK_INTERVAL: Duration = Duration::from_secs(60 * 60); | ||
|
||
/// Wait a few seconds at startup so `best_tip_height` is always `Some`. | ||
const INITIAL_WAIT: Duration = Duration::from_secs(10); | ||
|
||
/// Start the end of support checking task for Mainnet. | ||
pub async fn start( | ||
network: Network, | ||
latest_chain_tip: impl ChainTip + std::fmt::Debug, | ||
) -> Result<(), Report> { | ||
info!("Starting end of support task"); | ||
|
||
tokio::time::sleep(INITIAL_WAIT).await; | ||
|
||
loop { | ||
if network == Network::Mainnet { | ||
if let Some(tip_height) = latest_chain_tip.best_tip_height() { | ||
check(tip_height, network); | ||
} | ||
} else { | ||
info!("Release always valid in Testnet"); | ||
} | ||
tokio::time::sleep(CHECK_INTERVAL).await; | ||
} | ||
} | ||
|
||
/// Check if the current release is too old and panic if so. | ||
pub fn check(tip_height: Height, network: Network) { | ||
info!("Checking if Zebra release is inside support range ..."); | ||
|
||
// Get the current block spacing | ||
let target_block_spacing = NetworkUpgrade::target_spacing_for_height(network, tip_height); | ||
|
||
// Get the number of blocks per day | ||
let estimated_blocks_per_day = | ||
u32::try_from(chrono::Duration::days(1).num_seconds() / target_block_spacing.num_seconds()) | ||
.expect("number is always small enough to fit"); | ||
|
||
let panic_height = | ||
Height(ESTIMATED_RELEASE_HEIGHT + (EOS_PANIC_AFTER * estimated_blocks_per_day)); | ||
let warn_height = | ||
Height(ESTIMATED_RELEASE_HEIGHT + (EOS_WARN_AFTER * estimated_blocks_per_day)); | ||
|
||
if tip_height > panic_height { | ||
panic!( | ||
"{EOS_PANIC_MESSAGE_HEADER} if the release date is older than {EOS_PANIC_AFTER} days. \ | ||
\nRelease name: {}, Estimated release height: {ESTIMATED_RELEASE_HEIGHT} \ | ||
\nHint: Download and install the latest Zebra release from: https://github.com/ZcashFoundation/zebra/releases/latest", | ||
*RELEASE_NAME | ||
); | ||
} else if tip_height > warn_height { | ||
warn!( | ||
"{EOS_WARN_MESSAGE_HEADER} at block {}. \ | ||
\nRelease name: {}, Estimated release height: {ESTIMATED_RELEASE_HEIGHT} \ | ||
\nHint: Download and install the latest Zebra release from: https://github.com/ZcashFoundation/zebra/releases/latest", panic_height.0, RELEASE_NAME.to_string() | ||
); | ||
} else { | ||
info!("Zebra release is supported until block {}, please report bugs at https://github.com/ZcashFoundation/zebra/issues", panic_height.0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.