Skip to content

fix(transaction): validate endorsements count on merge#247

Open
Prachi194agrawal wants to merge 1 commit into
hyperledger:mainfrom
Prachi194agrawal:bug/merge-endorsements-length-check
Open

fix(transaction): validate endorsements count on merge#247
Prachi194agrawal wants to merge 1 commit into
hyperledger:mainfrom
Prachi194agrawal:bug/merge-endorsements-length-check

Conversation

@Prachi194agrawal
Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix

Description

This change prevents Merge from panicking when a transaction carries more
endorsement entries than namespace entries.

Previously, mergeEndorsements allocated its internal slices using
len(txs[0].GetNamespaces()), but then indexed them using positions from
tx.GetEndorsements(). When len(Endorsements) > len(Namespaces) for any
transaction, this led to an index out of range panic.

To fix this, validateTransactionsForMerge now checks that, for every
transaction, the endorsements count matches the base namespace count. If not,
Merge returns a descriptive error instead of panicking.

A test case was added to TestMerge_ErrorCases to cover the endorsements
count mismatch scenario.

Additional details (Optional)

The new validation leverages the existing baseNsCount computed from the
first transaction, so the check is performed consistently with the existing
namespace-count validation. The error message includes the transaction index
and both counts to aid debugging.

Tests:

  • go test ./tools/fxconfig/internal/transaction -run TestMerge_ErrorCases -v

Related issues

Signed-off-by: Prachi Agrawal <prachi194agrawal@gmail.com>
@Prachi194agrawal Prachi194agrawal force-pushed the bug/merge-endorsements-length-check branch from a43dc4b to 1697e9e Compare May 5, 2026 17:05
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.

1 participant