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

minor: Use height in query account txs #1525

Conversation

0xBigBoss
Copy link
Contributor

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
# ]

@0xBigBoss 0xBigBoss force-pushed the 0xbigboss/feat/use-accounttx-height-index branch from 6bc10fb to 64de1dd Compare February 18, 2023 22:01
@0xBigBoss 0xBigBoss force-pushed the 0xbigboss/feat/use-accounttx-height-index branch from 64de1dd to 61a7135 Compare February 18, 2023 22:08
@Olshansk Olshansk self-requested a review February 20, 2023 04:21
@reviewpad
Copy link

reviewpad bot commented Apr 4, 2023

Thank you @0xBigBoss for this first contribution!

@reviewpad reviewpad bot added medium Pull request is medium waiting-for-review labels Apr 4, 2023
@Olshansk Olshansk added this to the Network Quality of Life milestone Apr 5, 2023
Olshansk
Olshansk previously approved these changes Apr 5, 2023
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment and question but no blockers on my end. Massive improvement!

app/cmd/cli/query.go Outdated Show resolved Hide resolved
types/indexer.go Outdated
return []byte(fmt.Sprintf("%s/%s/%s",
TxSignerKey,
signer,
elenEncoder.EncodeInt(int(height)), // totally safe right?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// totally safe right? -> Do you think we'll hit an overflow issue or something? If so, we can just force the user to pass an int into this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh i think this was more of a joke to myself, I don't think we will be still babysitting v0 after 2^63-1 (or 2^31-1 on 32bit systems) blocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Member

@Olshansk Olshansk Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the joke with a real comment (so future readers aren't confused as much as I do appreciate it), but otherwise lgtm

@@ -200,19 +211,33 @@ func (t *TransactionIndexer) heightQuery(condition query.Condition, pagination *
return t.getByPrefix(prefixKeyForHeight(height), pagination)
}

func (t *TransactionIndexer) signerQuery(condition query.Condition, pagination *query.Page) (res []*types.TxResult, total int, err error) {
signer, err := hex.DecodeString(condition.Operand.(string))
func (t *TransactionIndexer) signerQuery(primaryCondition query.Condition, secondaryCondition query.Condition, pagination *query.Page) (res []*types.TxResult, total int, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not actionable: I don't think we'll need any more features here, otherwise I would've suggested variadic params (for v1 stuff).

@reviewpad reviewpad bot requested a review from luyzdeleon April 5, 2023 03:36
@cr-gpt
Copy link

cr-gpt bot commented Apr 5, 2023

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
Copy link

reviewpad bot commented Apr 5, 2023

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
Copy link

reviewpad bot commented Apr 6, 2023

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.

@0xBigBoss 0xBigBoss requested a review from Olshansk April 6, 2023 01:01
@Olshansk Olshansk removed the request for review from luyzdeleon April 6, 2023 21:20
// Transaction(tx) Block height index key.
//
// Note: Block height is cast as int when querying using the tx height index due to the lexicographic encoder library,
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT (not actually): Block height should never exceed 2^31-1 on any 32+ bit system ;)

@0xBigBoss 0xBigBoss merged commit fc19062 into pokt-network:staging Apr 7, 2023
@0xBigBoss 0xBigBoss deleted the 0xbigboss/feat/use-accounttx-height-index branch April 7, 2023 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium Pull request is medium waiting-for-review
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants