Skip to content

Fix miner initial block statehash#1706

Merged
nickeskov merged 9 commits into
masterfrom
fix-miner-initial-block-statehash
Jun 3, 2025
Merged

Fix miner initial block statehash#1706
nickeskov merged 9 commits into
masterfrom
fix-miner-initial-block-statehash

Conversation

@nickeskov

@nickeskov nickeskov commented May 30, 2025

Copy link
Copy Markdown
Collaborator

This pull request introduces several changes to improve reward distribution logic, enhance test coverage, and refactor the block addition process. The most notable updates include adding support for block height-based feature activation, creating new test suites for reward distribution scenarios, and refactoring the stateManager to modularize block addition steps.

Reward Distribution Enhancements:

  • Refactored addBlockReward in pkg/state/block_differ.go to support block height-based feature activation, ensuring reward logic is applied correctly at specific blockchain heights. [1] [2]
  • Updated createMinerAndRewardDiff to accept blockHeight as a parameter for more precise reward calculations. [1] [2]

Test Coverage Improvements:

  • Added new test suites (RewardDistributionIncreaseDaoXtnSupportedNoScalaMiningSuite and RewardDistributionAPIRollbackBeforeF21NoScalaMiningSuite) to validate reward distribution logic without Scala mining. [1] [2]
  • Modified existing tests in pkg/state/block_differ_test.go to incorporate block height in reward distribution validation. [1] [2]

Block Addition Refactor:

  • Modularized stateManager block addition process by introducing initBlockAdditionWithHeightActions, generateAndSaveBlockHitSource, and blockVerifyTaskWithHeaderValidation methods for better readability and maintainability. [1] [2] [3]
  • Ensured proper cleanup of in-memory storages after snapshot hash creation using the reset method. [1] [2]

Miscellaneous Updates:

  • Added config.WithNoScalaMining() as a new blockchain option to support Go-only mining scenarios. [1] [2]
  • Updated imports in test files to include the config package for blockchain options. [1] [2]

nickeskov added 3 commits May 30, 2025 15:43
Remove state height dependency: pass height as an argument.
It's necessary for calculating some consensus parameters which is
required for new blosk state hash generation.
@nickeskov nickeskov added the bug Something isn't working label May 30, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances block reward handling by introducing explicit block height parameters, refactors block validation logic into separate steps, and updates tests to cover height-specific reward scenarios.

  • Pass explicit blockHeight to reward methods (createMinerAndRewardDiff/addBlockReward) for height-based activation checks.
  • Refactor stateManager: separate header validation into blockVerifyTaskWithHeaderValidation and extend beforeAddingBlock for hit-source generation.
  • Update tests to supply and verify explicit block heights, and adjust snapshot creation and block-read-writer reset.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/state/state.go Extract header validation into blockVerifyTaskWithHeaderValidation; extend beforeAddingBlock; simulate in CreateNextSnapshotHash.
pkg/state/blockreadwriter.go Reset addingBlock flag in reset() method to ensure clean state between operations.
pkg/state/block_differ.go Add blockHeight parameter to createMinerAndRewardDiff/addBlockReward; switch to newestIsActivatedAtHeight.
pkg/state/appender.go Supply currentBlockHeight when calling createMinerAndRewardDiff.
pkg/state/block_differ_test.go Update all tests to retrieve and pass explicit heights (recentHeight()) to createMinerAndRewardDiff.
Comments suppressed due to low confidence (2)

pkg/state/block_differ_test.go:101

  • [nitpick] Variable name 'h' is too generic; consider renaming to 'currentHeight' for clarity.
h := to.stor.rw.recentHeight()

pkg/state/block_differ_test.go:116

  • [nitpick] Variable name 'hc' is unclear; consider renaming to 'childHeight' for better readability.
hc := to.stor.rw.recentHeight()

Comment thread pkg/state/state.go Outdated
Fix typo.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@nickeskov nickeskov added the do not merge The PR is not ready to be merged label May 30, 2025
@nickeskov nickeskov removed the bug Something isn't working label Jun 3, 2025
@nickeskov nickeskov added the bug Something isn't working label Jun 3, 2025
@nickeskov
nickeskov requested a review from Copilot June 3, 2025 02:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the block addition process, updates reward distribution logic to account for block height-based feature activation, and introduces new test suites to increase coverage for reward distribution scenarios.

  • Refactored internal functions in state management to modularize block addition steps
  • Updated reward distribution logic to incorporate block height parameters
  • Added new IT tests and blockchain options for Go-only mining support

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/state/state.go New modular functions for block addition and hit source generation with block height support
pkg/state/blockreadwriter.go Reset logic updated to explicitly reset the addingBlock flag
pkg/state/block_differ_test.go Updated test cases to pass current block height for reward diff calculation
pkg/state/block_differ.go Updated function signatures to include a blockHeight param for reward calculation
pkg/state/appender.go Passes current block height to the updated miner and reward diff function
itests/* Added/test updates for reward distribution in Go-only mining scenarios
Comments suppressed due to low confidence (1)

pkg/state/block_differ.go:265

  • Verify that passing the blockHeight parameter directly to applyToDiff fully replicates the previous logic from using addingBlockHeight() and accurately represents the intended block height.
if adErr := c.applyToDiff(diff, addr, blockHeight, reward); adErr != nil {

Comment thread pkg/state/state.go
Comment thread pkg/state/blockreadwriter.go
@nickeskov nickeskov added do not merge The PR is not ready to be merged and removed do not merge The PR is not ready to be merged labels Jun 3, 2025
@nickeskov

Copy link
Copy Markdown
Collaborator Author

Waiting merge of #1711

@nickeskov nickeskov removed the do not merge The PR is not ready to be merged label Jun 3, 2025
@nickeskov
nickeskov merged commit 0b0a3c0 into master Jun 3, 2025
22 checks passed
@nickeskov
nickeskov deleted the fix-miner-initial-block-statehash branch June 3, 2025 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants