Implement getSlice API #206

Merged
prathamesh0 merged 21 commits from pm-get-slice into v4 2022-12-19 08:42:23 +00:00
2 changed files with 7 additions and 3 deletions
Showing only changes of commit 8e061504a2 - Show all commits

View File

@ -100,6 +100,7 @@ const (
RetrieveBlockNumberForStateRoot = `SELECT block_number RetrieveBlockNumberForStateRoot = `SELECT block_number
FROM eth.header_cids FROM eth.header_cids
WHERE state_root = $1 WHERE state_root = $1
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number))
ORDER BY block_number DESC ORDER BY block_number DESC
LIMIT 1` LIMIT 1`
RetrieveBlockNumberAndStateLeafKeyForStorageRoot = `SELECT block_number, state_leaf_key RetrieveBlockNumberAndStateLeafKeyForStorageRoot = `SELECT block_number, state_leaf_key
@ -108,6 +109,7 @@ const (
AND state_cids.state_path = state_accounts.state_path AND state_cids.state_path = state_accounts.state_path
AND state_cids.header_id = state_accounts.header_id AND state_cids.header_id = state_accounts.header_id
AND state_cids.block_number = state_accounts.block_number AND state_cids.block_number = state_accounts.block_number
AND state_accounts.header_id = (SELECT canonical_header_hash(state_accounts.block_number))
ORDER BY state_accounts.block_number DESC ORDER BY state_accounts.block_number DESC
LIMIT 1` LIMIT 1`
) )
@ -977,10 +979,10 @@ func (b *Backend) GetStateSlice(path string, depth int, root common.Hash) (*GetS
} }
response.MetaData.NodeStats["01-max-depth"] = strconv.Itoa(maxDepth) response.MetaData.NodeStats["01-max-depth"] = strconv.Itoa(maxDepth)
response.MetaData.NodeStats["02-total-trie-nodes"] = strconv.Itoa(len(response.TrieNodes.Stem) + len(response.TrieNodes.Slice) + 1) response.MetaData.NodeStats["02-total-trie-nodes"] = strconv.Itoa(len(response.TrieNodes.Stem) + len(response.TrieNodes.Head) + len(response.TrieNodes.Slice))
response.MetaData.NodeStats["03-leaves"] = strconv.Itoa(len(leafNodes)) response.MetaData.NodeStats["03-leaves"] = strconv.Itoa(len(leafNodes))
response.MetaData.NodeStats["04-smart-contracts"] = "" // TODO: count # of contracts response.MetaData.NodeStats["04-smart-contracts"] = "" // TODO: count # of contracts
response.MetaData.NodeStats["00-stem-and-head-nodes"] = strconv.Itoa(len(response.TrieNodes.Stem) + 1) response.MetaData.NodeStats["00-stem-and-head-nodes"] = strconv.Itoa(len(response.TrieNodes.Stem) + len(response.TrieNodes.Head))
return response, nil return response, nil
} }

View File

@ -240,7 +240,7 @@ const (
) )
WHERE tx_hash = $1 WHERE tx_hash = $1
AND transaction_cids.header_id = (SELECT canonical_header_hash(transaction_cids.block_number))` AND transaction_cids.header_id = (SELECT canonical_header_hash(transaction_cids.block_number))`
RetrieveStateByPathAndBlockNumberPgStr = `SELECT cid, data, node_type RetrieveStateByPathAndBlockNumberPgStr = `SELECT cid, data, node_type, state_cids.block_number
FROM eth.state_cids FROM eth.state_cids
INNER JOIN public.blocks ON ( INNER JOIN public.blocks ON (
state_cids.mh_key = blocks.key state_cids.mh_key = blocks.key
@ -249,6 +249,7 @@ const (
WHERE state_path = $1 WHERE state_path = $1
AND state_cids.block_number <= $2 AND state_cids.block_number <= $2
AND node_type != 3 AND node_type != 3
AND state_cids.header_id = (SELECT canonical_header_hash(state_cids.block_number))
ORDER BY state_cids.block_number DESC ORDER BY state_cids.block_number DESC
LIMIT 1` LIMIT 1`
RetrieveStorageByStateLeafKeyAndPathAndBlockNumberPgStr = `SELECT storage_cids.cid, data, storage_cids.node_type RetrieveStorageByStateLeafKeyAndPathAndBlockNumberPgStr = `SELECT storage_cids.cid, data, storage_cids.node_type
@ -266,6 +267,7 @@ const (
AND storage_path = $2 AND storage_path = $2
AND storage_cids.block_number <= $3 AND storage_cids.block_number <= $3
AND node_type != 3 AND node_type != 3
AND storage_cids.header_id = (SELECT canonical_header_hash(storage_cids.block_number))
ORDER BY storage_cids.block_number DESC ORDER BY storage_cids.block_number DESC
LIMIT 1` LIMIT 1`
RetrieveAccountByLeafKeyAndBlockHashPgStr = `SELECT state_cids.cid, state_cids.mh_key, state_cids.block_number, state_cids.node_type RetrieveAccountByLeafKeyAndBlockHashPgStr = `SELECT state_cids.cid, state_cids.mh_key, state_cids.block_number, state_cids.node_type