Skip to content

Ensure first transaction in subtree is coinbase placeholder#64

Merged
oskarszoon merged 6 commits into
bsv-blockchain:mainfrom
galt-tr:blockValidationCoinbase
Oct 28, 2025
Merged

Ensure first transaction in subtree is coinbase placeholder#64
oskarszoon merged 6 commits into
bsv-blockchain:mainfrom
galt-tr:blockValidationCoinbase

Conversation

@galt-tr

@galt-tr galt-tr commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

This pull request strengthens the validation logic for blocks by enforcing and testing that the first transaction in the first subtree is a coinbase placeholder. It makes this check active in the production code and adds comprehensive tests to ensure correct and incorrect scenarios are handled as expected.

Validation logic improvements:

  • Enforced the check in Block.Valid to require that the first transaction in the first subtree is a coinbase placeholder, returning an error if not.

Testing improvements:

  • Added a new test TestBlock_Valid_CoinbasePlaceholderCheck in Block_test.go that covers:
    • Valid blocks with the coinbase placeholder in the correct position.
    • Invalid blocks with a regular transaction in the first position.
    • Invalid blocks with the coinbase placeholder in the wrong subtree.
    • Behavior when subtree slices are empty.

@galt-tr galt-tr requested a review from icellan October 27, 2025 21:36
@galt-tr galt-tr force-pushed the blockValidationCoinbase branch from 2141d8a to e93a15e Compare October 28, 2025 00:50
@github-actions

github-actions Bot commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

Status: Complete

Current Review:
No issues found. The PR correctly enforces coinbase placeholder validation with comprehensive test coverage.

History:

  • ✅ Fixed: Typo in error message ("subtbree" → "subtree")
  • ✅ Clarified: Empty subtree test case is intentional for internal block validation scenarios

Summary:
This PR strengthens block validation by enforcing that the first transaction in the first subtree must be a coinbase placeholder. The implementation includes proper bounds checking and comprehensive tests covering valid/invalid scenarios.

Comment thread model/Block.go Outdated
Comment thread model/Block_test.go
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
75.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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