Skip to content
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!: introduce MsgTryUpgrade #2880

Merged
merged 2 commits into from
Dec 1, 2023
Merged

feat!: introduce MsgTryUpgrade #2880

merged 2 commits into from
Dec 1, 2023

Conversation

cmwaters
Copy link
Contributor

Addresses: #2877

Introduces a crank message for tallying all the signal messages

Copy link
Contributor

coderabbitai bot commented Nov 30, 2023

Walkthrough

Walkthrough

The Celestia blockchain has introduced a new RPC method 'TryUpgrade' to its upgrade module, allowing votes to be tallied and triggering upgrades at a specified height. This change replaces the previous 'EndBlock' logic with a direct method call that can be invoked via an endpoint. The upgrade process now involves a new message type for initiating upgrade requests and a corresponding response type. Additionally, the upgrade module's internal logic and test cases have been updated to reflect this new approach.

Changes

File Path Change Summary
proto/celestia/upgrade/v1/tx.proto Added 'TryUpgrade' RPC method, 'MsgTryUpgrade', and 'MsgTryUpgradeResponse'.
x/upgrade/keeper.go
x/upgrade/module.go
Replaced 'EndBlock' with 'TryUpgrade' method, updated 'MsgServer' implementation, and modified 'RegisterServices' method. Removed 'EndBlock' method.
x/upgrade/tally_test.go Updated test logic to use 'TryUpgrade' instead of 'EndBlock', adjusted assertions.
x/upgrade/types/msgs.go Added 'MsgTryUpgrade' struct, creation function, and methods 'GetSigners', 'ValidateBasic'.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@celestia-bot celestia-bot requested a review from a team November 30, 2023 16:33
Comment on lines 49 to 54
func (msg *MsgTryUpgrade) GetSigners() []sdk.AccAddress {
valAddr, err := sdk.ValAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sdk.AccAddress(valAddr)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetSigners() method for MsgTryUpgrade incorrectly converts the Signer from a Bech32 string to a ValAddress instead of an AccAddress. This should be corrected to avoid potential runtime errors.

- valAddr, err := sdk.ValAddressFromBech32(msg.Signer)
+ accAddr, err := sdk.AccAddressFromBech32(msg.Signer)
- return []sdk.AccAddress{sdk.AccAddress(valAddr)}
+ return []sdk.AccAddress{accAddr}

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (msg *MsgTryUpgrade) GetSigners() []sdk.AccAddress {
valAddr, err := sdk.ValAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sdk.AccAddress(valAddr)}
func (msg *MsgTryUpgrade) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{accAddr}

@@ -13,7 +13,7 @@ import (

// Keeper implements the MsgServer and QueryServer interfaces
var (
_ types.MsgServer = Keeper{}
_ types.MsgServer = &Keeper{}
_ types.QueryServer = Keeper{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Keeper struct should consistently implement interfaces either by pointer or by value. The QueryServer interface is still implemented by value, which is inconsistent with the MsgServer interface implementation. Consider updating the QueryServer implementation to use a pointer receiver for consistency.

- _ types.QueryServer = Keeper{}
+ _ types.QueryServer = &Keeper{}

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
_ types.QueryServer = Keeper{}
_ types.QueryServer = &Keeper{}

x/upgrade/types/msgs.go Outdated Show resolved Hide resolved
Comment on lines +104 to +105
if hasQuorum {
k.quorumVersion = version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quorumVersion is set within the TryUpgrade method without checking if it has already been set during the same block, which could lead to overwriting the quorumVersion if TryUpgrade is called multiple times. Consider adding a check to prevent overwriting an already established quorumVersion within the same block.

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only have one question about the signer

}

func (msg *MsgTryUpgrade) GetSigners() []sdk.AccAddress {
valAddr, err := sdk.ValAddressFromBech32(msg.Signer)
Copy link
Member

@evan-forbes evan-forbes Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking question]
why not just use a normal account address?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good catch. This was just copied over from the previous message type. Let me fix it

@celestia-bot celestia-bot requested a review from a team November 30, 2023 17:05
x/upgrade/types/msgs.go Show resolved Hide resolved
x/upgrade/types/msgs.go Show resolved Hide resolved
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I think it may be helpful for us to build an off-chain tool that tallies upgrade votes so that we know when it makes sense to submit the TryUpgrade message.

@cmwaters
Copy link
Contributor Author

cmwaters commented Dec 1, 2023

Yes I thought about implementing an upgrade daemon that continually queries the chain and sends the upgrade message when the quorum has been reached

@cmwaters cmwaters merged commit 95bda40 into main Dec 1, 2023
30 checks passed
@cmwaters cmwaters deleted the cal/msg-try-upgrade branch December 1, 2023 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants