EmerisHQ / demeris-backend

Monorepo containing all the Demeris backend code and infrastructure definitions.
GNU Affero General Public License v3.0
8 stars 1 forks source link

API returns staking balance without considering slashing #726

Closed Pitasi closed 2 years ago

Pitasi commented 2 years ago

Tracelistener writes the shares amount into the db. api-server returns that amount as-is.

The problem is that shares and the actual staked amount are two separates concepts as exaplained here: https://allinbits.slack.com/archives/CQBCG2DT7/p1650967174081609?thread_ts=1650965509.245189&cid=CQBCG2DT7.

To summarize what we need to return instead of shares is:

shares / total_validator_shares * total_validator_balance

DoD:

Pitasi commented 2 years ago

The database already contains all the informations we need so I suggest we do this in the api-server before returning results.

Main blocker I see is that in database we store the validator address in the form sifvaloper1lnhxf6war6qlldemkqzp0t3g57hpe9a6nh3tyv while in the delegations tables we have the validator_address column in the form fcee64e9dd1e81ffb73bb00417ae28a7ae1c97ba.

If we want to do things properly I suggest we add a new column to validators to additionally store the bech32 decoded address. After we do this, we can calculate the staking balance in a single db query joining the tables.