Skip to content

Commit f3a8d40

Browse files
authored
Merge pull request #3813 from oasisprotocol/ptrus/backport/20.12.x-upgrader-fix
[20.12.x] go/upgrade: fix node restarting before reaching the upgrade epoch
2 parents 3002c57 + d23571e commit f3a8d40

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

.changelog/3813.bugfix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
go/upgrade: fix node querying upgrade handler too soon
2+
3+
Fixes node querying the upgrade handler too soon when restarted while the
4+
upgrade epoch was not yet reached.

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/oasis-test-runner/scenario/e2e/upgrade.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ func (sc *nodeUpgradeImpl) Run(childEnv *env.Env) error { // nolint: gocyclo
215215
return fmt.Errorf("error submitting descriptor with nonexistent handler to node: %w", err)
216216
}
217217

218+
// Restart the validator node. Should restart normally as upgrade epoch was not reached yet.
219+
if err = sc.restart(true); err != nil {
220+
return err
221+
}
222+
218223
if err = sc.nextEpoch(); err != nil {
219224
return err
220225
}

go/upgrade/upgrade.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (u *upgradeManager) CancelUpgrade(ctx context.Context) error {
103103
return nil
104104
}
105105

106-
func (u *upgradeManager) checkStatus() error {
106+
func (u *upgradeManager) checkStatus(dataDir string) error {
107107
var err error
108108

109109
if err = u.store.GetCBOR(metadataStoreKey, &u.pending); err != nil {
@@ -123,10 +123,6 @@ func (u *upgradeManager) checkStatus() error {
123123

124124
// By this point, the descriptor is valid and still pending.
125125
if u.pending.UpgradeHeight == api.InvalidUpgradeHeight {
126-
// Only allow the old binary to run before the upgrade epoch.
127-
if u.pending.SubmittingVersion != thisVersion {
128-
return api.ErrNewTooSoon
129-
}
130126
return nil
131127
}
132128

@@ -145,7 +141,11 @@ func (u *upgradeManager) checkStatus() error {
145141
return api.ErrUpgradePending
146142
}
147143

148-
// In case the previous startup was e.g. interruptd during the second part of the
144+
// We are running the correct version, setup handler.
145+
u.ctx = migrations.NewContext(u.pending, dataDir)
146+
u.handler = migrations.GetHandler(u.ctx)
147+
148+
// In case the previous startup was e.g. interrupted during the second part of the
149149
// upgrade, we need to make sure that we're the same version as the previous run.
150150
if u.pending.RunningVersion != "" && u.pending.RunningVersion != thisVersion {
151151
return api.ErrInvalidResumingVersion
@@ -274,14 +274,9 @@ func New(store *persistent.CommonStore, dataDir string) (api.Backend, error) {
274274
logger: logging.GetLogger(api.ModuleName),
275275
}
276276

277-
if err := upgrader.checkStatus(); err != nil {
277+
if err := upgrader.checkStatus(dataDir); err != nil {
278278
return nil, err
279279
}
280280

281-
if upgrader.pending != nil {
282-
upgrader.ctx = migrations.NewContext(upgrader.pending, dataDir)
283-
upgrader.handler = migrations.GetHandler(upgrader.ctx)
284-
}
285-
286281
return upgrader, nil
287282
}

0 commit comments

Comments
 (0)