Skip to content

fix(inpoints): NewTxInpoints returns non-nil empty ParentTxHashes#126

Merged
icellan merged 1 commit into
masterfrom
fix/newtxinpoints-empty-parents
May 19, 2026
Merged

fix(inpoints): NewTxInpoints returns non-nil empty ParentTxHashes#126
icellan merged 1 commit into
masterfrom
fix/newtxinpoints-empty-parents

Conversation

@icellan
Copy link
Copy Markdown
Contributor

@icellan icellan commented May 19, 2026

Summary

Meta.Serialize rejects nil TxInpoints[i].ParentTxHashes for non-coinbase nodes (subtree_meta.go:174). Prior to the packed-layout rewrite in v1.4.0 the cap-8 constructor produced a non-nil-but-empty slice, so callers that initialised `TxInpoints` to "empty" via `NewTxInpoints` satisfied that check naturally.

v1.4.0 returns the zero value, breaking downstream consumers that rely on a non-nil sentinel to distinguish "set, no parents" from "not set".

This restores the empty-but-non-nil `ParentTxHashes` — a slice header pointing to the runtime's zero-cap sentinel array, so no heap allocation is incurred.

Surfaced by

teranode CI after the v1.4.0 bump (bsv-blockchain/teranode#889):

```
TestBlock_ValidateSubtree_MissingParents/multiple_invalid_parents
TestBlock_ValidateSubtree_NodeIteration/subtree_with_multiple_nodes_iteration
```

both fail with `cannot serialize, parent tx hashes are not set for node N`.

Test plan

  • `go test -race ./...` green
  • Cut v1.4.1 after merge so downstream consumers can pin.

Meta.Serialize rejects nil TxInpoints[i].ParentTxHashes for non-coinbase
nodes (subtree_meta.go:174). Prior to the packed-layout rewrite in
v1.4.0 the cap-8 constructor produced a non-nil-but-empty slice, so
callers that initialised TxInpoints to "empty" via NewTxInpoints
satisfied that check naturally.

v1.4.0 returns the zero value, breaking downstream consumers that rely
on a non-nil sentinel to distinguish "set, no parents" from "not set".
Restore the empty-but-non-nil ParentTxHashes — a slice header pointing
to the runtime's zero-cap sentinel array, so no heap allocation is
incurred.

Surfaced by teranode CI after the v1.4.0 bump:
   TestBlock_ValidateSubtree_MissingParents/multiple_invalid_parents
   TestBlock_ValidateSubtree_NodeIteration/subtree_with_multiple_nodes_iteration
fail with "cannot serialize, parent tx hashes are not set for node N".
@icellan icellan requested a review from mrz1836 as a code owner May 19, 2026 09:04
@github-actions github-actions Bot added size/S Small change (11–50 lines) bug-P3 Lowest rated bug, affects nearly none or low-impact labels May 19, 2026
@sonarqubecloud
Copy link
Copy Markdown

@icellan icellan merged commit 2764214 into master May 19, 2026
44 checks passed
@github-actions github-actions Bot deleted the fix/newtxinpoints-empty-parents branch May 19, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-P3 Lowest rated bug, affects nearly none or low-impact size/S Small change (11–50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants