-
-
Save SmaugPool/892f5bc18bf5c6e52245e1b7bd0bed84 to your computer and use it in GitHub Desktop.
WITH stake AS | |
(SELECT d1.addr_id | |
FROM delegation d1, pool_hash | |
WHERE pool_hash.id=d1.pool_hash_id | |
AND pool_hash.hash_raw='\xabacadaba9f12a8b5382fc370e4e7e69421fb59831bb4ecca3a11d9b' | |
AND NOT EXISTS | |
(SELECT TRUE | |
FROM delegation d2 | |
WHERE d2.addr_id=d1.addr_id | |
AND d2.tx_id>d1.tx_id) | |
AND NOT EXISTS | |
(SELECT TRUE | |
FROM stake_deregistration | |
WHERE stake_deregistration.addr_id=d1.addr_id | |
AND stake_deregistration.tx_id>d1.tx_id)) | |
SELECT sum(total) | |
FROM | |
(SELECT sum(value) total | |
FROM utxo_view | |
INNER JOIN stake ON utxo_view.stake_address_id=stake.addr_id | |
UNION SELECT sum(amount) | |
FROM reward | |
INNER JOIN stake ON reward.addr_id=stake.addr_id | |
WHERE reward.spendable_epoch <= (SELECT MAX(epoch_no) FROM block) | |
UNION SELECT -sum(amount) | |
FROM withdrawal | |
INNER JOIN stake ON withdrawal.addr_id=stake.addr_id | |
) AS t; |
my mistake...It should be
earned_epoch < current_epoch
. We know that if I have reward at epochT
, it will show up on my wallet at epochT + 2
. So the question is that reward at epoch T will be count in total delegate from epochT+1
orT+2
?
If result isT+2
, we are wasting millions ADA to advance PoS protocol for epochT+1
(15.38m reward distributed in Epoch 290). My formula is correct withepoch_stake.amount
indb-sync
.
A pool live stake is generally considered as the sum of all wallets balances as currently seen by their users. If you use earned_epoch < current_epoch
at epoch n, again, before the end of the epoch you will get new rows included for the rewards earned epoch n-1 and being calculated progressively during the epoch but not yet spendable (they will be spendable epoch n+1).
This would be a different definition of a pool live stake and it would include before the end of epochs some rewards that no one has in their wallet yet. You could use earned_epoch < current_epoch - 1
, but then it's exactly the same as spendable_epoch <= current_epoch
as used in the current query.
my mistake...It should be
earned_epoch < current_epoch
. We know that if I have reward at epochT
, it will show up on my wallet at epochT + 2
. So the question is that reward at epoch T will be count in total delegate from epochT+1
orT+2
?If result is
T+2
, we are wasting millions ADA to advance PoS protocol for epochT+1
(15.38m reward distributed in Epoch 290). My formula is correct withepoch_stake.amount
indb-sync
.