diff --git a/pkg/eth/backend.go b/pkg/eth/backend.go index a09184ac..6c2d6caf 100644 --- a/pkg/eth/backend.go +++ b/pkg/eth/backend.go @@ -100,6 +100,7 @@ const ( RetrieveBlockNumberForStateRoot = `SELECT block_number FROM eth.header_cids WHERE state_root = $1 + AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number)) ORDER BY block_number DESC LIMIT 1` RetrieveBlockNumberAndStateLeafKeyForStorageRoot = `SELECT block_number, state_leaf_key @@ -108,6 +109,7 @@ const ( AND state_cids.state_path = state_accounts.state_path AND state_cids.header_id = state_accounts.header_id 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 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["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["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 } diff --git a/pkg/eth/ipld_retriever.go b/pkg/eth/ipld_retriever.go index fe36f991..c12ed34d 100644 --- a/pkg/eth/ipld_retriever.go +++ b/pkg/eth/ipld_retriever.go @@ -240,7 +240,7 @@ const ( ) WHERE tx_hash = $1 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 INNER JOIN public.blocks ON ( state_cids.mh_key = blocks.key @@ -249,6 +249,7 @@ const ( WHERE state_path = $1 AND state_cids.block_number <= $2 AND node_type != 3 + AND state_cids.header_id = (SELECT canonical_header_hash(state_cids.block_number)) ORDER BY state_cids.block_number DESC LIMIT 1` RetrieveStorageByStateLeafKeyAndPathAndBlockNumberPgStr = `SELECT storage_cids.cid, data, storage_cids.node_type @@ -266,6 +267,7 @@ const ( AND storage_path = $2 AND storage_cids.block_number <= $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 LIMIT 1` RetrieveAccountByLeafKeyAndBlockHashPgStr = `SELECT state_cids.cid, state_cids.mh_key, state_cids.block_number, state_cids.node_type