Skip to content

Commit 0a51a0a

Browse files
committed
feat!: build: separate miner and node version strings
Ref: #12010
1 parent cf8d187 commit 0a51a0a

File tree

25 files changed

+72
-37
lines changed

25 files changed

+72
-37
lines changed

api/docgen-openrpc/openrpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func NewLotusOpenRPCDocument(Comments, GroupDocs map[string]string) *go_openrpc_
106106
title := "Lotus RPC API"
107107
info.Title = (*meta_schema.InfoObjectProperties)(&title)
108108

109-
version := build.BuildVersion
109+
version := build.NodeBuildVersion
110110
info.Version = (*meta_schema.InfoObjectVersion)(&version)
111111
return info
112112
},

build/panic_reporter.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,31 @@ var PanicReportingPath = "panic-reports"
2828
// the lotus journal to be included in the panic report.
2929
var PanicReportJournalTail = defaultJournalTail
3030

31-
// GeneratePanicReport produces a timestamped dump of the application state
31+
// GenerateNodePanicReport produces a timestamped dump of the application state
3232
// for inspection and debugging purposes. Call this function from any place
3333
// where a panic or severe error needs to be examined. `persistPath` is the
3434
// path where the reports should be saved. `repoPath` is the path where the
3535
// journal should be read from. `label` is an optional string to include
3636
// next to the report timestamp.
37-
func GeneratePanicReport(persistPath, repoPath, label string) {
37+
//
38+
// This function should be called for panics originating from the Lotus daemon.
39+
func GenerateNodePanicReport(persistPath, repoPath, label string) {
40+
generatePanicReport(NodeUserVersion(), persistPath, repoPath, label)
41+
}
42+
43+
// GenerateMinerPanicReport produces a timestamped dump of the application state
44+
// for inspection and debugging purposes. Call this function from any place
45+
// where a panic or severe error needs to be examined. `persistPath` is the
46+
// path where the reports should be saved. `repoPath` is the path where the
47+
// journal should be read from. `label` is an optional string to include
48+
// next to the report timestamp.
49+
//
50+
// This function should be called for panics originating from the Lotus miner.
51+
func GenerateMinerPanicReport(persistPath, repoPath, label string) {
52+
generatePanicReport(MinerUserVersion(), persistPath, repoPath, label)
53+
}
54+
55+
func generatePanicReport(buildVersion BuildVersion, persistPath, repoPath, label string) {
3856
// make sure we always dump the latest logs on the way out
3957
// especially since we're probably panicking
4058
defer panicLog.Sync() //nolint:errcheck
@@ -64,21 +82,21 @@ func GeneratePanicReport(persistPath, repoPath, label string) {
6482
return
6583
}
6684

67-
writeAppVersion(filepath.Join(reportPath, "version"))
85+
writeAppVersion(buildVersion, filepath.Join(reportPath, "version"))
6886
writeStackTrace(filepath.Join(reportPath, "stacktrace.dump"))
6987
writeProfile("goroutines", filepath.Join(reportPath, "goroutines.pprof.gz"))
7088
writeProfile("heap", filepath.Join(reportPath, "heap.pprof.gz"))
7189
writeJournalTail(PanicReportJournalTail, repoPath, filepath.Join(reportPath, "journal.ndjson"))
7290
}
7391

74-
func writeAppVersion(file string) {
92+
func writeAppVersion(buildVersion BuildVersion, file string) {
7593
f, err := os.Create(file)
7694
if err != nil {
7795
panicLog.Error(err.Error())
7896
}
7997
defer f.Close() //nolint:errcheck
8098

81-
versionString := []byte(BuildVersion + BuildTypeString() + CurrentCommit + "\n")
99+
versionString := []byte(string(buildVersion) + BuildTypeString() + CurrentCommit + "\n")
82100
if _, err := f.Write(versionString); err != nil {
83101
panicLog.Error(err.Error())
84102
}

build/version.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package build
22

33
import "os"
44

5+
type BuildVersion string
6+
57
var CurrentCommit string
68
var BuildType int
79

@@ -36,13 +38,24 @@ func BuildTypeString() string {
3638
}
3739
}
3840

39-
// BuildVersion is the local build version
40-
const BuildVersion = "1.27.1-dev"
41+
// NodeBuildVersion is the local build version of the Lotus daemon
42+
const NodeBuildVersion string = "1.27.1-dev"
43+
44+
func NodeUserVersion() BuildVersion {
45+
if os.Getenv("LOTUS_VERSION_IGNORE_COMMIT") == "1" {
46+
return BuildVersion(NodeBuildVersion)
47+
}
48+
49+
return BuildVersion(NodeBuildVersion + BuildTypeString() + CurrentCommit)
50+
}
51+
52+
// MinerBuildVersion is the local build version of the Lotus miner
53+
const MinerBuildVersion = "1.27.1-dev"
4154

42-
func UserVersion() string {
55+
func MinerUserVersion() BuildVersion {
4356
if os.Getenv("LOTUS_VERSION_IGNORE_COMMIT") == "1" {
44-
return BuildVersion
57+
return BuildVersion(MinerBuildVersion)
4558
}
4659

47-
return BuildVersion + BuildTypeString() + CurrentCommit
60+
return BuildVersion(MinerBuildVersion + BuildTypeString() + CurrentCommit)
4861
}

chain/beacon/drand/drand.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
9797
if err != nil {
9898
return nil, xerrors.Errorf("could not create http drand client: %w", err)
9999
}
100-
hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.BuildVersion)
100+
hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.NodeBuildVersion)
101101
clients = append(clients, hc)
102102

103103
}

cmd/lotus-bench/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func main() {
100100
app := &cli.App{
101101
Name: "lotus-bench",
102102
Usage: "Benchmark performance of lotus on your hardware",
103-
Version: build.UserVersion(),
103+
Version: string(build.NodeUserVersion()),
104104
DisableSliceFlagSeparator: true,
105105
Commands: []*cli.Command{
106106
proveCmd,

cmd/lotus-fountain/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func main() {
4141
app := &cli.App{
4242
Name: "lotus-fountain",
4343
Usage: "Devnet token distribution utility",
44-
Version: build.UserVersion(),
44+
Version: string(build.NodeUserVersion()),
4545
Flags: []cli.Flag{
4646
&cli.StringFlag{
4747
Name: "repo",

cmd/lotus-gateway/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func main() {
4040
app := &cli.App{
4141
Name: "lotus-gateway",
4242
Usage: "Public API server for lotus",
43-
Version: build.UserVersion(),
43+
Version: string(build.NodeUserVersion()),
4444
Flags: []cli.Flag{
4545
&cli.StringFlag{
4646
Name: "repo",

cmd/lotus-health/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func main() {
3636
app := &cli.App{
3737
Name: "lotus-health",
3838
Usage: "Tools for monitoring lotus daemon health",
39-
Version: build.UserVersion(),
39+
Version: string(build.NodeUserVersion()),
4040
Commands: local,
4141
Flags: []cli.Flag{
4242
&cli.StringFlag{

cmd/lotus-miner/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func main() {
101101
app := &cli.App{
102102
Name: "lotus-miner",
103103
Usage: "Filecoin decentralized storage network miner",
104-
Version: build.UserVersion(),
104+
Version: string(build.MinerUserVersion()),
105105
EnableBashCompletion: true,
106106
Flags: []cli.Flag{
107107
&cli.StringFlag{
@@ -159,7 +159,7 @@ func main() {
159159
After: func(c *cli.Context) error {
160160
if r := recover(); r != nil {
161161
// Generate report in LOTUS_PATH and re-raise panic
162-
build.GeneratePanicReport(c.String("panic-reports"), c.String(FlagMinerRepo), c.App.Name)
162+
build.GenerateMinerPanicReport(c.String("panic-reports"), c.String(FlagMinerRepo), c.App.Name)
163163
panic(r)
164164
}
165165
return nil

cmd/lotus-miner/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var runCmd = &cli.Command{
5757
}
5858

5959
ctx, _ := tag.New(lcli.DaemonContext(cctx),
60-
tag.Insert(metrics.Version, build.BuildVersion),
60+
tag.Insert(metrics.Version, build.MinerBuildVersion),
6161
tag.Insert(metrics.Commit, build.CurrentCommit),
6262
tag.Insert(metrics.NodeType, "miner"),
6363
)

0 commit comments

Comments
 (0)