Skip to content

Commit bf9c342

Browse files
authored
Merge pull request IntersectMBO#1203 from input-output-hk/erikd/misc
Consolidate a number of individual PRs
2 parents f7c22d0 + 4612d11 commit bf9c342

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ possible solutions.
7272

7373
* [BuildingRunning][BuildingRunning]: Building and running the db-sync node.
7474
* [Docker][Docker]: Instruction for docker-compose, and building the images using nix.
75+
* [ERD][ERD]: The entity relationship diagram.
7576
* [Example SQL queries][ExampleQueries]: Some example SQL and Haskell/Esqueleto queries.
7677
* [PoolOfflineData][PoolOfflineData]: Explanation of how stake pool offline data is retried.
7778
* [Schema Documentation][Schema Documentation]: The database schema documentation.
@@ -83,6 +84,7 @@ possible solutions.
8384
[BuildingRunning]: doc/building-running.md
8485
[DB Schema]: https://hydra.iohk.io/job/Cardano/cardano-db-sync/native.haskellPackages.cardano-db.checks.test-db.x86_64-linux/latest/download/1
8586
[Docker]: doc/docker.md
87+
[ERD]: doc/ERG>png
8688
[ExampleQueries]: doc/interesting-queries.md
8789
[PostgresView]: https://www.postgresql.org/docs/current/sql-createview.html
8890
[PoolOfflineData]: doc/pool-offline-data.md

cardano-db-sync/app/cardano-db-sync.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pLedgerStateDir :: Parser LedgerStateDir
8080
pLedgerStateDir =
8181
LedgerStateDir <$> Opt.strOption
8282
( Opt.long "state-dir"
83-
<> Opt.help "The directory for persistung ledger state."
83+
<> Opt.help "The directory for persisting ledger state."
8484
<> Opt.completer (Opt.bashCompleter "directory")
8585
<> Opt.metavar "FILEPATH"
8686
)

cardano-db-tool/app/cardano-db-tool.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pLedgerStateDir :: Parser LedgerStateDir
188188
pLedgerStateDir =
189189
LedgerStateDir <$> Opt.strOption
190190
( Opt.long "state-dir"
191-
<> Opt.help "The directory for persistung ledger state."
191+
<> Opt.help "The directory for persisting ledger state."
192192
<> Opt.completer (Opt.bashCompleter "directory")
193193
<> Opt.metavar "FILEPATH"
194194
)

doc/ERD.png

1.79 MB
Loading

doc/interesting-queries.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,69 @@ select redeemer.tx_id as tx_id, redeemer.unit_mem, redeemer.unit_steps, redeemer
546546
asset1mu7h997yyvzrppdwjzhpex6u7khrucspxvjjuw | \x69b30e43bc5401bb34d0b12bd06cd9b537f33065aa49df7e8652739d | \x4c51 | 2 | 1 | 21000000000000 | 2021-02-03 20:22:23
547547

548548
```
549+
550+
### Get blocks with 0 transactions and the pools that forged it
551+
```sql
552+
select distinct on(block.hash) block.hash as block_hash , epoch_no, tx_count, pool_hash.hash_raw as pool_hash,
553+
pool_update.pledge, pool_update.active_epoch_no, pool_metadata_ref.url, pool_offline_data.ticker_name
554+
from block join slot_leader on block.slot_leader_id = slot_leader.id
555+
join pool_hash on slot_leader.pool_hash_id = pool_hash.id
556+
join pool_update on pool_update.hash_id = pool_hash.id
557+
left join pool_metadata_ref on pool_update.meta_id = pool_metadata_ref.id
558+
left join pool_offline_data on pool_offline_data.pmr_id = pool_metadata_ref.id
559+
where tx_count = 0 and epoch_no > 150
560+
order by block.hash, pool_update.active_epoch_no desc;
561+
562+
563+
block_hash | epoch_no | tx_count | pool_hash | pledge | active_epoch_no | url | ticker_name
564+
--------------------------------------------------------------------+----------+----------+------------------------------------------------------------+-----------------+-----------------+------------------------------------------------------------------+-------------
565+
\x0000f4b44d1484d7280f087c1df94f068a02e23570e8ed9eb5c0dd980d4c46c1 | 165 | 0 | \xe402f5894b8a7073f198bb0710d6294f2ac354ede2577b5ce15159a4 | 50000000000 | 137 | https://www.canadastakes.ca/metadata/can1-testnet-metadata.json |
566+
\x0001715520d185accd550c7b6c0811a2589e778e6408ffcd75b0f83f4f45c2c0 | 153 | 0 | \xacfd479740bde8289885694e69e3494f7dcbcfdca540aead48c5d653 | 64000000000000 | 100 | |
567+
\x00044646beb7d24dce8cd74408c76b9816453a451fc030c42cc9961be55932d9 | 163 | 0 | \x1e2191487bed3de4bf440d5ff80bdae31d7f22798d3a93444302acb3 | 64000000000000 | 100 | |
568+
\x000732a2f62e289930c2779559a975566395dcf0cf32130f3852a6e031d13d61 | 154 | 0 | \xd9dc497e633c2f1c665467e1ed7a93e4f8541bfbabe1cc31818fb20f | 1000000000000 | 131 | https://www.uniquestaking.com/pool/uniq9/1ecf39ad-4f3c-4043 |
569+
```
549570
---
550571

572+
### Query all delegators and some basic info
573+
```sql
574+
SELECT sa.view AS address,
575+
nh.view AS delegated_now_poolid,
576+
d.active_epoch_no delegated_now_epoch,
577+
oh.view AS delegated_before_poolid,
578+
od.active_epoch_no AS delegated_before_epoch,
579+
d.addr_id,
580+
br."time" AS stake_key_registered
581+
FROM ( SELECT max(delegation.id) AS id
582+
FROM delegation
583+
GROUP BY delegation.addr_id) a
584+
LEFT JOIN delegation d ON d.id = a.id
585+
LEFT JOIN tx txn ON txn.id = d.tx_id
586+
LEFT JOIN block bn ON bn.id = txn.block_id
587+
LEFT JOIN stake_address sa ON sa.id = d.addr_id
588+
LEFT JOIN stake_deregistration de ON de.addr_id = d.addr_id AND de.id = (( SELECT max(stake_deregistration.id) AS max
589+
FROM stake_deregistration
590+
WHERE stake_deregistration.addr_id = d.addr_id))
591+
LEFT JOIN stake_registration re ON re.addr_id = d.addr_id AND re.id = (( SELECT max(stake_registration.id) AS max
592+
FROM stake_registration
593+
WHERE stake_registration.addr_id = d.addr_id))
594+
LEFT JOIN delegation od ON od.addr_id = d.addr_id AND od.id = (( SELECT max(delegation.id) AS max
595+
FROM delegation
596+
WHERE delegation.addr_id = d.addr_id AND NOT delegation.pool_hash_id = d.pool_hash_id))
597+
LEFT JOIN tx txo ON txo.id = od.tx_id
598+
LEFT JOIN block bo ON bo.id = txo.block_id
599+
LEFT JOIN pool_hash nh ON nh.id = d.pool_hash_id
600+
LEFT JOIN pool_hash oh ON oh.id = od.pool_hash_id
601+
LEFT JOIN tx txr ON txr.id = re.tx_id
602+
LEFT JOIN block br ON br.id = txr.block_id
603+
WHERE (de.tx_id < re.tx_id OR de.* IS NULL);
604+
605+
606+
address | delegated_now_poolid | delegated_now_epoch | delegated_before_poolid | delegated_before_epoch | addr_id | stake_key_registered
607+
-------------------------------------------------------------+----------------------------------------------------------+---------------------+----------------------------------------------------------+------------------------+---------+----------------------
608+
stake1u9ylzsgxaa6xctf4juup682ar3juj85n8tx3hthnljg47zctvm3rc | pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy | 210 | | | 1 | 2020-07-29 22:41:31
609+
stake1u8mt5gqclkq0swmvzx9lvq4jgwsnx9yh030yrxwqwllu0mq2m0l4n | pool1qqqqzyqf8mlm70883zht60n4q6uqxg4a8x266sewv8ad2grkztl | 317 | pool1qqqz9vlskay2gv3ec5pyck8c2tq9ty7dpfm60x8shvapguhcemt | 211 | 3 | 2020-08-06 20:00:11
610+
```
611+
---
612+
613+
551614
[Query.hs]: https://github.com/input-output-hk/cardano-db-sync/blob/master/cardano-db/src/Cardano/Db/Query.hs

0 commit comments

Comments
 (0)