Skip to content

Add generation balance validation#1938

Merged
nickeskov merged 87 commits intodetermenistic-finality-featurefrom
add-generation-balace-validation
Dec 16, 2025
Merged

Add generation balance validation#1938
nickeskov merged 87 commits intodetermenistic-finality-featurefrom
add-generation-balace-validation

Conversation

@alexeykiselev
Copy link
Collaborator

@alexeykiselev alexeykiselev commented Dec 11, 2025

This pull request refactors how the minimal generating balance for block validation is determined, making it more flexible and future-proof by moving the logic into the state layer and using feature activation checks. Additionally, it updates related interfaces, mock implementations, and test code to support this change. Minor code cleanups and test message corrections are also included.

Consensus and Validation Logic Improvements:

  • The minimal generating balance check in blocks_validation.go now retrieves the required balance dynamically via the new MinimalGeneratingBalanceAtHeight method from the state, instead of using hardcoded constants and feature checks. This centralizes and simplifies the logic for determining the required balance for block generation. [1] [2]
  • Removed the smallerMinimalGeneratingBalanceActivated method and related constants, as this logic is now encapsulated in the state layer. [1] [2]

State Layer Enhancements:

  • Added the minimalGeneratingBalanceAtHeight method to the features struct, which determines the minimal generating balance based on height, timestamp, and feature activation. The corresponding interface and mock implementations are updated to support this. [1] [2] [3] [4]

Testing and Mock Updates:

  • Updated the stateInfoProvider and featuresState mocks and their usage in tests to support the new method signatures and logic, including tracking calls and arguments for the new and modified methods. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Minor Cleanups:

  • Simplified some conditional returns in block.go for marshaling logic and fixed a comment typo. [1] [2] [3]
  • Corrected test error messages to use "Ethereum" with a capital "E" for consistency. [1] [2] [3]

esuwu and others added 30 commits August 29, 2025 12:34
Submodule updated to the latest commit.
Package renamed from blssig to bls.
Crypto primitives SecretKey, PublicKey and Signature were added.
Public functions Sing and Verify reimplemented to use new primitives.
Function to create aggregated signature from multiple Waves secrets keys
was removed because it was useful only in tests.
PoP functions moved to separate file.
Fixed review issues.
BLS package used to validate PoP during transaction validation.
Reduced cognitive complexity of the new test.
Added test on JSON serialization of new transaction.
WIP: added skipped test on Scala compatibility of JSON serialization.
@alexeykiselev alexeykiselev requested a review from esuwu December 11, 2025 08:25
@alexeykiselev alexeykiselev added the awaiting-release Ready to be a part of a new release label Dec 11, 2025
@alexeykiselev alexeykiselev changed the base branch from master to add-commit-to-generation-transaction December 11, 2025 08:25
@alexeykiselev alexeykiselev added the do not merge The PR is not ready to be merged label Dec 11, 2025
@alexeykiselev alexeykiselev removed the do not merge The PR is not ready to be merged label Dec 11, 2025
Test on CommitToGeneration transaction JSON deserialization updated and skip removed.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds generation balance validation to CommitToGenerationWithProofs transactions, ensuring that generators have sufficient balance before committing to the next generation period.

Key Changes

  • Added balance validation in checkCommitToGenerationWithProofs that verifies the generator has enough balance after deducting the deposit (100 WAVES) and transaction fee to meet the minimal generating balance requirement
  • Implemented minimalGeneratingBalanceAtHeight function in the features layer to calculate the required minimal generating balance based on feature activations (1,000 WAVES with SmallerMinimalGeneratingBalance feature, otherwise 10,000 WAVES)
  • Refactored code for improved maintainability, including extracting Ethereum transaction validation logic into separate methods and consolidating common asset operation checks

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/state/transaction_checker_test.go Added comprehensive test cases for insufficient generating balance scenarios; updated existing test values to use smaller block heights for faster execution
pkg/state/transaction_checker.go Implemented generation balance validation logic; refactored Ethereum transaction checking into separate helper methods; improved error messages with proper capitalization
pkg/state/features.go Added minimalGeneratingBalanceAtHeight function to compute minimal generating balance based on timestamp and feature activation
pkg/state/state.go Added public MinimalGeneratingBalanceAtHeight method; improved recipient-to-address conversion with nil checks; removed unnecessary else clauses
pkg/state/feautures_interface.go Extended interface with minimalGeneratingBalanceAtHeight method
pkg/state/feautures_moq_test.go Updated mock implementation with new method
pkg/consensus/blocks_validation.go Refactored to use centralized minimalGeneratingBalanceAtHeight from state layer; removed duplicate constants and logic
pkg/consensus/validator_moq_test.go Updated mock with MinimalGeneratingBalanceAtHeight method
pkg/state/ethereum_tx_test.go Updated test expectations to match corrected error message capitalization
pkg/proto/block.go Fixed grammar in comment ("a io.Reader" → "an io.Reader"); removed unnecessary else clauses

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nickeskov
Copy link
Collaborator

@alexeykiselev should we mere this PR first or #1841?

Base automatically changed from add-commit-to-generation-transaction to determenistic-finality-feature December 16, 2025 07:01
@nickeskov nickeskov merged commit 87af3f3 into determenistic-finality-feature Dec 16, 2025
16 of 17 checks passed
@nickeskov nickeskov deleted the add-generation-balace-validation branch December 16, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-release Ready to be a part of a new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants