Skip to content

Commit

Permalink
make the node fail to start on invalid version
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Jul 28, 2023
1 parent e0527bc commit 9d1c066
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 36 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
env:
GO_VERSION: "1.20"

concurrency:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

Expand Down Expand Up @@ -203,6 +203,9 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
# all tags are needed for integration tests
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion cmd/bootstrap/transit/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (

// commit and semver vars
commit = build.Commit()
semver = build.Semver()
semver = build.Version()
)

// readNodeID reads the NodeID file
Expand Down
21 changes: 12 additions & 9 deletions cmd/build/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package build

import (
"fmt"
"strings"

smv "github.com/coreos/go-semver/semver"
Expand All @@ -21,8 +22,8 @@ var (
commit string
)

// Semver returns the semantic version of this build.
func Semver() string {
// Version returns the raw version string of this build.
func Version() string {
return semver
}

Expand All @@ -48,24 +49,26 @@ func init() {
}
}

// SemverV2 returns the semantic version of this build as a semver.Version
// if it is defined, or nil otherwise.
var UndefinedVersionError = fmt.Errorf("version is undefined")

// Semver returns the semantic version of this build as a semver.Version
// if it is defined, or UndefinedVersionError otherwise.
// The version string is converted to a semver compliant one if it isn't already
// but this might fail if the version string is still not semver compliant. In that
// case, an error is returned.
func SemverV2() (*smv.Version, error) {
func Semver() (*smv.Version, error) {
if !IsDefined(semver) {
return nil, nil
return nil, UndefinedVersionError
}
ver, err := smv.NewVersion(makeSemverV2Compliant(semver))
ver, err := smv.NewVersion(makeSemverCompliant(semver))
return ver, err
}

// makeSemverV2Compliant converts a non-semver version string to a semver compliant one.
// makeSemverCompliant converts a non-semver version string to a semver compliant one.
// This removes the leading 'v'.
// In the past we sometimes omitted the patch version, e.g. v1.0.0 became v1.0 so this
// also adds a 0 patch version if there's no patch version.
func makeSemverV2Compliant(version string) string {
func makeSemverCompliant(version string) string {
if !IsDefined(version) {
return version
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/build/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestMakeSemverV2Compliant(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
output := makeSemverV2Compliant(tc.input)
output := makeSemverCompliant(tc.input)
if output != tc.expected {
t.Errorf("Got %s; expected %s", output, tc.expected)
}
Expand Down
17 changes: 10 additions & 7 deletions cmd/execution_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,18 @@ func (exeNode *ExecutionNode) LoadStopControl(
module.ReadyDoneAware,
error,
) {
ver, err := build.SemverV2()
ver, err := build.Semver()
if err != nil {
ver = nil
// TODO: In the future we want to error here, but for now we just log a warning.
// This is because we currently have no strong guarantee that then node version
// tag is semver compliant.
exeNode.builder.Logger.Warn().
err = fmt.Errorf("could not set semver version for stop control. "+
"version %s is not semver compliant: %w", build.Version(), err)

// The node would not know its own version. Without this the node would not know
// how to reach to version boundaries.
exeNode.builder.Logger.
Err(err).
Msg("could not set semver version for stop control")
Msg("error starting stop control")

return nil, err
}

latestFinalizedBlock, err := node.State.Final().Head()
Expand Down
8 changes: 4 additions & 4 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (fnb *FlowNodeBuilder) EnqueuePingService() {
// setup the Ping provider to return the software version and the sealed block height
pingInfoProvider := &ping.InfoProvider{
SoftwareVersionFun: func() string {
return build.Semver()
return build.Version()
},
SealedBlockHeightFun: func() (uint64, error) {
head, err := node.State.Sealed().Head()
Expand Down Expand Up @@ -610,7 +610,7 @@ func (fnb *FlowNodeBuilder) ValidateFlags(f func() error) NodeBuilder {
}

func (fnb *FlowNodeBuilder) PrintBuildVersionDetails() {
fnb.Logger.Info().Str("version", build.Semver()).Str("commit", build.Commit()).Msg("build details")
fnb.Logger.Info().Str("version", build.Version()).Str("commit", build.Commit()).Msg("build details")
}

func (fnb *FlowNodeBuilder) initNodeInfo() error {
Expand Down Expand Up @@ -733,7 +733,7 @@ func (fnb *FlowNodeBuilder) initMetrics() error {
if err != nil {
return fmt.Errorf("could not query root snapshoot protocol version: %w", err)
}
nodeInfoMetrics.NodeInfo(build.Semver(), build.Commit(), nodeConfig.SporkID.String(), protocolVersion)
nodeInfoMetrics.NodeInfo(build.Version(), build.Commit(), nodeConfig.SporkID.String(), protocolVersion)
return nil
})
}
Expand Down Expand Up @@ -761,7 +761,7 @@ func (fnb *FlowNodeBuilder) createGCEProfileUploader(client *gcemd.Client, opts
ProjectID: projectID,
ChainID: chainID,
Role: fnb.NodeConfig.NodeRole,
Version: build.Semver(),
Version: build.Version(),
Commit: build.Commit(),
Instance: instance,
}
Expand Down
6 changes: 0 additions & 6 deletions cmd/util/cmd/execution-state-extract/export_report.json

This file was deleted.

2 changes: 1 addition & 1 deletion engine/access/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ func (suite *Suite) TestAPICallNodeVersionInfo() {

respNodeVersionInfo := resp.Info
suite.Require().Equal(respNodeVersionInfo, &entitiesproto.NodeVersionInfo{
Semver: build.Semver(),
Semver: build.Version(),
Commit: build.Commit(),
SporkId: sporkId[:],
ProtocolVersion: uint64(protocolVersion),
Expand Down
2 changes: 1 addition & 1 deletion engine/access/rest/routes/node_version_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestGetNodeVersionInfo(t *testing.T) {
req := getNodeVersionInfoRequest(t)

params := &access.NodeVersionInfo{
Semver: build.Semver(),
Semver: build.Version(),
Commit: build.Commit(),
SporkId: unittest.IdentifierFixture(),
ProtocolVersion: unittest.Uint64InRange(10, 30),
Expand Down
2 changes: 1 addition & 1 deletion engine/access/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (b *Backend) GetNodeVersionInfo(ctx context.Context) (*access.NodeVersionIn
}

return &access.NodeVersionInfo{
Semver: build.Semver(),
Semver: build.Version(),
Commit: build.Commit(),
SporkId: sporkId,
ProtocolVersion: uint64(protocolVersion),
Expand Down
2 changes: 1 addition & 1 deletion engine/access/rpc/backend/backend_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (b *backendNetwork) GetNodeVersionInfo(ctx context.Context) (*access.NodeVe
}

return &access.NodeVersionInfo{
Semver: build.Semver(),
Semver: build.Version(),
Commit: build.Commit(),
SporkId: sporkId,
ProtocolVersion: uint64(protocolVersion),
Expand Down
6 changes: 4 additions & 2 deletions engine/testutil/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/coreos/go-semver/semver"
"github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
blockstore "github.com/ipfs/go-ipfs-blockstore"
Expand Down Expand Up @@ -687,8 +688,9 @@ func ExecutionNode(t *testing.T, hub *stub.Hub, identity *flow.Identity, identit
// disabled by default
uploader := uploader.NewManager(node.Tracer)

ver, err := build.SemverV2()
require.NoError(t, err, "failed to parse semver version from build info")
_, err = build.Semver()
require.ErrorIs(t, err, build.UndefinedVersionError)
ver := semver.New("0.0.0")

latestFinalizedBlock, err := node.State.Final().Head()
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion integration/localnet/builder/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func defaultService(name, role, dataDir, profilerDir string, i int) Service {
Dockerfile: "cmd/Dockerfile",
Args: map[string]string{
"TARGET": fmt.Sprintf("./cmd/%s", role),
"VERSION": build.Semver(),
"VERSION": build.Version(),
"COMMIT": build.Commit(),
"GOARCH": runtime.GOARCH,
},
Expand Down

0 comments on commit 9d1c066

Please sign in to comment.