-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: connect app version with consensus params in end block #16244
Merged
Merged
Changes from 25 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
00cee72
feat!: connect app version with consensus params in end block
cmwaters bfec2f8
add migration and bump to version 3
cmwaters 6dedbc0
fix some of the broken tests
cmwaters e7f45a0
update changelog
cmwaters 3df29df
Merge branch 'main' into cal/app-version
cmwaters b0bdf3b
fix info call
cmwaters f46d3c2
Merge branch 'cal/app-version' of https://github.com/cmwaters/cosmos-…
cmwaters 31c5d9b
Merge branch 'main' into cal/app-version
cmwaters d2f714d
fix imports
cmwaters bd9c4f6
Merge branch 'main' into cal/app-version
cmwaters eb97ef5
incorporate suggestions
cmwaters a7a90ea
add a comment for applying upgrades
cmwaters 0142d23
add nil check
cmwaters 05aa9e2
lint
cmwaters a7f2e8d
Merge branch 'main' into cal/app-version
cmwaters b73d6da
fix test
cmwaters 6acb09f
Merge branch 'cal/app-version' of https://github.com/cmwaters/cosmos-…
cmwaters 41ae153
Merge branch 'main' into cal/app-version
cmwaters a01073e
fix e2e test
cmwaters 470ab70
Merge branch 'cal/app-version' of https://github.com/cmwaters/cosmos-…
cmwaters 01cf826
Merge branch 'main' into cal/app-version
cmwaters 2337db9
use errors instead of panics
cmwaters 209cd3d
Merge branch 'cal/app-version' of https://github.com/cmwaters/cosmos-…
cmwaters af8e556
Merge branch 'main' into cal/app-version
cmwaters a2d9880
Merge branch 'main' into cal/app-version
cmwaters e123895
Merge remote-tracking branch 'upstream/main' into cal/app-version
cmwaters 1991f40
lint
cmwaters 37b73a5
Update baseapp/baseapp.go
tac0turtle f12fb7c
Update baseapp/options.go
tac0turtle 8075b5f
Merge branch 'main' into cal/app-version
tac0turtle dbe58bb
lint-fix, go mod replace
tac0turtle d523bb9
fix upgrade tests
tac0turtle 29f38cb
Merge branch 'main' into cal/app-version
tac0turtle 60f3164
fix lint
tac0turtle 61f3fc0
lint
tac0turtle 0ea7c57
Merge branch 'main' into cal/app-version
tac0turtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package exported | ||
|
||
// ProtocolVersionSetter defines the interface fulfilled by BaseApp | ||
// which allows setting it's appVersion field. | ||
type ProtocolVersionSetter interface { | ||
SetProtocolVersion(uint64) | ||
} | ||
import ( | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
) | ||
|
||
// AppVersionModifier defines the interface fulfilled by BaseApp | ||
// which allows getting and setting it's appVersion field. This | ||
// in turn updates the consensus params that are sent to the | ||
// consensus engine in EndBlock | ||
type AppVersionModifier baseapp.AppVersionModifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ type Keeper struct { | |
storeService corestore.KVStoreService // key to access x/upgrade store | ||
cdc codec.BinaryCodec // App-wide binary codec | ||
upgradeHandlers map[string]types.UpgradeHandler // map of plan name to upgrade handler | ||
versionSetter xp.ProtocolVersionSetter // implements setting the protocol version field on BaseApp | ||
versionModifier xp.AppVersionModifier // implements setting the protocol version field on BaseApp | ||
downgradeVerified bool // tells if we've already sanity checked that this binary version isn't being used against an old state. | ||
authority string // the address capable of executing and canceling an upgrade. Usually the gov module account | ||
initVersionMap module.VersionMap // the module version map at init genesis | ||
|
@@ -53,14 +53,14 @@ type Keeper struct { | |
// cdc - the app-wide binary codec | ||
// homePath - root directory of the application's config | ||
// vs - the interface implemented by baseapp which allows setting baseapp's protocol version field | ||
func NewKeeper(skipUpgradeHeights map[int64]bool, storeService corestore.KVStoreService, cdc codec.BinaryCodec, homePath string, vs xp.ProtocolVersionSetter, authority string) *Keeper { | ||
func NewKeeper(skipUpgradeHeights map[int64]bool, storeService corestore.KVStoreService, cdc codec.BinaryCodec, homePath string, vs xp.AppVersionModifier, authority string) *Keeper { | ||
k := &Keeper{ | ||
homePath: homePath, | ||
skipUpgradeHeights: skipUpgradeHeights, | ||
storeService: storeService, | ||
cdc: cdc, | ||
upgradeHandlers: map[string]types.UpgradeHandler{}, | ||
versionSetter: vs, | ||
versionModifier: vs, | ||
authority: authority, | ||
} | ||
|
||
|
@@ -71,16 +71,6 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeService corestore.KVStore | |
return k | ||
} | ||
|
||
// SetVersionSetter sets the interface implemented by baseapp which allows setting baseapp's protocol version field | ||
func (k *Keeper) SetVersionSetter(vs xp.ProtocolVersionSetter) { | ||
k.versionSetter = vs | ||
} | ||
|
||
// GetVersionSetter gets the protocol version field of baseapp | ||
func (k *Keeper) GetVersionSetter() xp.ProtocolVersionSetter { | ||
return k.versionSetter | ||
} | ||
|
||
// SetInitVersionMap sets the initial version map. | ||
// This is only used in app wiring and should not be used in any other context. | ||
func (k *Keeper) SetInitVersionMap(vm module.VersionMap) { | ||
|
@@ -100,35 +90,6 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl | |
k.upgradeHandlers[name] = upgradeHandler | ||
} | ||
|
||
// setProtocolVersion sets the protocol version to state | ||
func (k Keeper) setProtocolVersion(ctx context.Context, v uint64) error { | ||
store := k.storeService.OpenKVStore(ctx) | ||
versionBytes := make([]byte, 8) | ||
binary.BigEndian.PutUint64(versionBytes, v) | ||
return store.Set([]byte{types.ProtocolVersionByte}, versionBytes) | ||
} | ||
|
||
// getProtocolVersion gets the protocol version from state | ||
func (k Keeper) getProtocolVersion(ctx context.Context) (uint64, error) { | ||
store := k.storeService.OpenKVStore(ctx) | ||
ok, err := store.Has([]byte{types.ProtocolVersionByte}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
if ok { | ||
pvBytes, err := store.Get([]byte{types.ProtocolVersionByte}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
protocolVersion := binary.BigEndian.Uint64(pvBytes) | ||
return protocolVersion, nil | ||
} | ||
// default value | ||
return 0, nil | ||
} | ||
|
||
// SetModuleVersionMap saves a given version map to state | ||
func (k Keeper) SetModuleVersionMap(ctx context.Context, vm module.VersionMap) error { | ||
if len(vm) > 0 { | ||
|
@@ -445,6 +406,7 @@ func (k Keeper) GetUpgradePlan(ctx context.Context) (plan types.Plan, err error) | |
func (k Keeper) setDone(ctx context.Context, name string) error { | ||
store := k.storeService.OpenKVStore(ctx) | ||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||
fmt.Println("setting done", "height", sdkCtx.HeaderInfo().Height, "name", name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have been using the logger There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can remove in a follow up |
||
return store.Set(encodeDoneKey(name, sdkCtx.HeaderInfo().Height), []byte{1}) | ||
} | ||
|
||
|
@@ -455,6 +417,7 @@ func (k Keeper) HasHandler(name string) bool { | |
} | ||
|
||
// ApplyUpgrade will execute the handler associated with the Plan and mark the plan as done. | ||
// If successful, it will increment the app version and clear the IBC state | ||
func (k Keeper) ApplyUpgrade(ctx context.Context, plan types.Plan) error { | ||
handler := k.upgradeHandlers[plan.Name] | ||
if handler == nil { | ||
|
@@ -476,20 +439,16 @@ func (k Keeper) ApplyUpgrade(ctx context.Context, plan types.Plan) error { | |
return err | ||
} | ||
|
||
// incremement the protocol version and set it in state and baseapp | ||
nextProtocolVersion, err := k.getProtocolVersion(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
nextProtocolVersion++ | ||
err = k.setProtocolVersion(ctx, nextProtocolVersion) | ||
if err != nil { | ||
return err | ||
} | ||
// incremement the app version and set it in state and baseapp | ||
cmwaters marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if k.versionModifier != nil { | ||
currentAppVersion, err := k.versionModifier.AppVersion(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if k.versionSetter != nil { | ||
// set protocol version on BaseApp | ||
k.versionSetter.SetProtocolVersion(nextProtocolVersion) | ||
if err := k.versionModifier.SetAppVersion(ctx, currentAppVersion+1); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get those changelog entries under unreleased?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gentle ping @cmwaters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I left this PR. Have tried to update it and move the changelog entries under unreleased