Fix state leaf key removed query #99

Closed
opened 2021-09-09 12:40:36 +00:00 by arijitAD · 2 comments
arijitAD commented 2021-09-09 12:40:36 +00:00 (Migrated from github.com)

The issue of storage key removal is fixed in https://github.com/vulcanize/ipld-eth-server/pull/83/ but the same issue exists for state key removal.

Query to fetch storage leaf node

8a105812c2/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.
8a105812c2/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.
000c0ef066/db/migrations/00014_create_stored_functions.sql (L11-L14)

Added a fix for state node https://github.com/vulcanize/ipld-eth-server/pull/98

The issue of storage key removal is fixed in https://github.com/vulcanize/ipld-eth-server/pull/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: ```sql= 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 https://github.com/vulcanize/ipld-eth-server/pull/98
arijitAD commented 2021-09-09 12:46:11 +00:00 (Migrated from github.com)

Due to this incorrect query removed value was false and we were trying to decode nil value which lead to panic 000c0ef066/pkg/eth/ipld_retriever.go (L403-L409)

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
Member
Fixed in https://github.com/vulcanize/ipld-eth-server/issues/101
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cerc-io/ipld-eth-server#99
No description provided.