Skip to content

feat: hardcoded block time related values changes#3932

Merged
skosito merged 24 commits intodevelopfrom
hardcoded-block-time-values
May 30, 2025
Merged

feat: hardcoded block time related values changes#3932
skosito merged 24 commits intodevelopfrom
hardcoded-block-time-values

Conversation

@skosito
Copy link
Member

@skosito skosito commented May 29, 2025

Description

modifying hardcoded values related to block time reduction

it seems some of these can be set via params upgrade, but also updating default values here

Q: how is this value calculated?

BlockReward = sdkmath.LegacyMustNewDecFromStr("9620949074074074074.074070733466756687")

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features
    • Introduced a new migration that updates emissions module parameters during version upgrades.
  • Bug Fixes
    • Adjusted test logic to improve reliability by increasing the wait duration after sending BTC donations.
  • Chores
    • Updated block time and timeout parameters for improved performance.
    • Incremented the consensus version for the emissions module and registered the new migration.
    • Added a new entry to the changelog for unreleased features.

@skosito skosito added TSS_MIGRATION_TESTS Run TSS migration tests SOLANA_TESTS Run make start-solana-test PERFORMANCE_TESTS Run make start-e2e-performance-test labels May 29, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 29, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This update introduces a new migration for the emissions module, incrementing its consensus version and adding a migration routine for version 5 to 6. Several block time-related constants are adjusted for improved timing precision. The test suite is updated to accommodate these timing changes. Documentation is updated to reflect the new feature.

Changes

File(s) Change Summary
changelog.md Added entry describing the addition of hardcoded block time parameters for an unreleased version.
cmd/zetacored/root.go Changed DefaultTimeoutCommit constant from 5s to 3.5s.
pkg/constant/constant.go Updated ZetaBlockTime constant from 6s to 4.5s.
e2e/e2etests/test_bitcoin_donation.go Increased block wait in test from 4 to 6 Zeta blocks.
x/emissions/keeper/migrator.go Added Migrate5to6 method to the Migrator struct, invoking v6 migration logic.
x/emissions/migrations/v6/migrate.go Introduced MigrateStore function and EmissionsKeeper interface for updating emissions parameters.
x/emissions/migrations/v6/migrate_test.go Added TestMigrateStore to verify correct parameter migration and preservation of unrelated fields.
x/emissions/module.go Incremented consensus version to 6 and registered the new migration from version 5 to 6.

Sequence Diagram(s)

sequenceDiagram
    participant AppModule
    participant Migrator
    participant v6Migration
    participant EmissionsKeeper
    participant Store

    AppModule->>Migrator: Register Migrate5to6 for version 5
    Migrator->>v6Migration: Call MigrateStore(ctx, emissionsKeeper)
    v6Migration->>EmissionsKeeper: GetParams(ctx)
    EmissionsKeeper->>v6Migration: Return Params
    v6Migration->>EmissionsKeeper: SetParams(ctx, updatedParams)
    EmissionsKeeper->>Store: Save updated Params
    v6Migration->>Migrator: Return success/error
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@skosito skosito added the UPGRADE_TESTS Run make start-upgrade-tests label May 29, 2025
Base automatically changed from add-support-to-set-config-toml-default-values to develop May 29, 2025 21:16
@skosito skosito marked this pull request as ready for review May 29, 2025 23:51
@skosito skosito requested a review from a team as a code owner May 29, 2025 23:51
@codecov
Copy link

codecov bot commented May 29, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 64.85%. Comparing base (c73ff7e) to head (76f8634).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
x/emissions/migrations/v6/migrate.go 91.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3932   +/-   ##
========================================
  Coverage    64.84%   64.85%           
========================================
  Files          471      472    +1     
  Lines        34434    34446   +12     
========================================
+ Hits         22330    22341   +11     
- Misses       11074    11075    +1     
  Partials      1030     1030           
Files with missing lines Coverage Δ
x/emissions/migrations/v6/migrate.go 91.66% <91.66%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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: 1

🧹 Nitpick comments (1)
x/emissions/migrations/v6/migrate_test.go (1)

13-51: Comprehensive test coverage with one gap.

The test effectively validates that only the intended parameters are updated while others remain unchanged. The expected values align correctly with the migration logic.

Consider adding a test case for the error scenario when parameters are not found:

+	t.Run("return error when params not found", func(t *testing.T) {
+		// Arrange
+		k, ctx, _, _ := keepertest.EmissionsKeeper(t)
+		// Don't set params to simulate missing params scenario
+
+		// Act
+		err := v6.MigrateStore(ctx, k)
+
+		// Assert
+		require.Error(t, err)
+		require.Contains(t, err.Error(), "emission params not found")
+	})
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b427bf3 and b25455e.

📒 Files selected for processing (8)
  • changelog.md (1 hunks)
  • cmd/zetacored/root.go (1 hunks)
  • e2e/e2etests/test_bitcoin_donation.go (1 hunks)
  • pkg/constant/constant.go (1 hunks)
  • x/emissions/keeper/migrator.go (2 hunks)
  • x/emissions/migrations/v6/migrate.go (1 hunks)
  • x/emissions/migrations/v6/migrate_test.go (1 hunks)
  • x/emissions/module.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • e2e/e2etests/test_bitcoin_donation.go
  • pkg/constant/constant.go
  • cmd/zetacored/root.go
  • x/emissions/keeper/migrator.go
  • x/emissions/module.go
  • x/emissions/migrations/v6/migrate_test.go
  • x/emissions/migrations/v6/migrate.go
🧬 Code Graph Analysis (3)
e2e/e2etests/test_bitcoin_donation.go (1)
pkg/constant/constant.go (1)
  • ZetaBlockTime (8-8)
x/emissions/migrations/v6/migrate_test.go (4)
x/emissions/migrations/v6/migrate.go (2)
  • EmissionsKeeper (13-16)
  • MigrateStore (20-35)
x/emissions/types/params.go (1)
  • DefaultParams (24-26)
x/emissions/types/keys.go (2)
  • BallotMaturityBlocks (54-54)
  • ObserverSlashAmount (50-50)
x/observer/migrations/v11/migrate.go (1)
  • PendingBallotsDeletionBufferBlocks (19-19)
x/emissions/migrations/v6/migrate.go (1)
x/emissions/types/keys.go (1)
  • BallotMaturityBlocks (54-54)
🪛 GitHub Check: codecov/patch
x/emissions/migrations/v6/migrate.go

[warning] 34-34: x/emissions/migrations/v6/migrate.go#L34
Added line #L34 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: start-upgrade-test / e2e
  • GitHub Check: start-tss-migration-test / e2e
  • GitHub Check: start-solana-test / e2e
  • GitHub Check: start-e2e-test / e2e
  • GitHub Check: start-e2e-performance-test / e2e
🔇 Additional comments (8)
pkg/constant/constant.go (1)

8-8:

Details

✅ Verification successful

Block time reduction looks well-coordinated.

The reduction from 6000ms to 4500ms (25% decrease) represents a significant improvement to block production timing. This change appears properly coordinated with the consensus timeout adjustments in cmd/zetacored/root.go.

To ensure this change doesn't introduce timing-related issues, please verify that all timing-dependent components have been updated accordingly:


🏁 Script executed:

#!/bin/bash
# Description: Search for hardcoded values that might reference the old 6000ms block time
# Expected: Any hardcoded timing values should be reviewed for compatibility

echo "Searching for potential hardcoded timing values..."
rg -n "6000|6\s*\*\s*time\." --type go
echo ""
echo "Searching for other block time references..."
rg -n "ZetaBlockTime|block.*time|timeout.*commit" --type go -A 2 -B 2

Length of output: 90196


🏁 Script executed:

#!/bin/bash
set -e

echo "🔍 Searching for literal 6000ms block‐time usages in pkg/ and cmd/…"
rg -n "6000\s*\*\s*time\.Millisecond" --type go pkg cmd || echo "✔ No literal 6000ms found."

echo ""
echo "🔍 Searching for literal 6 * time.Second usages in pkg/ and cmd/…"
rg -n "6\s*\*\s*time\.Second" --type go pkg cmd || echo "✔ No literal 6 * time.Second found."

echo ""
echo "🔍 Searching for all ZetaBlockTime references in pkg/ and cmd/…"
rg -n "ZetaBlockTime" --type go pkg cmd || echo "✔ No other ZetaBlockTime usages found."

Length of output: 901


Block time constant update is consistent
Searches in pkg/ and cmd/ confirm there are no remaining hardcoded 6000ms or 6*time.Second usages—only ZetaBlockTime = 4500*time.Millisecond remains. No further changes are necessary.

changelog.md (1)

33-33: Documentation properly captures the feature addition.

The changelog entry accurately describes the addition of hardcoded block time related parameters, providing appropriate traceability for this significant timing adjustment.

e2e/e2etests/test_bitcoin_donation.go (1)

27-28: Test timing adjustment appropriately maintains stability buffer.

The increase from 4 to 6 blocks provides a conservative timing adjustment that accounts for the reduced block time while maintaining test reliability. The total wait time increases slightly from 24 seconds to 27 seconds (6 × 4.5s), which provides additional safety margin for test stability.

cmd/zetacored/root.go (1)

52-52: Consensus timeout reduction properly coordinated with block time changes.

The reduction from 5 seconds to 3.5 seconds (30% decrease) aligns well with the block time reduction from 6 seconds to 4.5 seconds (25% decrease). This maintains appropriate consensus timing relationships while improving overall network responsiveness.

x/emissions/keeper/migrator.go (1)

8-8: Migration implementation follows established patterns correctly.

The new Migrate5to6 method and import addition are implemented consistently with the existing migration pattern. The code structure is clean and maintainable.

Also applies to: 30-33

x/emissions/module.go (1)

25-25: Version upgrade implementation is correct.

The consensus version increment and migration registration update are properly aligned and follow the expected pattern for module migrations.

Also applies to: 138-138

x/emissions/migrations/v6/migrate.go (2)

28-28: Clarify the calculation basis for BlockRewardAmount.

The hardcoded BlockRewardAmount value uses a very precise decimal string that aligns with the PR author's question about how this value is calculated.

Please provide documentation or comments explaining how this specific value was derived, as it's not immediately clear from the codebase:

+		// BlockRewardAmount calculated as: [provide formula/reasoning here]
 		params.BlockRewardAmount = sdkmath.LegacyMustNewDecFromStr("7595486111111111680.000000000000000000")

This will improve maintainability and help future developers understand the rationale behind this specific value.


34-34: Error path lacks test coverage.

The error case on line 34 is not covered by tests, as indicated by static analysis tools. While this scenario should theoretically not occur, having test coverage would improve confidence in the migration's robustness.

The missing test coverage was already addressed in the previous file review suggestion. This aligns with the static analysis finding.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 34-34: x/emissions/migrations/v6/migrate.go#L34
Added line #L34 was not covered by tests

@skosito skosito requested a review from lumtis May 30, 2025 14:21
@skosito skosito enabled auto-merge May 30, 2025 15:44
Copy link
Member

@kingpinXD kingpinXD left a comment

Choose a reason for hiding this comment

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

https://github.com/zeta-chain/zeta-node/blob/5c890dec7e106a6730513c1f216a96e8aeef18f3/contrib/localnet/orchestrator/start-zetae2e.sh#L256-L256

The upgrade tests are linked to the height , I think we might need to increase this as well in case the first round of tests dont complete on time .

I thionk the tests would still work , even if the upgrade happens before the e2e tests complete but we should increase this number to a time after we expect the e2e runs to be done

@skosito
Copy link
Member Author

skosito commented May 30, 2025

https://github.com/zeta-chain/zeta-node/blob/5c890dec7e106a6730513c1f216a96e8aeef18f3/contrib/localnet/orchestrator/start-zetae2e.sh#L256-L256

The upgrade tests are linked to the height , I think we might need to increase this as well in case the first round of tests dont complete on time .

I thionk the tests would still work , even if the upgrade happens before the e2e tests complete but we should increase this number to a time after we expect the e2e runs to be done

is this related to block time decrease? on localnet we dont change actual block time, it is 2s timeout_commit before and after upgrade so should not be affected?

@skosito skosito disabled auto-merge May 30, 2025 16:33
@skosito skosito enabled auto-merge May 30, 2025 17:23
@skosito skosito disabled auto-merge May 30, 2025 18:54
Copy link
Member

@CharlieMc0 CharlieMc0 left a comment

Choose a reason for hiding this comment

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

Need to plan on 4 seconds block times not 4.5s

@skosito skosito requested a review from CharlieMc0 May 30, 2025 19:18
@skosito skosito added this pull request to the merge queue May 30, 2025
Merged via the queue into develop with commit d33d8ac May 30, 2025
47 checks passed
@skosito skosito deleted the hardcoded-block-time-values branch May 30, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PERFORMANCE_TESTS Run make start-e2e-performance-test SOLANA_TESTS Run make start-solana-test TSS_MIGRATION_TESTS Run TSS migration tests UPGRADE_TESTS Run make start-upgrade-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants