From e91b338191c6c58803ce84e8e04c318715bd0e6c Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 17 Oct 2024 12:08:55 +1100 Subject: [PATCH] feat(cli): lotus chain head --height to print epoch number A simpler version of what's currently possible with: lotus chain list --format '' --count 1 --- CHANGELOG.md | 3 +-- cli/chain.go | 14 ++++++++++++-- documentation/en/cli-lotus.md | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ecf7d0768..e287a49148b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Reduce size of embedded genesis CAR files by removing WASM actor blocks and compressing with zstd. This reduces the `lotus` binary size by approximately 10 MiB. ([filecoin-project/lotus#12439](https://github.com/filecoin-project/lotus/pull/12439)) - Add ChainSafe operated Calibration archival node to the bootstrap list ([filecoin-project/lotus#12517](https://github.com/filecoin-project/lotus/pull/12517)) - Fix hotloop in F3 pariticpation API ([filecoin-project/lotus#12575](https://github.com/filecoin-project/lotus/pull/12575)) +- `lotus chain head` now supports a `--height` flag to print just the epoch number of the current chain head ([filecoin-project/lotus#12609](https://github.com/filecoin-project/lotus/pull/12609)) ## Bug Fixes - Fix a bug in the `lotus-shed indexes backfill-events` command that may result in either duplicate events being backfilled where there are existing events (such an operation *should* be idempotent) or events erroneously having duplicate `logIndex` values when queried via ETH APIs. ([filecoin-project/lotus#12567](https://github.com/filecoin-project/lotus/pull/12567)) @@ -15,8 +16,6 @@ ## Improvements -## Improvements - ## Deps # UNRELEASED Node v1.30.0 diff --git a/cli/chain.go b/cli/chain.go index f941061d5d9..e04a715ac1e 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -72,6 +72,12 @@ var ChainCmd = &cli.Command{ var ChainHeadCmd = &cli.Command{ Name: "head", Usage: "Print chain head", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "height", + Usage: "print just the epoch number of the chain head", + }, + }, Action: func(cctx *cli.Context) error { afmt := NewAppFmt(cctx.App) @@ -87,8 +93,12 @@ var ChainHeadCmd = &cli.Command{ return err } - for _, c := range head.Cids() { - afmt.Println(c) + if cctx.Bool("height") { + afmt.Println(head.Height()) + } else { + for _, c := range head.Cids() { + afmt.Println(c) + } } return nil }, diff --git a/documentation/en/cli-lotus.md b/documentation/en/cli-lotus.md index 7ec4f78a930..02950a2ba56 100644 --- a/documentation/en/cli-lotus.md +++ b/documentation/en/cli-lotus.md @@ -1616,6 +1616,7 @@ USAGE: lotus chain head [command options] [arguments...] OPTIONS: + --height print just the epoch number of the chain head (default: false) --help, -h show help ```