-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add a signalling mechanism for coordinated upgrades (#2832)
As per ADR-018, this PR extends the existing minimal upgrade module with a signalling mechanism. Validators are expected to submit an on-chain message to signal that they wish to change version of the network. When a quorum has signalled the next version the upgrade module signals to the app that it is ready to switch to the next state machine. If the app version is not supported the node will panic. Note that this feature does not currently support downgrading. The only permissible app version change is the very next increment. To cancel the upgrade, the same validators need only to submit an on-chain message with the current version they are on. Co-authored-by: Evan Forbes <42654277+evan-forbes@users.noreply.github.com> Co-authored-by: Rootul P <rootulp@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
54e8936
commit c1754b0
Showing
19 changed files
with
2,299 additions
and
449 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
syntax = "proto3"; | ||
package celestia.upgrade.v1; | ||
|
||
import "google/api/annotations.proto"; | ||
|
||
option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; | ||
|
||
// Query defines the upgrade Query service. | ||
service Query { | ||
// VersionTally allows the querying of the tally of voting power by all | ||
// validators that have signalled for each version | ||
rpc VersionTally(QueryVersionTallyRequest) | ||
returns (QueryVersionTallyResponse) { | ||
option (google.api.http).get = "/upgrade/v1/tally/{version}"; | ||
} | ||
} | ||
|
||
// QueryVersionTallyRequest is the request type for the UpgradeStatus RPC | ||
// method. | ||
message QueryVersionTallyRequest { uint64 version = 1; } | ||
|
||
// QueryVersionTallyResponse is the response type for the UpgradeStatus RPC | ||
// method. | ||
message QueryVersionTallyResponse { | ||
uint64 voting_power = 1; | ||
uint64 threshold_power = 2; | ||
uint64 total_voting_power = 3; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
syntax = "proto3"; | ||
package celestia.upgrade.v1; | ||
|
||
import "google/api/annotations.proto"; | ||
|
||
option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; | ||
|
||
// Msg defines the upgrade Msg service. | ||
service Msg { | ||
// SignalVersion allows the validator to signal for an upgrade | ||
rpc SignalVersion(MsgSignalVersion) returns (MsgSignalVersionResponse) { | ||
option (google.api.http).post = "/upgrade/v1/signal"; | ||
} | ||
} | ||
|
||
// MsgSignalVersion signals for an upgrade | ||
message MsgSignalVersion { | ||
string validator_address = 1; | ||
uint64 version = 2; | ||
} | ||
|
||
// MsgSignalVersionResponse describes the response returned after the submission | ||
// of a SignalVersion | ||
message MsgSignalVersionResponse {} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package upgrade | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
ibctypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" | ||
) | ||
|
||
// We need compatibility with the way that IBC uses the upgrade module. This file | ||
// ensures that we comply to the interface that IBC expects | ||
var _ ibctypes.UpgradeKeeper = (*Keeper)(nil) | ||
|
||
// ScheduleUpgrade implements the ibc upgrade keeper interface. This is a noop as | ||
// no other process is allowed to schedule an upgrade but the upgrade keeper itself. | ||
// This is kept around to support the interface. | ||
func (k Keeper) ScheduleUpgrade(_ sdk.Context, _ types.Plan) error { | ||
return nil | ||
} | ||
|
||
// GetUpgradePlan implements the ibc upgrade keeper interface. This is used in BeginBlock | ||
// to know when to write the upgraded consensus state. The IBC module needs to sign over | ||
// the next consensus state to ensure a smooth transition for counterparty chains. This | ||
// is implemented as a noop. Any IBC breaking change would be invoked by this upgrade module | ||
// in end blocker. | ||
func (k Keeper) GetUpgradePlan(_ sdk.Context) (plan types.Plan, havePlan bool) { | ||
return types.Plan{}, false | ||
} | ||
|
||
// SetUpgradedClient sets the expected upgraded client for the next version of this chain at the last height the current chain will commit. | ||
func (k Keeper) SetUpgradedClient(ctx sdk.Context, planHeight int64, bz []byte) error { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Set(types.UpgradedClientKey(planHeight), bz) | ||
return nil | ||
} | ||
|
||
// GetUpgradedClient gets the expected upgraded client for the next version of this chain | ||
func (k Keeper) GetUpgradedClient(ctx sdk.Context, height int64) ([]byte, bool) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.UpgradedClientKey(height)) | ||
if len(bz) == 0 { | ||
return nil, false | ||
} | ||
|
||
return bz, true | ||
} | ||
|
||
// SetUpgradedConsensusState set the expected upgraded consensus state for the next version of this chain | ||
// using the last height committed on this chain. | ||
func (k Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz []byte) error { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Set(types.UpgradedConsStateKey(planHeight), bz) | ||
return nil | ||
} | ||
|
||
// GetUpgradedConsensusState get the expected upgraded consensus state for the next version of this chain | ||
func (k Keeper) GetUpgradedConsensusState(ctx sdk.Context, lastHeight int64) ([]byte, bool) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.UpgradedConsStateKey(lastHeight)) | ||
if len(bz) == 0 { | ||
return nil, false | ||
} | ||
|
||
return bz, true | ||
} | ||
|
||
// ClearIBCState clears any planned IBC state | ||
func (k Keeper) ClearIBCState(ctx sdk.Context, lastHeight int64) { | ||
// delete IBC client and consensus state from store if this is IBC plan | ||
store := ctx.KVStore(k.storeKey) | ||
store.Delete(types.UpgradedClientKey(lastHeight)) | ||
store.Delete(types.UpgradedConsStateKey(lastHeight)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package upgrade | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
type StakingKeeper interface { | ||
GetLastValidatorPower(ctx sdk.Context, addr sdk.ValAddress) int64 | ||
GetLastTotalPower(ctx sdk.Context) math.Int | ||
GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) | ||
} |
Oops, something went wrong.