Skip to content

Commit

Permalink
feat!: build: separate miner and node version strings
Browse files Browse the repository at this point in the history
Ref: #12010
  • Loading branch information
rvagg committed May 23, 2024
1 parent 081efa4 commit 70b1b80
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 42 deletions.
2 changes: 1 addition & 1 deletion api/docgen-openrpc/openrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewLotusOpenRPCDocument(Comments, GroupDocs map[string]string) *go_openrpc_
title := "Lotus RPC API"
info.Title = (*meta_schema.InfoObjectProperties)(&title)

version := build.BuildVersion
version := build.NodeBuildVersion
info.Version = (*meta_schema.InfoObjectVersion)(&version)
return info
},
Expand Down
28 changes: 23 additions & 5 deletions build/panic_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,31 @@ var PanicReportingPath = "panic-reports"
// the lotus journal to be included in the panic report.
var PanicReportJournalTail = defaultJournalTail

// GeneratePanicReport produces a timestamped dump of the application state
// GenerateNodePanicReport produces a timestamped dump of the application state
// for inspection and debugging purposes. Call this function from any place
// where a panic or severe error needs to be examined. `persistPath` is the
// path where the reports should be saved. `repoPath` is the path where the
// journal should be read from. `label` is an optional string to include
// next to the report timestamp.
func GeneratePanicReport(persistPath, repoPath, label string) {
//
// This function should be called for panics originating from the Lotus daemon.
func GenerateNodePanicReport(persistPath, repoPath, label string) {
generatePanicReport(NodeUserVersion(), persistPath, repoPath, label)
}

// GenerateMinerPanicReport produces a timestamped dump of the application state
// for inspection and debugging purposes. Call this function from any place
// where a panic or severe error needs to be examined. `persistPath` is the
// path where the reports should be saved. `repoPath` is the path where the
// journal should be read from. `label` is an optional string to include
// next to the report timestamp.
//
// This function should be called for panics originating from the Lotus miner.
func GenerateMinerPanicReport(persistPath, repoPath, label string) {
generatePanicReport(MinerUserVersion(), persistPath, repoPath, label)
}

func generatePanicReport(buildVersion BuildVersion, persistPath, repoPath, label string) {
// make sure we always dump the latest logs on the way out
// especially since we're probably panicking
defer panicLog.Sync() //nolint:errcheck
Expand Down Expand Up @@ -64,21 +82,21 @@ func GeneratePanicReport(persistPath, repoPath, label string) {
return
}

writeAppVersion(filepath.Join(reportPath, "version"))
writeAppVersion(buildVersion, filepath.Join(reportPath, "version"))
writeStackTrace(filepath.Join(reportPath, "stacktrace.dump"))
writeProfile("goroutines", filepath.Join(reportPath, "goroutines.pprof.gz"))
writeProfile("heap", filepath.Join(reportPath, "heap.pprof.gz"))
writeJournalTail(PanicReportJournalTail, repoPath, filepath.Join(reportPath, "journal.ndjson"))
}

func writeAppVersion(file string) {
func writeAppVersion(buildVersion BuildVersion, file string) {
f, err := os.Create(file)
if err != nil {
panicLog.Error(err.Error())
}
defer f.Close() //nolint:errcheck

versionString := []byte(BuildVersion + BuildTypeString() + CurrentCommit + "\n")
versionString := []byte(string(buildVersion) + BuildTypeString() + CurrentCommit + "\n")
if _, err := f.Write(versionString); err != nil {
panicLog.Error(err.Error())
}
Expand Down
23 changes: 18 additions & 5 deletions build/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package build

import "os"

type BuildVersion string

var CurrentCommit string
var BuildType int

Expand Down Expand Up @@ -36,13 +38,24 @@ func BuildTypeString() string {
}
}

// BuildVersion is the local build version
const BuildVersion = "1.27.1-dev"
// NodeBuildVersion is the local build version of the Lotus daemon
const NodeBuildVersion string = "1.27.1-dev"

func NodeUserVersion() BuildVersion {
if os.Getenv("LOTUS_VERSION_IGNORE_COMMIT") == "1" {
return BuildVersion(NodeBuildVersion)
}

return BuildVersion(NodeBuildVersion + BuildTypeString() + CurrentCommit)
}

// MinerBuildVersion is the local build version of the Lotus miner
const MinerBuildVersion = "1.27.1-dev"

func UserVersion() string {
func MinerUserVersion() BuildVersion {
if os.Getenv("LOTUS_VERSION_IGNORE_COMMIT") == "1" {
return BuildVersion
return BuildVersion(MinerBuildVersion)
}

return BuildVersion + BuildTypeString() + CurrentCommit
return BuildVersion(MinerBuildVersion + BuildTypeString() + CurrentCommit)
}
2 changes: 1 addition & 1 deletion chain/beacon/drand/drand.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub, config dtypes
if err != nil {
return nil, xerrors.Errorf("could not create http drand client: %w", err)
}
hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.BuildVersion)
hc.(DrandHTTPClient).SetUserAgent("drand-client-lotus/" + build.NodeBuildVersion)
clients = append(clients, hc)

}
Expand Down
2 changes: 1 addition & 1 deletion cmd/curio/guidedsetup/guidedsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func oneLastThing(d *MigrationData) {
d.say(notice, "Error getting miner power: %s", err.Error())
os.Exit(1)
}
msgMap["version"] = build.BuildVersion
msgMap["version"] = build.MinerBuildVersion
msgMap["net"] = build.BuildType
msgMap["power"] = map[uploadType]uint64{
uploadTypeIndividual: power.MinerPower.QualityAdjPower.Uint64(),
Expand Down
4 changes: 2 additions & 2 deletions cmd/curio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func main() {
app := &cli.App{
Name: "curio",
Usage: "Filecoin decentralized storage network provider",
Version: build.UserVersion(),
Version: string(build.MinerUserVersion()),
EnableBashCompletion: true,
Before: func(c *cli.Context) error {
setupCloseHandler()
Expand Down Expand Up @@ -154,7 +154,7 @@ func main() {
}

// Generate report in CURIO_PATH and re-raise panic
build.GeneratePanicReport(c.String("panic-reports"), p, c.App.Name)
build.GenerateMinerPanicReport(c.String("panic-reports"), p, c.App.Name)
panic(r)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/curio/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var runCmd = &cli.Command{
}

ctx, _ := tag.New(lcli.DaemonContext(cctx),
tag.Insert(metrics.Version, build.BuildVersion),
tag.Insert(metrics.Version, build.MinerBuildVersion),
tag.Insert(metrics.Commit, build.CurrentCommit),
tag.Insert(metrics.NodeType, "curio"),
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func main() {
app := &cli.App{
Name: "lotus-bench",
Usage: "Benchmark performance of lotus on your hardware",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
DisableSliceFlagSeparator: true,
Commands: []*cli.Command{
proveCmd,
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-fountain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
app := &cli.App{
Name: "lotus-fountain",
Usage: "Devnet token distribution utility",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
app := &cli.App{
Name: "lotus-gateway",
Usage: "Public API server for lotus",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-health/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
app := &cli.App{
Name: "lotus-health",
Usage: "Tools for monitoring lotus daemon health",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Commands: local,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-miner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func main() {
app := &cli.App{
Name: "lotus-miner",
Usage: "Filecoin decentralized storage network miner",
Version: build.UserVersion(),
Version: string(build.MinerUserVersion()),
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -159,7 +159,7 @@ func main() {
After: func(c *cli.Context) error {
if r := recover(); r != nil {
// Generate report in LOTUS_PATH and re-raise panic
build.GeneratePanicReport(c.String("panic-reports"), c.String(FlagMinerRepo), c.App.Name)
build.GenerateMinerPanicReport(c.String("panic-reports"), c.String(FlagMinerRepo), c.App.Name)
panic(r)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-miner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var runCmd = &cli.Command{
}

ctx, _ := tag.New(lcli.DaemonContext(cctx),
tag.Insert(metrics.Version, build.BuildVersion),
tag.Insert(metrics.Version, build.MinerBuildVersion),
tag.Insert(metrics.Commit, build.CurrentCommit),
tag.Insert(metrics.NodeType, "miner"),
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-pcr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
A single message will be produced per miner totaling their refund for all PreCommitSector messages
in a tipset.
`,
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "lotus-path",
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-seed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
app := &cli.App{
Name: "lotus-seed",
Usage: "Seal sectors for genesis miner",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "sector-dir",
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-shed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func main() {
app := &cli.App{
Name: "lotus-shed",
Usage: "A place for all the lotus tools",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Commands: local,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-stats/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
app := &cli.App{
Name: "lotus-stats",
Usage: "Collect basic information about a filecoin network using lotus",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "lotus-path",
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-wallet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
app := &cli.App{
Name: "lotus-wallet",
Usage: "Basic external wallet",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
Description: `
lotus-wallet provides a remote wallet service for lotus.
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
app := &cli.App{
Name: "lotus-worker",
Usage: "Remote miner worker",
Version: build.UserVersion(),
Version: string(build.MinerUserVersion()),
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -104,7 +104,7 @@ func main() {
After: func(c *cli.Context) error {
if r := recover(); r != nil {
// Generate report in LOTUS_PANIC_REPORT_PATH and re-raise panic
build.GeneratePanicReport(c.String("panic-reports"), c.String(FlagWorkerRepo), c.App.Name)
build.GenerateMinerPanicReport(c.String("panic-reports"), c.String(FlagWorkerRepo), c.App.Name)
panic(r)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ var DaemonCmd = &cli.Command{
}

ctx, _ := tag.New(context.Background(),
tag.Insert(metrics.Version, build.BuildVersion),
tag.Insert(metrics.Version, build.NodeBuildVersion),
tag.Insert(metrics.Commit, build.CurrentCommit),
tag.Insert(metrics.NodeType, "chain"),
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func main() {
app := &cli.App{
Name: "lotus",
Usage: "Filecoin decentralized storage network client",
Version: build.UserVersion(),
Version: string(build.NodeUserVersion()),
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -107,7 +107,7 @@ func main() {
After: func(c *cli.Context) error {
if r := recover(); r != nil {
// Generate report in LOTUS_PATH and re-raise panic
build.GeneratePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name)
build.GenerateNodePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name)
panic(r)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/sptool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
app := &cli.App{
Name: "sptool",
Usage: "Manage Filecoin Miner Actor",
Version: build.UserVersion(),
Version: string(build.MinerUserVersion()),
Commands: local,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion itests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (ts *apiSuite) testVersion(t *testing.T) {

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

func (ts *apiSuite) testID(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,13 @@ func Base() Option {
}

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

return Options(
func(s *Settings) error { s.Config = true; return nil },
Override(new(build.BuildVersion), buildVersion),
Override(new(dtypes.APIEndpoint), func() (dtypes.APIEndpoint, error) {
return multiaddr.NewMultiaddr(cfg.API.ListenAddress)
}),
Expand Down
3 changes: 2 additions & 1 deletion node/builder_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/filecoin-project/go-fil-markets/storagemarket"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain"
"github.com/filecoin-project/lotus/chain/beacon"
"github.com/filecoin-project/lotus/chain/consensus"
Expand Down Expand Up @@ -184,7 +185,7 @@ func ConfigFullNode(c interface{}) Option {
enableLibp2pNode := true // always enable libp2p for full nodes

return Options(
ConfigCommon(&cfg.Common, enableLibp2pNode),
ConfigCommon(&cfg.Common, build.NodeUserVersion(), enableLibp2pNode),

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

Expand Down
2 changes: 1 addition & 1 deletion node/builder_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func ConfigStorageMiner(c interface{}) Option {
Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig),
Override(new(dtypes.BootstrapPeers), modules.BuiltinBootstrap),
Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap),
ConfigCommon(&cfg.Common, enableLibp2pNode),
ConfigCommon(&cfg.Common, build.NodeUserVersion(), enableLibp2pNode),

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

Expand Down
4 changes: 3 additions & 1 deletion node/impl/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var session = uuid.New()
type CommonAPI struct {
fx.In

BuildVersion build.BuildVersion

Alerting *alerting.Alerting
APISecret *dtypes.APIAlg
ShutdownChan dtypes.ShutdownChan
Expand Down Expand Up @@ -63,7 +65,7 @@ func (a *CommonAPI) Version(context.Context) (api.APIVersion, error) {
}

return api.APIVersion{
Version: build.UserVersion(),
Version: string(a.BuildVersion),
APIVersion: v,

BlockDelay: build.BlockDelaySecs,
Expand Down
2 changes: 1 addition & 1 deletion node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ func (a *EthModule) EthSendRawTransaction(ctx context.Context, rawTx ethtypes.Et
}

func (a *EthModule) Web3ClientVersion(ctx context.Context) (string, error) {
return build.UserVersion(), nil
return string(build.NodeUserVersion()), nil
}

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

0 comments on commit 70b1b80

Please sign in to comment.