Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jonathanknowles opened this issue Jun 27, 2024 · 2 comments
Assignees
Labels

Comments

@jonathanknowles
Copy link
Member

jonathanknowles commented Jun 27, 2024

Version

a2cac93

Bug description

If:

  • the user calls the constructTransaction HTTP API endpoint
  • the metadata field is populated with metadata to be encrypted according to CIP-83

And if:

  • the included metadata map includes more than one message with a msg key
  • the detailed JSON schema option TxMetadataDetailedSchema is used.

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:

  • The API returns a dedicated error with a corresponding schema definition, indicating that only one message is allowed to be encrypted.

Or:

  • The API accepts more than one message for encryption, and encrypts them all of them.
@jonathanknowles jonathanknowles changed the title HTTP API returns "Internal Server Error" on attempt to encrypt multiple transaction metadata messages. HTTP API returns "Internal Server Error" when attempting to encrypt multiple transaction metadata messages. Jun 27, 2024
@jonathanknowles
Copy link
Member Author

jonathanknowles commented Jun 27, 2024

The cause of the internal server error is this section of code:

parseMessage = \case
TxMetaMap kvs ->
case mapMaybe getValue kvs of
[ ] -> Nothing
[v] -> Just v
_vs -> error "only one 'msg' field expected"

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 #4647 (comment) for an explanation of why this happens.

@jonathanknowles jonathanknowles changed the title HTTP API returns "Internal Server Error" when attempting to encrypt multiple transaction metadata messages. 🐞 Bug: HTTP API returns "Internal Server Error" when attempting to encrypt multiple transaction metadata messages. Jun 27, 2024
github-merge-queue bot pushed a commit that referenced this issue Jun 29, 2024
…tempting to encrypt multiple transaction metadata messages. (#4651)

## Related issue

- #4652

## Description

This PR demonstrates that if:
- the user calls the `constructTransaction` HTTP API endpoint
- the `metadata` field is populated with metadata to be encrypted
according to [CIP-83](https://cips.cardano.org/cip/CIP-83)

And if:
- the included metadata map includes **_more than one_** message with a
`msg` key
- the **_detailed_** JSON schema option `TxMetadataDetailedSchema` is
used.

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

## How to reproduce the failure

With a fresh checkout of the branch in this PR, run:

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

## Example failure links

-
https://buildkite.com/cardano-foundation/cardano-wallet/builds/5570#01905814-2e6e-460b-83aa-7cfed4ede245/139-753
-
https://buildkite.com/cardano-foundation/cardano-wallet/builds/5570#01905814-2e70-4cc3-b3f8-8f8f3d9eb0f8/139-758

## Example failure log extract
```hs
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"}
```
@paweljakubas
Copy link
Contributor

addressed and fixed #4651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants