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: add upgrade sequence to tx sim #3890

Merged
merged 4 commits into from
Sep 24, 2024
Merged

feat: add upgrade sequence to tx sim #3890

merged 4 commits into from
Sep 24, 2024

Conversation

cmwaters
Copy link
Contributor

@cmwaters cmwaters commented Sep 20, 2024

Adds the ability to use txsim to upgrade a network

@cmwaters cmwaters changed the title add upgrade sequence to tx sim feat: add upgrade sequence to tx sim Sep 23, 2024
@cmwaters cmwaters self-assigned this Sep 23, 2024
@cmwaters cmwaters marked this pull request as ready for review September 23, 2024 10:25
@cmwaters cmwaters requested a review from a team as a code owner September 23, 2024 10:25
@cmwaters cmwaters requested review from evan-forbes and ninabarbakadze and removed request for a team September 23, 2024 10:25
Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

Walkthrough

The changes introduce a new test function, TestTxSimUpgrade, to validate the upgrade process from version 2 to version 3 of the application. Additionally, a new file, upgrade.go, defines the UpgradeSequence struct, which manages the upgrade proposal and voting process within a blockchain context. This includes methods for initializing the upgrade sequence, allocating funds, and handling validator interactions during the upgrade process.

Changes

Files Change Summary
test/txsim/run_test.go Added the TestTxSimUpgrade function to test the upgrade from version 2 to version 3, including setup for consensus parameters, scheduling the upgrade, executing the simulation, and checking the upgrade status.
test/txsim/upgrade.go Introduced the UpgradeSequence struct to simulate an upgrade proposal and voting process. Added methods for initializing the upgrade, managing validator interactions, and handling the progression of the upgrade sequence.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@celestia-bot celestia-bot requested a review from a team September 23, 2024 10:27
}

opts := txsim.DefaultOptions().
// SuppressLogs().
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// SuppressLogs().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I uncommented this in another PR I'm working on

Comment on lines +198 to +200
// We can't check that the upgrade was successful because the upgrade height is thousands of blocks away
// and even at 300 millisecond block times, it would take too long. Instead we just want to assert
// that the upgrade is ready to be performed
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 good idea. As a separate issue we can explore making it easy to override the upgrade delay so that tests can configure it to be 1 block and verify the upgrade executed and app version transition from 2 -> 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm working on that right now actually

Copy link
Member

@ninabarbakadze ninabarbakadze left a comment

Choose a reason for hiding this comment

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

lgtm

@celestia-bot celestia-bot requested review from a team and staheri14 and removed request for a team September 24, 2024 09:05
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Outside diff range and nitpick comments (1)
test/txsim/run_test.go (1)

173-173: Typo in comment: "updrade" should be "upgrade"

There's a typo in the comment on line 173. Please correct "updrade" to "upgrade" for clarity.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 27dc26f and a798d6e.

Files selected for processing (2)
  • test/txsim/run_test.go (2 hunks)
  • test/txsim/upgrade.go (1 hunks)

Comment on lines +31 to +33
func (s *UpgradeSequence) Clone(_ int) []Sequence {
panic("cloning not supported for upgrade sequence. Only a single sequence is needed")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using panic in the Clone method.

Using panic in the Clone method can lead to unexpected crashes if the method is called. Consider returning nil or an empty slice to gracefully handle the unsupported operation, or implement the method as required by the Sequence interface.

Apply this diff to avoid panicking:

func (s *UpgradeSequence) Clone(_ int) []Sequence {
-	panic("cloning not supported for upgrade sequence. Only a single sequence is needed")
+	return nil // or return an empty slice []Sequence{}
}
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *UpgradeSequence) Clone(_ int) []Sequence {
panic("cloning not supported for upgrade sequence. Only a single sequence is needed")
}
func (s *UpgradeSequence) Clone(_ int) []Sequence {
return nil // or return an empty slice []Sequence{}
}

Comment on lines +35 to +38
// this is a no-op for the upgrade sequence
func (s *UpgradeSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccounts AccountAllocator, _ *rand.Rand, _ bool) {
s.account = allocateAccounts(1, fundsForUpgrade)[0]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update the comment to reflect the function's behavior.

The comment indicates that Init is a no-op, but the function allocates an account using allocateAccounts. Please update the comment to accurately describe the initialization logic.

Apply this diff to correct the comment:

-// this is a no-op for the upgrade sequence
+// Initialize the upgrade sequence by allocating an account
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// this is a no-op for the upgrade sequence
func (s *UpgradeSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccounts AccountAllocator, _ *rand.Rand, _ bool) {
s.account = allocateAccounts(1, fundsForUpgrade)[0]
}
// Initialize the upgrade sequence by allocating an account
func (s *UpgradeSequence) Init(_ context.Context, _ grpc.ClientConn, allocateAccounts AccountAllocator, _ *rand.Rand, _ bool) {
s.account = allocateAccounts(1, fundsForUpgrade)[0]
}

Comment on lines +55 to +65
// Choose a random validator to be the authority
var msg types.Msg
for _, validator := range validatorsResp.Validators {
if !s.voted[validator.OperatorAddress] {
msg = &signaltypes.MsgSignalVersion{
ValidatorAddress: validator.OperatorAddress,
Version: s.version,
}
s.voted[validator.OperatorAddress] = true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct the logic to select a random validator and prevent multiple message assignments.

The comment states that a random validator is chosen, but the code iterates over all validators, assigning msg multiple times without breaking the loop, and no randomness is involved.

Consider modifying the code to select a random validator who has not yet voted. Additionally, break the loop after assigning msg to prevent overwriting.

Apply this diff to select a random validator and break the loop:

 var msg types.Msg
+var notVotedValidators []stakingtypes.Validator
 for _, validator := range validatorsResp.Validators {
     if !s.voted[validator.OperatorAddress] {
-        msg = &signaltypes.MsgSignalVersion{
-            ValidatorAddress: validator.OperatorAddress,
-            Version:          s.version,
-        }
-        s.voted[validator.OperatorAddress] = true
-    }
+        notVotedValidators = append(notVotedValidators, validator)
+    }
 }
+
+if len(notVotedValidators) > 0 {
+    selectedValidator := notVotedValidators[rand.Intn(len(notVotedValidators))]
+    msg = &signaltypes.MsgSignalVersion{
+        ValidatorAddress: selectedValidator.OperatorAddress,
+        Version:          s.version,
+    }
+    s.voted[selectedValidator.OperatorAddress] = true
+} else {
+    // if all validators have voted, we can now try to upgrade.
+    msg = signaltypes.NewMsgTryUpgrade(s.account)
+    s.hasUpgraded = true
+}

Alternatively, if randomness is not necessary, update the comment and add a break statement after assigning msg:

-// Choose a random validator to be the authority
+// Find the next validator who hasn't voted yet
 var msg types.Msg
 for _, validator := range validatorsResp.Validators {
     if !s.voted[validator.OperatorAddress] {
         msg = &signaltypes.MsgSignalVersion{
             ValidatorAddress: validator.OperatorAddress,
             Version:          s.version,
         }
         s.voted[validator.OperatorAddress] = true
+        break // Prevent overwriting msg by breaking the loop
     }
 }
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Choose a random validator to be the authority
var msg types.Msg
for _, validator := range validatorsResp.Validators {
if !s.voted[validator.OperatorAddress] {
msg = &signaltypes.MsgSignalVersion{
ValidatorAddress: validator.OperatorAddress,
Version: s.version,
}
s.voted[validator.OperatorAddress] = true
}
}
// Choose a random validator to be the authority
var msg types.Msg
var notVotedValidators []stakingtypes.Validator
for _, validator := range validatorsResp.Validators {
if !s.voted[validator.OperatorAddress] {
notVotedValidators = append(notVotedValidators, validator)
}
}
if len(notVotedValidators) > 0 {
selectedValidator := notVotedValidators[rand.Intn(len(notVotedValidators))]
msg = &signaltypes.MsgSignalVersion{
ValidatorAddress: selectedValidator.OperatorAddress,
Version: s.version,
}
s.voted[selectedValidator.OperatorAddress] = true
} else {
// if all validators have voted, we can now try to upgrade.
msg = signaltypes.NewMsgTryUpgrade(s.account)
s.hasUpgraded = true
}

Comment on lines +198 to +200
// We can't check that the upgrade was successful because the upgrade height is thousands of blocks away
// and even at 300 millisecond block times, it would take too long. Instead we just want to assert
// that the upgrade is ready to be performed
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update comment to reflect actual upgrade height

The comment mentions that the upgrade height is thousands of blocks away, but the upgrade is scheduled at block height 20 in the code. Please update the comment to accurately reflect the current upgrade height.

)
require.NoError(t, err)

conn, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect function call: grpc.NewClient does not exist

The function grpc.NewClient does not exist in the grpc package. To create a gRPC client connection, you should use grpc.Dial.

Apply this diff to fix the function call:

-	conn, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
+	conn, err := grpc.Dial(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
conn, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.Dial(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))

@cmwaters cmwaters merged commit 418ddbf into main Sep 24, 2024
32 checks passed
@cmwaters cmwaters deleted the cal/v3-e2e-upgrade branch September 24, 2024 09:37
@coderabbitai coderabbitai bot mentioned this pull request Oct 7, 2024
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