Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Jan 7, 2025
1 parent ae0816e commit bc77fe1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 31 deletions.
38 changes: 19 additions & 19 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ func Start(_ *cobra.Command, _ []string) error {
return errors.Wrap(err, "unable to resolve observer pub key bech32")
}

isObserver, err := isObserverNode(ctx, zetacoreClient)
switch {
case err != nil:
return errors.Wrap(err, "unable to check if observer node")
case !isObserver:
logger.Std.Warn().Msg("This node is not an observer node. Exit 0")
return nil
}

shutdownListener := maintenance.NewShutdownListener(zetacoreClient, logger.Std)
if err := shutdownListener.RunPreStartCheck(ctx); err != nil {
return errors.Wrap(err, "pre start check failed")
}

tssSetupProps := zetatss.SetupProps{
Config: cfg,
Zetacore: zetacoreClient,
Expand All @@ -94,13 +108,11 @@ func Start(_ *cobra.Command, _ []string) error {
Telemetry: telemetry,
}

isObserver, err := isObserverNode(ctx, zetacoreClient)
switch {
case err != nil:
return errors.Wrap(err, "unable to check if observer node")
case !isObserver:
logger.Std.Warn().Msg("This node is not an observer node. Exit 0")
return nil
// This will start p2p communication so it should only happen after
// preflight checks have completed
tss, err := zetatss.Setup(ctx, tssSetupProps, logger.Std)
if err != nil {
return errors.Wrap(err, "unable to setup TSS service")
}

// Starts various background TSS listeners.
Expand All @@ -110,23 +122,11 @@ func Start(_ *cobra.Command, _ []string) error {
graceful.ShutdownNow()
})

shutdownListener := maintenance.NewShutdownListener(zetacoreClient, logger.Std)
err = shutdownListener.RunPreStartCheck(ctx)
if err != nil {
return errors.Wrap(err, "pre start check failed")
}
shutdownListener.Listen(ctx, func() {
logger.Std.Info().Msg("Shutdown listener received an action to shutdown zetaclientd.")
graceful.ShutdownNow()
})

// This will start p2p communication so it should only happen after
// preflight checks have completed
tss, err := zetatss.Setup(ctx, tssSetupProps, logger.Std)
if err != nil {
return errors.Wrap(err, "unable to setup TSS service")
}

// CreateSignerMap: This creates a map of all signers for each chain.
// Each signer is responsible for signing transactions for a particular chain
signerMap, err := orchestrator.CreateSignerMap(ctx, tss, logger)
Expand Down
3 changes: 2 additions & 1 deletion docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58119,7 +58119,8 @@ definitions:
type: string
description: |-
Minimum version of zetaclient that is allowed to run. This must be either
a valid semver string (v23.0.1) or empty.
a valid semver string (v23.0.1) or empty. If empty, all versions are
allowed.
description: Flags for the top-level operation of zetaclient.
observerPendingNonces:
type: object
Expand Down
3 changes: 2 additions & 1 deletion proto/zetachain/zetacore/observer/operational.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ message OperationalFlags {
[ (gogoproto.stdduration) = true ];

// Minimum version of zetaclient that is allowed to run. This must be either
// a valid semver string (v23.0.1) or empty.
// a valid semver string (v23.0.1) or empty. If empty, all versions are
// allowed.
string minimum_version = 3;
}
3 changes: 2 additions & 1 deletion typescript/zetachain/zetacore/observer/operational_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export declare class OperationalFlags extends Message<OperationalFlags> {

/**
* Minimum version of zetaclient that is allowed to run. This must be either
* a valid semver string (v23.0.1) or empty.
* a valid semver string (v23.0.1) or empty. If empty, all versions are
* allowed.
*
* @generated from field: string minimum_version = 3;
*/
Expand Down
3 changes: 2 additions & 1 deletion x/observer/types/operational.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions x/observer/types/operational_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func TestOperationalFlags_Validate(t *testing.T) {
MinimumVersion: "v1.1.1",
},
},
{
name: "minimum version invalid",
of: types.OperationalFlags{
MinimumVersion: "asdf",
},
errContains: types.ErrOperationalFlagsInvalidMinimumVersion.Error(),
},
{
name: "all flags valid",
of: types.OperationalFlags{
Expand Down
10 changes: 4 additions & 6 deletions zetaclient/maintenance/shutdown_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type ShutdownListener struct {
logger zerolog.Logger

lastRestartHeightMissed int64
getVersion func() string
// get the current version of zetaclient
getVersion func() string
}

// NewShutdownListener creates a new ShutdownListener.
Expand All @@ -46,10 +47,7 @@ func (o *ShutdownListener) RunPreStartCheck(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "unable to get initial operational flags")
}
if err := o.checkMinimumVersion(operationalFlags); err != nil {
return err
}
return nil
return o.checkMinimumVersion(operationalFlags)
}

func (o *ShutdownListener) Listen(ctx context.Context, action func()) {
Expand Down Expand Up @@ -100,7 +98,7 @@ func (o *ShutdownListener) getOperationalFlagsWithRetry(ctx context.Context) (ob
// handleNewFlags processes the flags and returns true if a shutdown should be signaled
func (o *ShutdownListener) handleNewFlags(ctx context.Context, f observertypes.OperationalFlags) bool {
if err := o.checkMinimumVersion(f); err != nil {
o.logger.Error().Err(err).Msg("minimum version check")
o.logger.Error().Err(err).Any("operational_flags", f).Msg("minimum version check")
return true
}
if f.RestartHeight < 1 {
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/maintenance/shutdown_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestShutdownListener(t *testing.T) {
client := mocks.NewZetacoreClient(t)

listener := NewShutdownListener(client, logger)
listener.getVersion = func() string {
listener.getNodeVersion = func() string {

Check failure on line 109 in zetaclient/maintenance/shutdown_listener_test.go

View workflow job for this annotation

GitHub Actions / build-and-test

listener.getNodeVersion undefined (type *ShutdownListener has no field or method getNodeVersion)

Check failure on line 109 in zetaclient/maintenance/shutdown_listener_test.go

View workflow job for this annotation

GitHub Actions / build-and-test

listener.getNodeVersion undefined (type *ShutdownListener has no field or method getNodeVersion)
return "1.1.2"
}

Expand Down Expand Up @@ -134,7 +134,7 @@ func TestShutdownListener(t *testing.T) {
client := mocks.NewZetacoreClient(t)

listener := NewShutdownListener(client, logger)
listener.getVersion = func() string {
listener.getNodeVersion = func() string {

Check failure on line 137 in zetaclient/maintenance/shutdown_listener_test.go

View workflow job for this annotation

GitHub Actions / build-and-test

listener.getNodeVersion undefined (type *ShutdownListener has no field or method getNodeVersion)

Check failure on line 137 in zetaclient/maintenance/shutdown_listener_test.go

View workflow job for this annotation

GitHub Actions / build-and-test

listener.getNodeVersion undefined (type *ShutdownListener has no field or method getNodeVersion)
return "1.1.1"
}

Expand Down

0 comments on commit bc77fe1

Please sign in to comment.