feat(cli): add epoch next and watch subcommands#670
Draft
ByteYue wants to merge 2 commits into
Draft
Conversation
Two light additions on top of the existing `epoch status`:
- `epoch next` — one-line prediction of when the chain will next
transition epochs. Useful for "is my PR going to catch the boundary
I care about?" sanity checks without the full status breakdown.
Emits structured JSON with `--output json`.
- `epoch watch [--interval-secs 5] [--verbose]` — polls and prints
when the current epoch changes. Defaults to 5s, tolerates transient
RPC errors (logs and retries), and streams a `[epoch watch]` line
only on transitions unless `--verbose` is passed.
Also leaves an inline TODO in `epoch/mod.rs` for the consensus-layer
QC / ledger_info / validator_count queries that belong alongside the
epoch tooling but are blocked on the consensus HTTP API currently
being gated behind `#[cfg(debug_assertions)]` in release builds.
Shared contract-call helpers (`fetch_epoch_timing`, `format_hms`) live
in `epoch/next.rs` and are reused by `watch` so the two commands see
identical values.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two light additions on top of the existing
epoch status:epoch next— one-line prediction of when the chain will next transition epochs. Useful for "is my PR going to catch the boundary I care about?" sanity checks without the full status breakdown. Emits structured JSON with--output json.epoch watch [--interval-secs 5] [--verbose]— polls and prints when the current epoch changes. Defaults to 5s, tolerates transient RPC errors (logs and retries), and only prints a[epoch watch]line on transitions unless--verboseis passed.Scope note — QC / DKG future work
epoch/mod.rshas an inline TODO pointing at the consensus-layer queries (/consensus/qc/:epoch/:round,/consensus/ledger_info/:epoch,/consensus/validator_count/:epoch) that would belong alongside this tooling. They're intentionally not wired up: the blocker is thatcrates/api/src/consensus_api.rscurrently mounts those routes under#[cfg(debug_assertions)], so they're missing in release builds. Once that gate is lifted or moved to an opt-in flag, the TODO gives a future contributor everything they need to addepoch qc/epoch ledger-infoetc.Implementation notes
Shared contract-call helper
fetch_epoch_timingandformat_hmslive inepoch/next.rsand are reused bywatchso the two commands see identical values. The existingepoch statuscontinues to use its own (slightly richer) format so the behaviour users are already relying on is unchanged.Test plan
cargo build -p gravity_cli --profile quick-releaseclean withRUSTFLAGS="--cfg tokio_unstable"gravity-cli epoch --helplistsstatus / next / watchepoch nextwithout--rpc-url→ clean required-flag error withinithintepoch nextagainst unreachable RPC → clean error withnode starthintepoch watch --interval-secs 3 --verboseagainst a node without system contracts → emits retry lines rather than crashing (behaviour identical to existingepoch statusin the same scenario)--output jsonthreads intoepoch next