-
Notifications
You must be signed in to change notification settings - Fork 50
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
fix: tzkt api may return more delegators than numDelegators #707
fix: tzkt api may return more delegators than numDelegators #707
Conversation
thanks @TPXP , can you clarify what happens when tzkt returns more delegators than numDelegators? Who are the extra delegators in this case? Are they duplicates? what's happening with the payouts? Is the program crashing? |
Hello @nicolasochem , thanks for the reply. When TzKT replies more delegators, the
I couldn't find any duplicates in the example I'm giving - maybe a few weird addresses but that's all. It seems that $ wget https://api.tzkt.io/v1/rewards/split/tz3LV9aGKHDnAZHCtC9SjNtTrKRu678FqSki/751\?offset\=0\&limit\=10000 -O rewards.json
$ jq '.numDelegators' ./rewards.json
3224
$ jq '.delegators[].address' ./rewards.json | sort | uniq | wc -l
3225
$ jq '.delegators[].address' ./rewards.json | sort | less
"KT1JBkpjozcKXWpHJLVhU67ZpXFhzH9Hekzg"
"tz1KeBQPzzGA7rBDcUY7biCKEKTSnxX291Hm"
...
"tz1iyXtwz3bKa6r8KEh6CnQU6CayU4msz4zj"
"tz2VJ6pJnnb9rYHFSQzUiZHX1M3uGnvGu4pz"
# Maybe 0 balances? (No)
$ jq '.delegators[].delegatedBalance' ./rewards.json | sort -h | less
154
[...]
6025854993128 |
@Groxan can you please check on your end why this would be happening? |
That indeed may happen, when an account re-delegates to another baker, but still has unstake requests with the previous baker. I.e. the account has delegated balance with two different bakers at the same time, but counted as delegator only with the actual one. In other words, |
The best way to check for end of data is |
888e4a2
to
055f6db
Compare
Thanks for confirming @Groxan , I've updated the PR to fetch pages until we get less delegators than |
See tz3LV9aGKHDnAZHCtC9SjNtTrKRu678FqSki at cycle 751 for an example https://api.tzkt.io/v1/rewards/split/tz3LV9aGKHDnAZHCtC9SjNtTrKRu678FqSki/751?offset=0&limit=10000
055f6db
to
e3dd95b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me - works fine in my bakery
thanks everyone |
ab8f87a
into
tezos-reward-distributor-organization:master
name: fix: tzkt api may return more delegators than numDelegators
about: Create a pull request to make a contribution
labels: bugfix, tzkt_api
This PR resolves the issue . The following steps were performed:
Analysis: TZTK seems to return more delegators than
numDelegators
in some cases on therewards/split
endpoint. Handle this gracefully and move on. Seetz3LV9aGKHDnAZHCtC9SjNtTrKRu678FqSki
at cycle 751 for an example: https://api.tzkt.io/v1/rewards/split/tz3LV9aGKHDnAZHCtC9SjNtTrKRu678FqSki/751?offset=0&limit=10000Solution: Update the length condition to stop if we fetched at least as much delegators as
numDelegators
. Also, add another safeguard by stopping the loop if we're not fetching any more validators (indicating we've reached the end of the list) - this way we will stop if TzKT returns less validators thannumDelegators
.Implementation: Rough description/explanation of the implementation choices.
Performed tests: Run TRD for baker
tz3LV9aGKHDnAZHCtC9SjNtTrKRu678FqSki
for cycle 751, confirm it worksDocumentation: N/A
Check list:
Work effort: 2 hours
Possibly fixes #616