-
Notifications
You must be signed in to change notification settings - Fork 346
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!: add a signalling mechanism for coordinated upgrades #2832
Changes from 6 commits
65b954c
2477ef4
1c7ad45
f446568
4ac4bdb
93a42f9
f36db3a
4285736
c13fa61
e14038e
a4eb85d
59c3b5d
cfcfa5c
215a562
4aa82ea
ebe2022
4d14422
9e2ebab
eae9549
2856aaf
e36e241
1365421
f4e5489
261ea06
1b4c693
1853460
c81743a
4674c0f
0580b1b
9de3714
823c1ea
3d6160d
6418b64
6156f3e
5184c9a
b9349a1
41f80b1
3ad204d
6274c98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,16 +8,34 @@ import ( | |||||
"github.com/celestiaorg/celestia-app/x/upgrade/types" | ||||||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||||||
) | ||||||
|
||||||
// Keeper implements the MsgServer and QueryServer interfaces | ||||||
var ( | ||||||
_ types.MsgServer = Keeper{} | ||||||
_ types.QueryServer = Keeper{} | ||||||
|
||||||
defaultSignalTheshold = Fraction{Numerator: 5, Denominator: 6} | ||||||
) | ||||||
|
||||||
type Fraction struct { | ||||||
Numerator int64 | ||||||
Denominator int64 | ||||||
} | ||||||
|
||||||
// SignalThreshold is the fraction of voting power that is required | ||||||
// to signal for a version change. It is set to 5/6 as the middle point | ||||||
// between 2/3 and 3/3 providing 1/6 fault tolerance to halting the | ||||||
// network during an upgrade period. It can be modified through a | ||||||
// hard fork change that modified the app version | ||||||
func SignalThreshold(version uint64) Fraction { | ||||||
switch version { | ||||||
default: | ||||||
return defaultSignalTheshold | ||||||
} | ||||||
} | ||||||
|
||||||
type Keeper struct { | ||||||
// we use the same upgrade store key so existing IBC client state can | ||||||
// safely be ported over without any migration | ||||||
|
@@ -35,23 +53,18 @@ type Keeper struct { | |||||
// staking keeper is used to fetch validators to calculate the total power | ||||||
// signalled to a version | ||||||
stakingKeeper StakingKeeper | ||||||
|
||||||
// paramStore provides access to the signal quorum param | ||||||
paramStore paramtypes.Subspace | ||||||
} | ||||||
|
||||||
// NewKeeper constructs an upgrade keeper | ||||||
func NewKeeper( | ||||||
storeKey storetypes.StoreKey, | ||||||
upgradeHeight int64, | ||||||
stakingKeeper StakingKeeper, | ||||||
paramStore paramtypes.Subspace, | ||||||
) Keeper { | ||||||
return Keeper{ | ||||||
storeKey: storeKey, | ||||||
upgradeHeight: upgradeHeight, | ||||||
stakingKeeper: stakingKeeper, | ||||||
paramStore: paramStore, | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -100,18 +113,11 @@ func (k Keeper) VersionTally(ctx context.Context, req *types.QueryVersionTallyRe | |||||
threshold := k.GetVotingPowerThreshold(sdkCtx) | ||||||
return &types.QueryVersionTallyResponse{ | ||||||
VotingPower: currentVotingPower.Uint64(), | ||||||
Threshold: threshold.Uint64(), | ||||||
ThresholdPower: threshold.Uint64(), | ||||||
TotalVotingPower: totalVotingPower.Uint64(), | ||||||
}, nil | ||||||
} | ||||||
|
||||||
// Params is a method required by the QueryServer interface | ||||||
func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { | ||||||
sdkCtx := sdk.UnwrapSDKContext(ctx) | ||||||
params := k.GetParams(sdkCtx) | ||||||
return &types.QueryParamsResponse{Params: ¶ms}, nil | ||||||
} | ||||||
|
||||||
// SetValidatorVersion saves a signalled version for a validator using the keeper's store key | ||||||
func (k Keeper) SetValidatorVersion(ctx sdk.Context, valAddress sdk.ValAddress, version uint64) { | ||||||
store := ctx.KVStore(k.storeKey) | ||||||
|
@@ -169,13 +175,12 @@ func (k Keeper) TallyVotingPower(ctx sdk.Context, threshold int64) (bool, uint64 | |||||
} | ||||||
|
||||||
// GetVotingPowerThreshold returns the voting power threshold required to | ||||||
// upgrade to a new version. It converts the signal quorum parameter which | ||||||
// is a number between 0 and math.MaxUint32 representing a fraction and | ||||||
// then multiplies it by the total voting power | ||||||
// upgrade to a new version. | ||||||
func (k Keeper) GetVotingPowerThreshold(ctx sdk.Context) sdkmath.Int { | ||||||
quorum := k.SignalQuorum(ctx) | ||||||
// contract: totalVotingPower should not exceed MaxUit64 | ||||||
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. [typo]
Suggested change
|
||||||
totalVotingPower := k.stakingKeeper.GetLastTotalPower(ctx) | ||||||
return quorum.MulInt(totalVotingPower).RoundInt() | ||||||
thresholdFraction := SignalThreshold(ctx.BlockHeader().Version.App) | ||||||
return totalVotingPower.MulRaw(thresholdFraction.Numerator).QuoRaw(thresholdFraction.Denominator) | ||||||
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. We may want to investigate / enforce that this never overflows 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. ref: #2878 |
||||||
} | ||||||
|
||||||
// ShouldUpgradeToV2 returns true if the current height is one before | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ func init() { | |
} | ||
|
||
const ( | ||
consensusVersion uint64 = 2 | ||
consensusVersion uint64 = 3 | ||
) | ||
|
||
var ( | ||
|
This file was deleted.
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 be done later, but could we have a quick doc here for this type since its exported?
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.
Yeah okay, maybe I just make it private. There's no need to have it public as it's not queryable