cardano-foundation / cardano-wallet

HTTP server & command-line for managing UTxOs and HD wallets in Cardano.
Apache License 2.0
763 stars 211 forks source link

šŸž Bug: HTTP API returns "Internal Server Error" when attempting to encrypt multiple transaction metadata messages. #4652

Closed jonathanknowles closed 3 months ago

jonathanknowles commented 3 months ago

Version

a2cac93ed8f55512d4e3590a6c8d64f6df5c4f7b

Bug description

If:

And if:

Then the HTTP API will return "Internal Server Error".

Reproduction steps

See the following PR that demonstrates the issue:

With a fresh checkout of the above PR, run:

$ nix develop
$ just conway-integration-tests-match "encrypt multiple metadata messages"

Example failure links

Example failure log extract

only one 'msg' field expected
CallStack (from HasCallStack):
  error, called at src/Cardano/Wallet/Api/Http/Shelley/Server.hs:3207:24 in cardano-wallet-api-2024.5.5-AKdt1G4fjDDEhVlTTGjQVf:Cardano.Wallet.Api.Http.Shelley.Server
From the following response: Left
    ( DecodeFailure "Something went wrong" "Unexpected "Something went wrong", expecting JSON value" )
While verifying value:
  ( Status
      { statusCode = 500
      , statusMessage = "Internal Server Error"
      }
  , Left
      ( DecodeFailure "Something went wrong" "Unexpected "Something went wrong", expecting JSON value" )
  )
expected: Status {statusCode = 202, statusMessage = "Accepted"}
 but got: Status {statusCode = 500, statusMessage = "Internal Server Error"}

Expected behaviour

Either:

Or:

jonathanknowles commented 3 months ago

The cause of the internal server error is this section of code: https://github.com/cardano-foundation/cardano-wallet/blob/a2cac93ed8f55512d4e3590a6c8d64f6df5c4f7b/lib/api/src/Cardano/Wallet/Api/Http/Shelley/Server.hs#L3202-L3207

The error branch will only be evaluated if the TxMetadataDetailedSchema JSON serialisation option is used in conjunction with a TxMetaMap object that contains multiple msg keys.

If instead the TxMetadataNoSchema JSON serialisation option is used, then only the last msg key-value mapping will be retained, and the error branch will not be evaluated.

See https://github.com/cardano-foundation/cardano-wallet/issues/4647#issuecomment-2193646898 for an explanation of why this happens.

paweljakubas commented 3 months ago

addressed and fixed https://github.com/cardano-foundation/cardano-wallet/pull/4651