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

Q: How to fetch generated blocks from a given provisioner? #3328

Open
BoboTiG opened this issue Jan 8, 2025 · 4 comments
Open

Q: How to fetch generated blocks from a given provisioner? #3328

BoboTiG opened this issue Jan 8, 2025 · 4 comments

Comments

@BoboTiG
Copy link

BoboTiG commented Jan 8, 2025

Summary

I would like to use an efficient GraphQL query to fetch generated blocks from a given provisioner.

The current way I'm doing it is to fetch all blocks, and then filter on the block.header.generatorBlsPubkey value. It is almost OK today because there are not millions of created blocks; but it will become a problem soon enough.

Detailed Description

Here is the current "broad" query:

provisioner='PUBLIC_KEY'
curl 'http://127.0.0.1:8080/02/Chain' \
  --data-raw '{"topic": "gql", "data":"fragment BlockInfo on Block { header { height, generatorBlsPubkey } } query() { blocks(last: 10000) {...BlockInfo} }"}' | \
     jq ".[] | map(select(.header.generatorBlsPubkey == \"${provisioner}\"))"

Now, my question is: can this kind of modified query work? Maybe it's something that could be acheive already but I did not find the correct query:

curl 'http://127.0.0.1:8080/02/Chain' \
  -H 'Rusk-gqlvar-prov: PUBLIC_KEY' \
  --data-raw '{"topic": "gql", "data":"fragment BlockInfo on Block { header { height, generatorBlsPubkey } } query($prov: String!) { blocks(generatorBlsPubkey: $prov) {...BlockInfo} }"}'

This results in this error:

[{"locations":[{"column":102,"line":1}],"message":"Unknown argument \"generatorBlsPubkey\" on field \"blocks\" of type \"Query\"."}]
@sanderdms
Copy link

sanderdms commented Jan 8, 2025

I currently ingest all data into a relational database and query it from there. I understand this doesn't directly answer your question, but could you share more about your use case? Depending on your needs, I might be able to work on providing trusted aggregation API endpoints or webhooks. -- Also can you specify what would be the required update frequency and how critical is API uptime for your case ?

@BoboTiG
Copy link
Author

BoboTiG commented Jan 8, 2025

I am tracking my nodes rewards, so every hour or so I call a cronjob to fetch the number of generated blocks using the code shared in the description.
Thank you for your idea, but I would not like to use a third-party service. A normal GQL request would be so much better.

The current code works and will work for quite some time, but it is very inefficient for both the node, the ingestion script, the bandwith, etc.

@BoboTiG
Copy link
Author

BoboTiG commented Jan 8, 2025

I went the other way finally: listening to the blockchain for accepted blocks events (using RUES).

@BoboTiG BoboTiG closed this as completed Jan 8, 2025
@BoboTiG
Copy link
Author

BoboTiG commented Jan 21, 2025

Update: I implemented pagined fetches in order to be able to get data from the genesis, see BoboTiG/dusk-monitor@0ca521b.

I am reopening the issue since having a way to filter blocks at the core level would be the best efficient.

Team, is it something that is already in your backlog? Is it something wanted?
I can give a hand, trying something given my rust skills (near to zero, but I already read a good part of the code, and I could hack something ugly haha). If you are OK, I could open a PR.

@BoboTiG BoboTiG reopened this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants