• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 767

04 Nov 2025 01:59PM UTC coverage: 32.374% (-4.5%) from 36.902%
767

push

buildkite

web-flow
Merge pull request #18063 from MinaProtocol/lyh/compat-into-dev-nov4-2025

Merge compatible into develop Nov. 4th 2025

87 of 228 new or added lines in 10 files covered. (38.16%)

3416 existing lines in 136 files now uncovered.

23591 of 72871 relevant lines covered (32.37%)

26590.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.44
/src/app/archive_hardfork_toolbox/sql.ml
1
open Core
2
open Caqti_request.Infix
3

4
module type CONNECTION = Mina_caqti.CONNECTION
5

6
let latest_state_hash_query =
7
  Caqti_type.(unit ->! string)
4✔
8
    {sql|
9
          SELECT state_hash from blocks order by height desc limit 1;
10
        |sql}
11

12
let latest_state_hash (module Conn : CONNECTION) =
13
  Conn.find latest_state_hash_query ()
1✔
14

15
let chain_of_query =
16
  {sql|
17
    WITH RECURSIVE chain AS (
18
        SELECT
19
            b.id AS id,
20
            b.parent_id AS parent_id,
21
            b.state_hash AS state_hash,
22
            b.height AS height,
23
            b.global_slot_since_genesis AS global_slot_since_genesis
24
        FROM blocks b
25
        WHERE b.state_hash = ?
26

27
        UNION ALL
28

29
        SELECT
30
            p.id,
31
            p.parent_id,
32
            p.state_hash,
33
            p.height,
34
            p.global_slot_since_genesis
35
        FROM blocks p
36
        JOIN chain c ON p.id = c.parent_id
37
        WHERE p.parent_id IS NOT NULL
38
    )
39
  |sql}
40

41
let is_in_best_chain_query =
42
  Caqti_type.(t4 string string int int64 ->! bool)
4✔
43
    ( chain_of_query
44
    ^ {sql|
45
    SELECT EXISTS (
46
      SELECT 1 FROM chain
47
      WHERE state_hash = ?
48
        AND height = ?
49
        AND global_slot_since_genesis = ?
50
    );
51
    |sql}
52
    )
53

54
let is_in_best_chain (module Conn : CONNECTION) ~tip_hash ~check_hash
55
    ~check_height ~check_slot =
56
  Conn.find is_in_best_chain_query
1✔
57
    (tip_hash, check_hash, check_height, check_slot)
58

59
let num_of_confirmations_query =
60
  Caqti_type.(t2 string int ->! int)
4✔
61
    ( chain_of_query
62
    ^ {sql|
63
    SELECT count(*) FROM chain 
64
    WHERE global_slot_since_genesis >= ?;
65
    |sql}
66
    )
67

68
let num_of_confirmations (module Conn : CONNECTION) ~latest_state_hash
69
    ~fork_slot =
70
  Conn.find num_of_confirmations_query (latest_state_hash, fork_slot)
1✔
71

72
let number_of_commands_since_block_query block_commands_table =
73
  Caqti_type.(t2 string int ->! t4 string int int int)
3✔
74
    ( chain_of_query
75
    ^ Printf.sprintf
3✔
76
        {sql|
77
    SELECT 
78
        state_hash,
79
        height,
80
        global_slot_since_genesis,
81
        COUNT(bc.block_id) AS command_count
82
    FROM chain
83
    LEFT JOIN %s bc 
84
        ON chain.id = bc.block_id
85
    WHERE global_slot_since_genesis >= ?
86
    GROUP BY 
87
        state_hash,
88
        height,
89
        global_slot_since_genesis;
90
    |sql}
91
        block_commands_table )
92

93
let number_of_user_commands_since_block (module Conn : CONNECTION)
94
    ~fork_state_hash ~fork_slot =
95
  Conn.find
1✔
96
    (number_of_commands_since_block_query "blocks_user_commands")
1✔
97
    (fork_state_hash, fork_slot)
98

99
let number_of_internal_commands_since_block (module Conn : CONNECTION)
100
    ~fork_state_hash ~fork_slot =
101
  Conn.find
1✔
102
    (number_of_commands_since_block_query "blocks_internal_commands")
1✔
103
    (fork_state_hash, fork_slot)
104

105
let number_of_zkapps_commands_since_block (module Conn : CONNECTION)
106
    ~fork_state_hash ~fork_slot =
107
  Conn.find
1✔
108
    (number_of_commands_since_block_query "blocks_zkapp_commands")
1✔
109
    (fork_state_hash, fork_slot)
110

111
let last_fork_block_query =
112
  Caqti_type.(unit ->! t2 string int64)
4✔
113
    {sql|
114
    SELECT state_hash, global_slot_since_genesis FROM blocks
115
    WHERE global_slot_since_hard_fork = 0
116
    ORDER BY height DESC
117
    LIMIT 1;
118
    |sql}
119

120
let last_fork_block (module Conn : CONNECTION) =
121
  Conn.find last_fork_block_query ()
1✔
122

123
let fetch_latest_migration_history_query =
124
  Caqti_type.(unit ->? t3 string string string)
4✔
125
    {|
126
      SELECT
127
        status, protocol_version, migration_version
128
      FROM migration_history
129
      ORDER BY commit_start_at DESC
130
      LIMIT 1;
131
    |}
132

133
let fetch_latest_migration_history (module Conn : CONNECTION) =
NEW
134
  Conn.find_opt fetch_latest_migration_history_query ()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc