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

externalDelegatedBalance discrepancy with delegator list #176

Closed
nicolasochem opened this issue Jul 31, 2024 · 3 comments
Closed

externalDelegatedBalance discrepancy with delegator list #176

nicolasochem opened this issue Jul 31, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@nicolasochem
Copy link

Hi,

I am having a baker fail a TRD invariant.

Specifically, the sum of delegatedBalance for all delegators does not match externalDelegatedBalance.

You can see for yourself with jq:

$ curl -s 'https://api.tzkt.io/v1/rewards/split/tz1MbhmEwEAzzfb3naSr7vTp4mDxB8HsknA9/760?offset=0&limit=10000' | jq '         
{
  externalDelegatedBalance: .externalDelegatedBalance,
  sumOfAllDelegatorBalances: ( .delegators | map(.delegatedBalance) | add )
}
' 
{
  "externalDelegatedBalance": 134799604249,
  "sumOfAllDelegatorBalances": 134791833489
}

This started happening during cycle 760. Cycle 759 and prior were fine:

$ curl -s 'https://api.tzkt.io/v1/rewards/split/tz1MbhmEwEAzzfb3naSr7vTp4mDxB8HsknA9/759?offset=0&limit=10000' | jq '
{
  externalDelegatedBalance: .externalDelegatedBalance,
  sumOfAllDelegatorBalances: ( .delegators | map(.delegatedBalance) | add )
}
' 
{
  "externalDelegatedBalance": 134632713172,
  "sumOfAllDelegatorBalances": 134632713172
}
@nicolasochem
Copy link
Author

Since there is a discrepancy of 8 tez, I am inclined to think it's about this delegator which has a finalizable balance with this baker.

@nicolasochem
Copy link
Author

So it looks like in order to reconcile these 2 values I have to query the following:

$ curl 'https://api.tzkt.io/v1/staking/unstake_requests?baker=tz1MbhmEwEAzzfb3naSr7vTp4mDxB8HsknA9&status-=finaliz
able'  | jq

And then filter out the baker's own finalizable amounts.

The remaining entries are pending finalize unstake, for which the delegation rewards accrue and should be paid. Could you please confirm?

@Groxan
Copy link
Member

Groxan commented Aug 1, 2024

That's a bug :(

The account tz1QM7QAKgjuZvSVqTU4VYfmvWbAxBBFQRka with unstaked balance 7770760 didn't get into snapshot and therefore was missed in the delegators list in the rewards split.

The bug happened because the account cancelled delegation and the SQL query WHERE account."UnstakedBakerId" != account."DelegateId" was broken, because in Postgres not_null != null returns null instead of true.

Thank you very much for spotting! We will fix it ASAP.

@Groxan Groxan added the bug Something isn't working label Aug 1, 2024
@Groxan Groxan closed this as completed in 6d197a5 Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants