Skip to content

4364: Test with blocks which have early duplicates which are fully sp…#198

Merged
liam merged 7 commits into
bsv-blockchain:mainfrom
liam:feature/blockValidationDuplicateTest
Nov 26, 2025
Merged

4364: Test with blocks which have early duplicates which are fully sp…#198
liam merged 7 commits into
bsv-blockchain:mainfrom
liam:feature/blockValidationDuplicateTest

Conversation

@liam

@liam liam commented Nov 20, 2025

Copy link
Copy Markdown
Collaborator

…ent & pruned

@liam liam requested a review from sugh01 November 20, 2025 15:15
@github-actions

github-actions Bot commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

🤖 Claude Code Review

Status: Complete


Findings:

The PR fixes a critical bug in duplicate transaction detection where the index calculation was incorrect for incomplete last subtrees. The fix is correct, but the tests have several issues that need addressing per reviewer feedback:

Test Issues (per human reviewer comments):

  • Generating 101 blocks is too heavy for CI - should use 2 blocks and MineAndWait helper
  • Excessive use of t.Logf statements should be removed unless required
  • Several skipped tests and TODO comments need cleanup
  • TestEarlyDuplicatePartiallySpentAndPruned needs CreateTransactionWithOption for multiple outputs
  • Some tests can be removed as they're already covered by other functionality

Core Fix (model/Block.go:629-635):
The baseIdx calculation fix is correct - it now sums actual subtree sizes instead of assuming all subtrees are the same size as the first one. This properly handles the last incomplete subtree.


Action Items:
See inline comments from @sugh01 for specific test improvements needed.

err := td.BlockchainClient.Run(td.Ctx, "test")
require.NoError(t, err)

err = td.BlockAssemblyClient.GenerateBlocks(td.Ctx, &blockassembly_api.GenerateBlocksRequest{Count: 101})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we have MineAndWait helper, may be use that
also 101 is too heavy for CI, 2 should be good for tests

err = td.BlockValidationClient.ProcessBlock(td.Ctx, block102, block102.Height, "", "legacy")
require.Error(t, err, "Block with duplicates should be rejected even with concurrency=0")

t.Logf("✓ Duplicate detection works with concurrency=0 (uses default)")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we need to avoid this pattern of t.Logf, unless required

// NOTE: This test is skipped because with spending transactions in the block, the block validation
// fails during transaction processing (UTXO validation) before the duplicate detection check runs.
// The test TestEarlyDuplicatePartiallySpentAndPruned covers a similar scenario successfully.
func TestEarlyDuplicateFullySpentAndPruned(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let us remove this

Comment thread test/sequentialtest/double_spend/early_duplicate_test.go
require.NoError(t, err)

err = td.BlockAssemblyClient.GenerateBlocks(td.Ctx, &blockassembly_api.GenerateBlocksRequest{Count: 101})
require.NoError(t, err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Generate blocks create blocks with just coinbase, so it gets tested by default, this test can be removed

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.

2 participants