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 state leaf key removed query #99

Closed
arijitAD opened this issue Sep 9, 2021 · 2 comments · Fixed by #98
Closed

Fix state leaf key removed query #99

arijitAD opened this issue Sep 9, 2021 · 2 comments · Fixed by #98

Comments

@arijitAD
Copy link
Contributor

arijitAD commented Sep 9, 2021

The issue of storage key removal is fixed in #83 but the same issue exists for state key removal.

Query to fetch storage leaf node

https://github.com/vulcanize/ipld-eth-server/blob/8a105812c206067b6f1d266ed2daea2f9b2176c6/pkg/eth/ipld_retriever.go#L146-L160

Example:

SELECT storage_cids.cid,blocks.data,
    was_storage_removed(storage_path,block_number,'0x4d172383ff04943c44b55a043e56145db94caf7aed03487151f6182f1ce2ea78') 
    AS removed
FROM eth.storage_cids
         INNER JOIN eth.state_cids ON (storage_cids.state_id = state_cids.id)
         INNER JOIN eth.header_cids ON (state_cids.header_id = header_cids.id)
         INNER JOIN public.blocks ON (storage_cids.mh_key = blocks.key)
    WHERE state_leaf_key = '0x6114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45'
        AND storage_leaf_key = '0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6'
        AND block_number <= (SELECT block_number
                       FROM eth.header_cids
                       WHERE block_hash = '0x4d172383ff04943c44b55a043e56145db94caf7aed03487151f6182f1ce2ea78')
        AND header_cids.id = (SELECTcanonical_header_id(block_number))
ORDER BY block_number DESC
LIMIT 1;

The above query will fetch the latest leaf node and this is passed on to was_storage_removed

This is the code before it was fixed.
https://github.com/vulcanize/ipld-eth-server/blob/8a105812c206067b6f1d266ed2daea2f9b2176c6/db/migrations/00014_create_stored_functions.sql#L4-L17

This will always return false as the height in was_storage_removed is the block_number passed , so height = block_number but block_number > height condition will evaluate to false.

This is fixed for the storage node in the master branch.
https://github.com/vulcanize/ipld-eth-server/blob/000c0ef066b530698a4d29f827a269c8fb4433b8/db/migrations/00014_create_stored_functions.sql#L11-L14

Added a fix for state node #98

@arijitAD
Copy link
Contributor Author

arijitAD commented Sep 9, 2021

Due to this incorrect query removed value was false and we were trying to decode nil value which lead to panic https://github.com/vulcanize/ipld-eth-server/blob/000c0ef066b530698a4d29f827a269c8fb4433b8/pkg/eth/ipld_retriever.go#L403-L409

@i-norden
Copy link
Collaborator

Fixed in #101

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 a pull request may close this issue.

2 participants