pokt-network / pocket-core

Official implementation of the Pocket Network Protocol
http://www.pokt.network
MIT License
209 stars 103 forks source link

minor: Use height in query account txs #1525

Closed 0xBigBoss closed 1 year ago

0xBigBoss commented 1 year ago

This PR Adds a new query parameter to the accounttxs endpoint to allow querying for account (send/received) txs starting at a certain height.

This is not a breaking change, as the new parameter is optional. If it is not provided, the endpoint will behave as it did before.

It is a performance improvement, as it allows the client to specify a height to start querying from, instead of having to query all txs and then filter them out.

You can try and verify by running the following commands:

CURRENT_POKT_RPC_URL= # replace with current rpc url POKT_RPC_WITH_HEIGHT_INDEX_URL= # replace with new rpc url built from this branch

Tested using the SendNodes POPs address.

pull hash and height of first and last tx

curl --request POST \
 --url http://CURRENT_POKT_RPC_URL/v1/query/accounttxs \
 --header 'Content-Type: application/json' \
 --data '{
"address": "cb6ff4204f8a93e89759c22a9e0f8896f8561379",
"page": 1,
"per_page": 10000,
"received": true,
"prove": false,
"order": "asc"
}' | jq '.txs | first, last | [.hash, .height]'

# example
#   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#                                  Dload  Upload   Total   Spent    Left  Speed
#   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
# 100 12.5M    0 12.5M  100   137  1364k     14  0:00:09  0:00:09 --:--:-- 4014k
# [
#   "1F6511B8E975C9189E4592C44CA0D8039B3861BC550EE96378D29BC43CE8E552",
#   86099
# ]
# [
#   "CCFB5D49009D37BFB3E472FBBD6E79791CB0B4E972765926074F521CF19A4812",
#   82654
# ]

query new version with last height

curl --request POST \
  --url http://POKT_RPC_WITH_HEIGHT_INDEX_URL/v1/query/accounttxs \
  --header 'Content-Type: application/json' \
  --data '{
  "address": "cb6ff4204f8a93e89759c22a9e0f8896f8561379",
  "page": 1,
  "per_page": 10000,
  "received": true,
  "prove": false,
  "order": "asc",
  "height": 82654
}' | jq '.txs | first, last | [.hash, .height]'

# should match old version
#   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#                                  Dload  Upload   Total   Spent    Left  Speed
# 100 12.5M    0 12.5M  100   168  10.7M    143  0:00:01  0:00:01 --:--:-- 10.7M
# [
#   "1F6511B8E975C9189E4592C44CA0D8039B3861BC550EE96378D29BC43CE8E552",
#   86099
# ]
# [
#   "CCFB5D49009D37BFB3E472FBBD6E79791CB0B4E972765926074F521CF19A4812",
#   82654
# ]

double check old version still matches

curl --request POST \
  --url https://POKT_RPC_WITH_HEIGHT_INDEX_URL/v1/query/accounttxs \
  --header 'Content-Type: application/json' \
  --data '{
  "address": "cb6ff4204f8a93e89759c22a9e0f8896f8561379",
  "page": 1,
  "per_page": 10000,
  "received": true,
  "prove": false,
  "order": "asc"
}' | jq '.txs | first, last | [.hash, .height]'

# should match old version
# [
#   "1F6511B8E975C9189E4592C44CA0D8039B3861BC550EE96378D29BC43CE8E552",
#   86099
# ]
# [
#   "CCFB5D49009D37BFB3E472FBBD6E79791CB0B4E972765926074F521CF19A4812",
#   82654
# ]
reviewpad[bot] commented 1 year ago

Thank you @0xBigBoss for this first contribution!

cr-gpt[bot] commented 1 year ago

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables for this repo. you could follow readme for more information

reviewpad[bot] commented 1 year ago

AI-Generated Pull Request Summary: This pull request contains 2 commits that introduce the use of block height in the query account transactions command. It adds functionality to search for account transactions with a specific height, useful for filtering transactions. Additionally, this PR includes some context to clarify the behavior of the height parameter when equal to 0.

reviewpad[bot] commented 1 year ago

AI-Generated Pull Request Summary: This pull request contains a series of 3 patches:

  1. The first patch modifies the QueryAccountTxs function to include the block height as an optional parameter in CLI and RPC queries. It also adds tests to ensure proper functionality when querying account transactions by height.

  2. The second patch adds a comment in the app/cmd/cli/query.go file to provide context for the height parameter's default value of 0. This value is ignored during the query and implies the latest height available.

  3. The third patch clarifies the casting of block heights as integers when querying using the tx height index due to the lexicographic encoder library used in the types/indexer.go file. This is safe because v0 block height should never exceed 2^63-1 on 64-bit systems or 2^31-1 on 32-bit systems.

Overall, these patches improve the functionality and maintainability of the codebase.