IntersectMBO / cardano-db-sync

A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL
Apache License 2.0
283 stars 158 forks source link

Withdrawals > Rewards for stake1uy8em3f3v7veagycqrcw69q4jggvrtwze6ve4rvtaz9j3rsxkpflt #1745

Closed SmaugPool closed 6 days ago

SmaugPool commented 1 week ago

OS Ubuntu 22.04

Versions The db-sync version (eg cardano-db-sync --version): 13.2.0.2 PostgreSQL version: 14.12

Build/Install Method Installed cardano-db-sync-13.2.0.2-linux.tar.gz binary assets.

Run method systemd

Additional context Fresh restore from db-sync-snapshot-schema-13.2-block-10484700-x86_64.tgz snapshot.

Problem Report stake1uy8em3f3v7veagycqrcw69q4jggvrtwze6ve4rvtaz9j3rsxkpflt (stake_address.id=7209) total withdrawal amount is greater than total reward amount.

cardano=> select (select sum(amount) from reward where addr_id=7209) - (select sum(amount) from withdrawal where addr_id=7209);

----------
 -1697525
(1 row)

This seems unexpected to me but maybe I'm missing something.

kderme commented 1 week ago

The rewards that are not related to a specific pool (MIR and proposal refunds for Conway) have been moved to the reward_rest table. The motivation for this was that having a nullable pool_id was problematic.

select sum(amount) from reward_rest where addr_id=7209;
   sum   
---------
 1697525

select * from reward_rest where addr_id=7209;
 addr_id |   type   | amount | spendable_epoch | earned_epoch 
---------+----------+--------+-----------------+--------------
    7209 | treasury | 474020 |             279 |          278
    7209 | reserves | 108736 |             286 |          285
    7209 | treasury | 354140 |             299 |          298
    7209 | treasury | 760629 |             301 |          300
kderme commented 1 week ago

Actually instead of reward_rest, it's called instant_reward in 13.2.0.2. It was later renamed to reward_rest to include the treasury withdrawals and proposal refunds for Conway

SmaugPool commented 6 days ago

Thank you! This explains it all:

> select (select sum(amount) from reward where addr_id=7209) + (select sum(amount) from instant_reward where addr_id=7209) - (select sum(amount) from withdrawal where addr_id=7209);

----------
        0
(1 row)

And sorry to have missed that change.