Fix miner initial block statehash#1706
Conversation
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.
There was a problem hiding this comment.
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
blockHeightto reward methods (createMinerAndRewardDiff/addBlockReward) for height-based activation checks. - Refactor
stateManager: separate header validation intoblockVerifyTaskWithHeaderValidationand extendbeforeAddingBlockfor 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()
Fix typo. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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 {
|
Waiting merge of #1711 |
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
stateManagerto modularize block addition steps.Reward Distribution Enhancements:
addBlockRewardinpkg/state/block_differ.goto support block height-based feature activation, ensuring reward logic is applied correctly at specific blockchain heights. [1] [2]createMinerAndRewardDiffto acceptblockHeightas a parameter for more precise reward calculations. [1] [2]Test Coverage Improvements:
RewardDistributionIncreaseDaoXtnSupportedNoScalaMiningSuiteandRewardDistributionAPIRollbackBeforeF21NoScalaMiningSuite) to validate reward distribution logic without Scala mining. [1] [2]pkg/state/block_differ_test.goto incorporate block height in reward distribution validation. [1] [2]Block Addition Refactor:
stateManagerblock addition process by introducinginitBlockAdditionWithHeightActions,generateAndSaveBlockHitSource, andblockVerifyTaskWithHeaderValidationmethods for better readability and maintainability. [1] [2] [3]resetmethod. [1] [2]Miscellaneous Updates:
config.WithNoScalaMining()as a new blockchain option to support Go-only mining scenarios. [1] [2]configpackage for blockchain options. [1] [2]