fix(inpoints): NewTxInpoints returns non-nil empty ParentTxHashes#126
Merged
Conversation
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".
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Meta.Serializerejects nilTxInpoints[i].ParentTxHashesfor 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