cardano-foundation / cardano-rosetta

An implementation of Rosetta for Cardano
https://www.rosetta-api.org
Apache License 2.0
98 stars 50 forks source link

/block Endpoint Incorrectly Returns Error for Nonexistent Blocks #536

Closed blorgon1 closed 1 year ago

blorgon1 commented 1 year ago

Summary

When querying the /block endpoint for a block_identifier that doesn't exist, a BLOCK_NOT_FOUND/4001 error is returned.

In this case, the Rosetta spec requires the response to be 200 with an empty response or { "block": null }: https://community.rosetta-api.org/t/handle-missed-blocks-for-block/349/3

Steps to reproduce the bug

Query /block with a payload containing a block_identifier that does not exist:

{
  "network_identifier": { "blockchain": "cardano", "network": "preprod" },
  "block_identifier": {"index": 1236859, "hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
}

Actual Result

{"code":4001,"message":"Block not found","retriable":false}

Expected Result

{"block": null}

Or

{}

Environment

2.1.0

Platform

Platform version

No response

Docker version

No response

blorgon1 commented 1 year ago

Apologies upon further review of the Rosetta docs, I believe the 200/empty block response should only be returned for "skipped" block indices. Returning an error when querying index+hash of reorged blocks is the correct behaviour.