Skip to content

Commit

Permalink
Rollback upgrade plan return values semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 committed Nov 8, 2024
1 parent aedfc3f commit 31af676
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
17 changes: 6 additions & 11 deletions pkg/rpc/clients_cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ import (
"github.com/zeta-chain/node/cmd/zetacored/config"
)

// GetUpgradePlan returns the current upgrade plan.
// Returns empty plan if no upgrade is planned
func (c *Clients) GetUpgradePlan(ctx context.Context) (upgradetypes.Plan, error) {
// GetUpgradePlan returns the current upgrade plan or nil if there is no plan.
func (c *Clients) GetUpgradePlan(ctx context.Context) (*upgradetypes.Plan, error) {
in := &upgradetypes.QueryCurrentPlanRequest{}

resp, err := c.Upgrade.CurrentPlan(ctx, in)
switch {
case err != nil:
return upgradetypes.Plan{}, errors.Wrap(err, "failed to get current upgrade plan")
case resp.Plan == nil:
// no upgrade planned
return upgradetypes.Plan{}, nil
default:
return *resp.Plan, nil
if err != nil {
return nil, errors.Wrap(err, "failed to get current upgrade plan")
}

return resp.Plan, nil
}

// GetZetaTokenSupplyOnNode returns the zeta token supply on the node
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type ZetacoreClient interface {
GetZetaHotKeyBalance(ctx context.Context) (sdkmath.Int, error)
GetInboundTrackersForChain(ctx context.Context, chainID int64) ([]crosschaintypes.InboundTracker, error)

GetUpgradePlan(ctx context.Context) (upgradetypes.Plan, error)
GetUpgradePlan(ctx context.Context) (*upgradetypes.Plan, error)

PostOutboundTracker(ctx context.Context, chainID int64, nonce uint64, txHash string) (string, error)
}
Expand Down
21 changes: 11 additions & 10 deletions zetaclient/orchestrator/contextupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type Zetacore interface {
GetBlockHeight(ctx context.Context) (int64, error)
GetUpgradePlan(ctx context.Context) (upgradetypes.Plan, error)
GetUpgradePlan(ctx context.Context) (*upgradetypes.Plan, error)
GetSupportedChains(ctx context.Context) ([]chains.Chain, error)
GetAdditionalChains(ctx context.Context) ([]chains.Chain, error)
GetCrosschainFlags(ctx context.Context) (observertypes.CrosschainFlags, error)
Expand Down Expand Up @@ -138,22 +138,23 @@ func UpdateAppContext(ctx context.Context, app *zctx.AppContext, zc Zetacore, lo
// returns an error if an upgrade is required
func checkForZetacoreUpgrade(ctx context.Context, zetaHeight int64, zc Zetacore) error {
plan, err := zc.GetUpgradePlan(ctx)
if err != nil {
switch {
case err != nil:
return errors.Wrap(err, "unable to get upgrade plan")

Check warning on line 143 in zetaclient/orchestrator/contextupdater.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/orchestrator/contextupdater.go#L142-L143

Added lines #L142 - L143 were not covered by tests
}

// no upgrade planned
if plan.Height == 0 {
case plan == nil:
// no upgrade planned
return nil
}

// We can return an error in couple of blocks ahead.
// It's okay because ticker might have a long interval
upgradeHeight := plan.Height

// We can return an error in a few blocks ahead.
// It's okay because the ticker might have a long interval.
const upgradeRange = 2

// Note that after plan.Height's block `x/upgrade` module deletes the plan
if (plan.Height - zetaHeight) <= upgradeRange {
return errors.Wrapf(ErrUpgradeRequired, "current height: %d, upgrade height: %d", zetaHeight, plan.Height)
if (upgradeHeight - zetaHeight) <= upgradeRange {
return errors.Wrapf(ErrUpgradeRequired, "current height: %d, upgrade height: %d", zetaHeight, upgradeHeight)
}

return nil

Check warning on line 160 in zetaclient/orchestrator/contextupdater.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/orchestrator/contextupdater.go#L160

Added line #L160 was not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/orchestrator/contextupdater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_UpdateAppContext(t *testing.T) {
}

zetacore.On("GetBlockHeight", mock.Anything).Return(int64(123), nil)
zetacore.On("GetUpgradePlan", mock.Anything).Return(upgradetypes.Plan{}, nil)
zetacore.On("GetUpgradePlan", mock.Anything).Return(nil, nil)
zetacore.On("GetSupportedChains", mock.Anything).Return(newChains, nil)
zetacore.On("GetAdditionalChains", mock.Anything).Return(nil, nil)
zetacore.On("GetChainParams", mock.Anything).Return(newParams, nil)
Expand Down Expand Up @@ -68,7 +68,7 @@ func Test_UpdateAppContext(t *testing.T) {
)

zetacore.On("GetBlockHeight", mock.Anything).Return(int64(123), nil)
zetacore.On("GetUpgradePlan", mock.Anything).Return(upgradetypes.Plan{
zetacore.On("GetUpgradePlan", mock.Anything).Return(&upgradetypes.Plan{
Name: "hello",
Height: 124,
}, nil)
Expand Down
12 changes: 7 additions & 5 deletions zetaclient/testutils/mocks/zetacore_client.go

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

0 comments on commit 31af676

Please sign in to comment.