fix(transaction): validate endorsements count on merge#247
Open
Prachi194agrawal wants to merge 1 commit into
Open
fix(transaction): validate endorsements count on merge#247Prachi194agrawal wants to merge 1 commit into
Prachi194agrawal wants to merge 1 commit into
Conversation
Signed-off-by: Prachi Agrawal <prachi194agrawal@gmail.com>
a43dc4b to
1697e9e
Compare
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.
Type of change
Description
This change prevents
Mergefrom panicking when a transaction carries moreendorsement entries than namespace entries.
Previously,
mergeEndorsementsallocated its internal slices usinglen(txs[0].GetNamespaces()), but then indexed them using positions fromtx.GetEndorsements(). Whenlen(Endorsements) > len(Namespaces)for anytransaction, this led to an
index out of rangepanic.To fix this,
validateTransactionsForMergenow checks that, for everytransaction, the endorsements count matches the base namespace count. If not,
Mergereturns a descriptive error instead of panicking.A test case was added to
TestMerge_ErrorCasesto cover the endorsementscount mismatch scenario.
Additional details (Optional)
The new validation leverages the existing
baseNsCountcomputed from thefirst 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 -vRelated issues