|
4 | 4 | "context"
|
5 | 5 | "encoding/binary"
|
6 | 6 | "encoding/json"
|
7 |
| - "errors" |
8 | 7 | "fmt"
|
| 8 | + "io/ioutil" |
9 | 9 | "os"
|
10 | 10 | "path/filepath"
|
11 | 11 | "sort"
|
@@ -33,12 +33,8 @@ type Keeper struct {
|
33 | 33 | skipUpgradeHeights map[int64]bool // map of heights to skip for an upgrade
|
34 | 34 | cdc codec.BinaryCodec // App-wide binary codec
|
35 | 35 | upgradeHandlers map[string]types.UpgradeHandler // map of plan name to upgrade handler
|
36 |
| - versionModifier server.VersionModifier // implements setting the protocol version field on BaseApp |
| 36 | + versionSetter xp.ProtocolVersionSetter // implements setting the protocol version field on BaseApp |
37 | 37 | downgradeVerified bool // tells if we've already sanity checked that this binary version isn't being used against an old state.
|
38 |
| - authority string // the address capable of executing and canceling an upgrade. Usually the gov module account |
39 |
| - initVersionMap appmodule.VersionMap // the module version map at init genesis |
40 |
| - |
41 |
| - consensusKeeper types.ConsensusKeeper |
42 | 38 | }
|
43 | 39 |
|
44 | 40 | // NewKeeper constructs an upgrade Keeper which requires the following arguments:
|
@@ -324,6 +320,26 @@ func encodeDoneKey(name string, height int64) []byte {
|
324 | 320 | return key
|
325 | 321 | }
|
326 | 322 |
|
| 323 | +// GetLastCompletedUpgrade returns the last applied upgrade name and height. |
| 324 | +func (k Keeper) GetLastCompletedUpgrade(ctx sdk.Context) (string, int64) { |
| 325 | + iter := sdk.KVStoreReversePrefixIterator(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) |
| 326 | + defer iter.Close() |
| 327 | + if iter.Valid() { |
| 328 | + return parseDoneKey(iter.Key()), int64(binary.BigEndian.Uint64(iter.Value())) |
| 329 | + } |
| 330 | + |
| 331 | + return "", 0 |
| 332 | +} |
| 333 | + |
| 334 | +// parseDoneKey - split upgrade name from the done key |
| 335 | +func parseDoneKey(key []byte) string { |
| 336 | + if len(key) < 2 { |
| 337 | + panic(fmt.Sprintf("expected key of length at least %d, got %d", 2, len(key))) |
| 338 | + } |
| 339 | + |
| 340 | + return string(key[1:]) |
| 341 | +} |
| 342 | + |
327 | 343 | // GetDoneHeight returns the height at which the given upgrade was executed
|
328 | 344 | func (k Keeper) GetDoneHeight(ctx context.Context, name string) (int64, error) {
|
329 | 345 | store := k.KVStoreService.OpenKVStore(ctx)
|
@@ -555,3 +571,13 @@ type upgradeInfo struct {
|
555 | 571 | // Height has types.Plan.Height value
|
556 | 572 | Info string `json:"info,omitempty"`
|
557 | 573 | }
|
| 574 | + |
| 575 | +// SetDowngradeVerified updates downgradeVerified. |
| 576 | +func (k *Keeper) SetDowngradeVerified(v bool) { |
| 577 | + k.downgradeVerified = v |
| 578 | +} |
| 579 | + |
| 580 | +// DowngradeVerified returns downgradeVerified. |
| 581 | +func (k Keeper) DowngradeVerified() bool { |
| 582 | + return k.downgradeVerified |
| 583 | +} |
0 commit comments