Skip to content

Commit 67c3a6f

Browse files
committed
feat!: build: separate miner and node version strings
Ref: #12010
1 parent 110da93 commit 67c3a6f

File tree

25 files changed

+72
-37
lines changed

25 files changed

+72
-37
lines changed

api/docgen-openrpc/openrpc.go

+1-1
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

+23-5
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

+18-5
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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
)

cmd/lotus-pcr/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
A single message will be produced per miner totaling their refund for all PreCommitSector messages
7171
in a tipset.
7272
`,
73-
Version: build.UserVersion(),
73+
Version: string(build.NodeUserVersion()),
7474
Flags: []cli.Flag{
7575
&cli.StringFlag{
7676
Name: "lotus-path",

cmd/lotus-seed/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func main() {
3838
app := &cli.App{
3939
Name: "lotus-seed",
4040
Usage: "Seal sectors for genesis miner",
41-
Version: build.UserVersion(),
41+
Version: string(build.NodeUserVersion()),
4242
Flags: []cli.Flag{
4343
&cli.StringFlag{
4444
Name: "sector-dir",

cmd/lotus-shed/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func main() {
9797
app := &cli.App{
9898
Name: "lotus-shed",
9999
Usage: "A place for all the lotus tools",
100-
Version: build.UserVersion(),
100+
Version: string(build.NodeUserVersion()),
101101
Commands: local,
102102
Flags: []cli.Flag{
103103
&cli.StringFlag{

cmd/lotus-stats/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
app := &cli.App{
4343
Name: "lotus-stats",
4444
Usage: "Collect basic information about a filecoin network using lotus",
45-
Version: build.UserVersion(),
45+
Version: string(build.NodeUserVersion()),
4646
Flags: []cli.Flag{
4747
&cli.StringFlag{
4848
Name: "lotus-path",

cmd/lotus-wallet/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func main() {
5252
app := &cli.App{
5353
Name: "lotus-wallet",
5454
Usage: "Basic external wallet",
55-
Version: build.UserVersion(),
55+
Version: string(build.NodeUserVersion()),
5656
Description: `
5757
lotus-wallet provides a remote wallet service for lotus.
5858

cmd/lotus-worker/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
app := &cli.App{
7171
Name: "lotus-worker",
7272
Usage: "Remote miner worker",
73-
Version: build.UserVersion(),
73+
Version: string(build.MinerUserVersion()),
7474
EnableBashCompletion: true,
7575
Flags: []cli.Flag{
7676
&cli.StringFlag{
@@ -104,7 +104,7 @@ func main() {
104104
After: func(c *cli.Context) error {
105105
if r := recover(); r != nil {
106106
// Generate report in LOTUS_PANIC_REPORT_PATH and re-raise panic
107-
build.GeneratePanicReport(c.String("panic-reports"), c.String(FlagWorkerRepo), c.App.Name)
107+
build.GenerateMinerPanicReport(c.String("panic-reports"), c.String(FlagWorkerRepo), c.App.Name)
108108
panic(r)
109109
}
110110
return nil

cmd/lotus/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ var DaemonCmd = &cli.Command{
209209
}
210210

211211
ctx, _ := tag.New(context.Background(),
212-
tag.Insert(metrics.Version, build.BuildVersion),
212+
tag.Insert(metrics.Version, build.NodeBuildVersion),
213213
tag.Insert(metrics.Commit, build.CurrentCommit),
214214
tag.Insert(metrics.NodeType, "chain"),
215215
)

cmd/lotus/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func main() {
7272
app := &cli.App{
7373
Name: "lotus",
7474
Usage: "Filecoin decentralized storage network client",
75-
Version: build.UserVersion(),
75+
Version: string(build.NodeUserVersion()),
7676
EnableBashCompletion: true,
7777
Flags: []cli.Flag{
7878
&cli.StringFlag{
@@ -107,7 +107,7 @@ func main() {
107107
After: func(c *cli.Context) error {
108108
if r := recover(); r != nil {
109109
// Generate report in LOTUS_PATH and re-raise panic
110-
build.GeneratePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name)
110+
build.GenerateNodePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name)
111111
panic(r)
112112
}
113113
return nil

itests/api_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (ts *apiSuite) testVersion(t *testing.T) {
7474

7575
versions := strings.Split(v.Version, "+")
7676
require.NotZero(t, len(versions), "empty version")
77-
require.Equal(t, versions[0], build.BuildVersion)
77+
require.Equal(t, versions[0], build.NodeBuildVersion)
7878
}
7979

8080
func (ts *apiSuite) testID(t *testing.T) {

node/builder.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,13 @@ func Base() Option {
266266
}
267267

268268
// Config sets up constructors based on the provided Config
269-
func ConfigCommon(cfg *config.Common, enableLibp2pNode bool) Option {
269+
func ConfigCommon(cfg *config.Common, buildVersion build.BuildVersion, enableLibp2pNode bool) Option {
270270
// setup logging early
271271
lotuslog.SetLevelsFromConfig(cfg.Logging.SubsystemLevels)
272272

273273
return Options(
274274
func(s *Settings) error { s.Config = true; return nil },
275+
Override(new(build.BuildVersion), buildVersion),
275276
Override(new(dtypes.APIEndpoint), func() (dtypes.APIEndpoint, error) {
276277
return multiaddr.NewMultiaddr(cfg.API.ListenAddress)
277278
}),

node/builder_chain.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/filecoin-project/go-fil-markets/storagemarket"
1313

1414
"github.com/filecoin-project/lotus/api"
15+
"github.com/filecoin-project/lotus/build"
1516
"github.com/filecoin-project/lotus/chain"
1617
"github.com/filecoin-project/lotus/chain/beacon"
1718
"github.com/filecoin-project/lotus/chain/consensus"
@@ -184,7 +185,7 @@ func ConfigFullNode(c interface{}) Option {
184185
enableLibp2pNode := true // always enable libp2p for full nodes
185186

186187
return Options(
187-
ConfigCommon(&cfg.Common, enableLibp2pNode),
188+
ConfigCommon(&cfg.Common, build.NodeUserVersion(), enableLibp2pNode),
188189

189190
Override(new(dtypes.UniversalBlockstore), modules.UniversalBlockstore),
190191

node/builder_miner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func ConfigStorageMiner(c interface{}) Option {
8484
Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig),
8585
Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
8686
Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap),
87-
ConfigCommon(&cfg.Common, enableLibp2pNode),
87+
ConfigCommon(&cfg.Common, build.NodeUserVersion(), enableLibp2pNode),
8888

8989
Override(CheckFDLimit, modules.CheckFdLimit(build.MinerFDLimit)), // recommend at least 100k FD limit to miners
9090

node/impl/common/common.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var session = uuid.New()
2424
type CommonAPI struct {
2525
fx.In
2626

27+
BuildVersion build.BuildVersion
28+
2729
Alerting *alerting.Alerting
2830
APISecret *dtypes.APIAlg
2931
ShutdownChan dtypes.ShutdownChan
@@ -63,7 +65,7 @@ func (a *CommonAPI) Version(context.Context) (api.APIVersion, error) {
6365
}
6466

6567
return api.APIVersion{
66-
Version: build.UserVersion(),
68+
Version: string(a.BuildVersion),
6769
APIVersion: v,
6870

6971
BlockDelay: build.BlockDelaySecs,

node/impl/full/eth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ func (a *EthModule) EthSendRawTransaction(ctx context.Context, rawTx ethtypes.Et
836836
}
837837

838838
func (a *EthModule) Web3ClientVersion(ctx context.Context) (string, error) {
839-
return build.UserVersion(), nil
839+
return string(build.NodeUserVersion()), nil
840840
}
841841

842842
func (a *EthModule) EthTraceBlock(ctx context.Context, blkNum string) ([]*ethtypes.EthTraceBlock, error) {

node/modules/lp2p/host.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func Peerstore() (peerstore.Peerstore, error) {
3838
return pstoremem.NewPeerstore()
3939
}
4040

41-
func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (RawHost, error) {
41+
func Host(mctx helpers.MetricsCtx, buildVersion build.BuildVersion, lc fx.Lifecycle, params P2PHostIn) (RawHost, error) {
4242
pkey := params.Peerstore.PrivKey(params.ID)
4343
if pkey == nil {
4444
return nil, fmt.Errorf("missing private key for node ID: %s", params.ID)
@@ -49,7 +49,7 @@ func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (RawHost,
4949
libp2p.Peerstore(params.Peerstore),
5050
libp2p.NoListenAddrs,
5151
libp2p.Ping(true),
52-
libp2p.UserAgent("lotus-" + build.UserVersion()),
52+
libp2p.UserAgent("lotus-" + string(buildVersion)),
5353
}
5454
for _, o := range params.Opts {
5555
opts = append(opts, o...)

0 commit comments

Comments
 (0)