Skip to content

Commit 7cd25fc

Browse files
authored
Merge pull request #17962 from MinaProtocol/dkijania/handle_forks_in_missing_bl_auditor
Handling archive from network which were derived from fork
2 parents 432937a + 63e44f8 commit 7cd25fc

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

changes/17962.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Altering mina-missing-block-auditor app.
2+
3+
Correctly handling network derived from devnet/mainnet, but without pre-hardfork blocks

src/app/missing_blocks_auditor/missing_blocks_auditor.ml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,25 @@ let main ~archive_uri () =
4242
~metadata:[ ("error", `String (Caqti_error.show msg)) ] ;
4343
exit 1
4444
in
45-
(* filter out genesis block *)
45+
(* filters out genesis or first fork block. This is needed as they are not considered missing and
46+
archive blocks can start from block with height > 1 in case of sandbox network forked from devnet/mainnet.
47+
Archive of such network won't include genesis block but fork block as a first block *)
48+
let%bind genesis_or_fork_block_height =
49+
match%bind
50+
Mina_caqti.Pool.use
51+
(fun db -> Sql.GenesisOrFirstForkBlockHeight.run db ())
52+
pool
53+
with
54+
| Ok height ->
55+
return height
56+
| Error msg ->
57+
[%log error] "Error getting genesis or first fork block height"
58+
~metadata:[ ("error", `String (Caqti_error.show msg)) ] ;
59+
exit 1
60+
in
4661
let missing_blocks =
47-
List.filter missing_blocks_raw ~f:(fun (_, _, height, _) -> height <> 1)
62+
List.filter missing_blocks_raw ~f:(fun (_, _, height, _) ->
63+
height <> genesis_or_fork_block_height )
4864
in
4965
let%bind () =
5066
if List.is_empty missing_blocks then
@@ -134,8 +150,14 @@ let main ~archive_uri () =
134150
[%log info] "Length of canonical chain is %Ld blocks" chain_len
135151
else (
136152
add_error chain_length_error ;
137-
[%log info] "Length of canonical chain is %Ld blocks, expected: %Ld"
138-
chain_len highest_canonical ) ;
153+
if genesis_or_fork_block_height = 1 then
154+
[%log info] "Length of canonical chain is %Ld blocks, expected: %Ld"
155+
chain_len highest_canonical
156+
else
157+
[%log info]
158+
"Length of canonical chain is %Ld blocks, expected: %Ld. (Note: \
159+
genesis or first fork block has height %d)"
160+
chain_len highest_canonical genesis_or_fork_block_height ) ;
139161
let invalid_chain =
140162
List.filter canonical_chain
141163
~f:(fun (_block_id, _state_hash, chain_status) ->

src/app/missing_blocks_auditor/sql.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ module Unparented_blocks = struct
1414
let run (module Conn : Mina_caqti.CONNECTION) () = Conn.collect_list query ()
1515
end
1616

17+
module GenesisOrFirstForkBlockHeight = struct
18+
let query =
19+
Mina_caqti.find_req Caqti_type.unit Caqti_type.int
20+
{sql| SELECT height FROM blocks
21+
WHERE parent_id IS NULL
22+
AND global_slot_since_hard_fork = 0
23+
AND chain_status = 'canonical'
24+
ORDER BY height ASC
25+
LIMIT 1
26+
|sql}
27+
28+
let run (module Conn : Mina_caqti.CONNECTION) height = Conn.find query height
29+
end
30+
1731
module Missing_blocks_gap = struct
1832
let query =
1933
Mina_caqti.find_req Caqti_type.int Caqti_type.int

0 commit comments

Comments
 (0)