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
multi: new treasury #1824
multi: new treasury #1824
Conversation
db/dcrpg/internal/treasury.go
Outdated
SelectTreasuryBalance = `SELECT | ||
COUNT(CASE WHEN tx_type=4 THEN 1 END) as tadds, | ||
SUM(CASE WHEN tx_type=4 THEN value ELSE 0 END) AS spent, | ||
COUNT(CASE WHEN tx_type=5 THEN 1 END) as tspends, | ||
SUM(CASE WHEN tx_type=5 THEN -value ELSE 0 END) AS spent, | ||
COUNT(CASE WHEN tx_type=6 THEN 1 END) as tbases, | ||
SUM(CASE WHEN tx_type=6 THEN value ELSE 0 END) AS spent | ||
FROM treasury | ||
WHERE is_mainchain AND block_height <= $1;` |
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.
I think I might have gone with a GROUP BY (tx_type)
for this, but yours does make the scan easier I think, and the cost is really not bad, so I like yours.
For ref
# SELECT tx_type, count(*), sum(value) FROM treasury WHERE is_mainchain AND block_height <= $1 GROUP BY tx_type;
tx_type | count | sum
---------+--------+---------------
6 | 118285 | 1486404783273
5 | 1 | -100002550
4 | 1 | 5000000000
(3 rows)
^ requires scanning N rows, and adjusting sign of tspends.
# SELECT
COUNT(CASE WHEN tx_type=4 THEN 1 END) as tadds,
SUM(CASE WHEN tx_type=4 THEN value ELSE 0 END) AS spent,
COUNT(CASE WHEN tx_type=5 THEN 1 END) as tspends,
SUM(CASE WHEN tx_type=5 THEN -value ELSE 0 END) AS spent,
COUNT(CASE WHEN tx_type=6 THEN 1 END) as tbases,
SUM(CASE WHEN tx_type=6 THEN value ELSE 0 END) AS spent
FROM treasury
WHERE is_mainchain AND block_height <= 700000;
tadds | spent | tspends | spent | tbases | spent
-------+------------+---------+-----------+--------+---------------
1 | 5000000000 | 1 | 100002550 | 118285 | 1486404783273
(1 row)
Time: 32.017 ms
^ one row scan, fixed type positions, and no sign adjustment
Both have <1ms execution time and comparable planner costs (7092.52 for CASE
s and 5326.68 for GROUP BY
s, both quite small).
Just making a note of this in case we want to revisit it later.
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.
Where I'm at right now is
SelectTreasuryBalance = `SELECT
tx_type,
COUNT(CASE WHEN block_height <= $1 THEN 1 END),
COUNT(CASE WHEN block_height > $1 THEN 1 END),
SUM(CASE WHEN block_height <= $1 THEN value ELSE 0 END),
SUM(CASE WHEN block_height > $1 THEN value ELSE 0 END)
FROM treasury
WHERE is_mainchain
GROUP BY tx_type;`
Though looking at this now, I'm wondering if it would be faster to do
COUNT(CASE WHEN block_height <= $1 THEN 1 END),
COUNT(1),
SUM(CASE WHEN block_height <= $1 THEN value ELSE 0 END),
SUM(value)
and then take the difference in the caller.
Getting a bunch of divide by zeros with http://127.0.0.1:7777/treasury?n=0&start=0&txntype=tspend
I get that on mainnet where there are no treasury txnsn yet by changing the Type on the page, so it seems it just needs to replace 0 by something else |
I'm now wondering if when there are no tspends yet, as on mainnet, it should show All. |
I've changed it to |
Looking to get this in, since I didn't backup my old database. Lemme know when, and I'll squash my commits. |
This is good now IMO. How's the txns counts over the pagination now? I haven't rechecked that with latest commits? |
Seems to be a bug there still, but less noticeable now since there are more pages. Lemme see if I can chase it down. Almost like the tx count is being double somewhere. |
Right, I think it was exactly doubled when there were only immature, and now it changed up, so I think it's got something to do with immature count. |
0cd5038 fixes pagination. I'm gonna squash though. |
Begin the treasury page. Add db queries for treasury page. Add links to legacy treasury. Add TreasuryBalance to pageData.HomeInfo, update in Store. Home page treasury balance is sum of legacy and decentralized. Decode TSpend vote choices. Presenly only accessible via API VoteChoices for a transaction. Label old treasury address as *legacy*
Get pagination and typed txs working for the treasury page. Hide the chart for now. Will follow up with caches and charts. Default to 'all' treasury txn types while there are no tadds or tspends on mainnet yet. Display immature treasury balance. Add i/o chart. Add fiat conversion.
@chappjc's #1821 plus some work on pagination. This is just a minimal implementation so we definitely have something that works for tonight. Work on charts and caches will follow, but can also be moved to separate PRs. I'd like to maybe get at least one chart up before tonight though. We'll see. Running out of time.