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

fix: correctly handle get_proof for contract without a root index #5

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

whichqua
Copy link

@whichqua whichqua commented Oct 3, 2024

In a nutshell

Key changes include:

  • Adjusting the get_proof method to return an empty list when no contract root is found.
  • Adding checks for None values when retrieving contract roots.

Problem:

Pathfinder returns an internal error when one tries to fetch a proof for contract with a contract_state_hash but without a root_index for the current block height. Pathfinder returns none which is propagated down to an internal error.

Replication

The following is an example of a request that fails without this fix:

{
  "id": "0",
  "jsonrpc": "2.0",
  "method": "pathfinder_getProof",
  "params": {
    "block_id": {
      "block_number": 155006
    },
    "contract_address": "0x40a29e36c82f868dc2b5712bc6729c6132ca75ae46d6c75718ecbd49a0c9fb7",
    "keys": [
      "0x206f38f7e4f15e87567361213c28f235cccdaa1d7fd34c9db1dfe9489c6a091"
    ]
  }
}

Solution:

When there is no root_index, this fix will return empty ProofNodes ie ProofNodes(vec![]) for each of the keys.

Extras

This fix also prevents multiple calls to the database fetching the same root (same contract and block number) while looping through the keys.

@whichqua whichqua changed the title fix: correctly handle contract without a root index fix: get_proof correctly handle contract without a root index Oct 3, 2024
@whichqua whichqua changed the title fix: get_proof correctly handle contract without a root index fix: correctly handle get_proof for contract without a root index Oct 3, 2024
Key changes include:
- Adjusting the get_proof method to return an empty list when no contract root is found.
- Adding checks for None values when retrieving contract roots.

Pathfinder returns an internal error when one tries to fetch a proof for contract with a `contract_state_hash` but without a `root_index` for the current block height. Pathfinder returns none which is propagated down to an internal error.

The following is an example of a request that fails without this fix:
```json
{
  "id": "0",
  "jsonrpc": "2.0",
  "method": "pathfinder_getProof",
  "params": {
    "block_id": {
      "block_number": 155006
    },
    "contract_address": "0x40a29e36c82f868dc2b5712bc6729c6132ca75ae46d6c75718ecbd49a0c9fb7",
    "keys": [
      "0x206f38f7e4f15e87567361213c28f235cccdaa1d7fd34c9db1dfe9489c6a091"
    ]
  }
}
```

When there is no root_index, this fix will return empty `ProofNodes` ie `ProofNodes(vec![])` for each of the keys.

This fix also prevents multiple calls to the database fetching the same root (same contract and block number) while looping through the keys.
@whichqua whichqua force-pushed the gm/return-empty-proofs-if-no-root branch from 8f08993 to aa96876 Compare October 4, 2024 13:26
@ftheirs ftheirs merged commit 46172d2 into main Nov 25, 2024
7 checks passed
@whichqua whichqua deleted the gm/return-empty-proofs-if-no-root branch November 25, 2024 13:15
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.

2 participants