Skip to content

fix(fxconfig/transaction): prevent duplicate endorsements per MSP#250

Open
Prachi194agrawal wants to merge 1 commit into
hyperledger:mainfrom
Prachi194agrawal:bug/endorse-duplicate-fix
Open

fix(fxconfig/transaction): prevent duplicate endorsements per MSP#250
Prachi194agrawal wants to merge 1 commit into
hyperledger:mainfrom
Prachi194agrawal:bug/endorse-duplicate-fix

Conversation

@Prachi194agrawal

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix
  • Test update

Description

Endorse in tools/fxconfig/internal/transaction/endorse.go previously only checked whether tx.Endorsements was nil before appending endorsements. As a result, calling Endorse a second time with the same signer on a transaction that already carried endorsements would silently append a second EndorsementWithIdentity with the same MSP ID for each namespace, contrary to the intent expressed in the function comment and to the deduplication behavior of mergeEndorsements. [web:21]

This PR updates Endorse to prevent duplicate endorsements from the same MSP per namespace:

  • Before appending a new EndorsementWithIdentity, the function now scans existing entries for the current namespace.
  • If an existing endorsement with the same Identity.MspId is found, Endorse returns a descriptive error of the form:
    duplicate endorsement: signer %q already endorsed namespace %d.
  • If no duplicate is found, the endorsement is appended as before.

This change makes Endorse consistent with its own comment (“check that tx does not yet carry any endorsements”) and with mergeEndorsements, which already deduplicates endorsements by MSP ID. It also prevents transactions from leaving Endorse in a state where the same MSP ID appears more than once for a given namespace, which could cause confusing downstream validation behavior. [web:21]

Additional details (Optional)

A new regression test, TestEndorse_DuplicateSignerReturnsError, has been added to tools/fxconfig/internal/transaction/endorse_test.go. This test:

  • Constructs a transaction with a single namespace.
  • Calls Endorse once with a mock signer (e.g. Org1MSP) and asserts that one endorsement is present.
  • Calls Endorse a second time with the same signer and asserts that:
    • An error is returned.
    • The returned transaction is nil.
    • The error message contains duplicate endorsement. [web:21]

This ensures the duplicate-protection behavior is exercised and prevents regressions where duplicate endorsements might be silently appended again.

Related issues

Signed-off-by: Prachi Agrawal <prachi194agrawal@gmail.com>
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.

bug(fxconfig/transaction): Endorse() silently appends duplicate endorsements when called twice with the same signer

1 participant