Skip to content

Commit 87db948

Browse files
authored
Merge pull request #11711 from MinaProtocol/feature/protocol-version-chain-id
2 parents 3277a79 + b70fe01 commit 87db948

File tree

9 files changed

+44
-9
lines changed

9 files changed

+44
-9
lines changed

src/app/cli/src/cli_entrypoint/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
block_time
6464
coda_runtime_config
6565
trust_system
66+
protocol_version
6667
coda_genesis_proof
6768
with_hash
6869
block_producer

src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ type mina_initialization =
2121
; limited_graphql_port : int option
2222
}
2323

24-
let chain_id ~constraint_system_digests ~genesis_state_hash ~genesis_constants =
24+
let chain_id ~constraint_system_digests ~genesis_state_hash ~genesis_constants
25+
~protocol_major_version =
2526
(* if this changes, also change Mina_commands.chain_id_inputs *)
2627
let genesis_state_hash = State_hash.to_base58_check genesis_state_hash in
2728
let genesis_constants_hash = Genesis_constants.hash genesis_constants in
2829
let all_snark_keys =
2930
List.map constraint_system_digests ~f:(fun (_, digest) -> Md5.to_hex digest)
3031
|> String.concat ~sep:""
3132
in
33+
let protocol_version_digest =
34+
Int.to_string protocol_major_version |> Md5.digest_string |> Md5.to_hex
35+
in
3236
let b2 =
3337
Blake2.digest_string
34-
(genesis_state_hash ^ all_snark_keys ^ genesis_constants_hash)
38+
( genesis_state_hash ^ all_snark_keys ^ genesis_constants_hash
39+
^ protocol_version_digest )
3540
in
3641
Blake2.to_hex b2
3742

@@ -1135,10 +1140,16 @@ let setup_daemon logger =
11351140

11361141
Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ;
11371142
let chain_id =
1143+
let protocol_major_version =
1144+
Protocol_version.of_string_exn
1145+
compile_time_current_protocol_version
1146+
|> Protocol_version.major
1147+
in
11381148
chain_id ~genesis_state_hash
11391149
~genesis_constants:precomputed_values.genesis_constants
11401150
~constraint_system_digests:
11411151
(Lazy.force precomputed_values.constraint_system_digests)
1152+
~protocol_major_version
11421153
in
11431154
let gossip_net_params =
11441155
Gossip_net.Libp2p.Config.

src/app/cli/src/init/client.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,11 @@ let chain_id_inputs =
20622062
~f:(fun port () ->
20632063
let open Daemon_rpcs in
20642064
match%map Client.dispatch Chain_id_inputs.rpc () port with
2065-
| Ok (genesis_state_hash, genesis_constants, snark_keys) ->
2065+
| Ok
2066+
( genesis_state_hash
2067+
, genesis_constants
2068+
, snark_keys
2069+
, protocol_major_version ) ->
20662070
let open Format in
20672071
printf "Genesis state hash: %s@."
20682072
(State_hash.to_base58_check genesis_state_hash) ;
@@ -2079,7 +2083,8 @@ let chain_id_inputs =
20792083
| None ->
20802084
"None" ) ;
20812085
printf "Snark keys:@." ;
2082-
List.iter snark_keys ~f:(printf " %s@.")
2086+
List.iter snark_keys ~f:(printf " %s@.") ;
2087+
printf "Protocol major version: %d@." protocol_major_version
20832088
| Error err ->
20842089
Format.eprintf "Could not get chain id inputs: %s@."
20852090
(Error.to_string_hum err) ) )

src/lib/daemon_rpcs/daemon_rpcs.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ end
116116
module Chain_id_inputs = struct
117117
type query = unit [@@deriving bin_io_unversioned]
118118

119-
type response = State_hash.Stable.Latest.t * Genesis_constants.t * string list
119+
type response =
120+
State_hash.Stable.Latest.t * Genesis_constants.t * string list * int
120121
[@@deriving bin_io_unversioned]
121122

122123
let rpc : (query, response) Rpc.Rpc.t =

src/lib/mina_commands/dune

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
(libraries
55
;; opam libraries
66
async_kernel
7+
base
78
core_kernel
89
core
910
async
@@ -46,8 +47,10 @@
4647
mina_ledger
4748
kimchi_backend.pasta
4849
pickles
50+
protocol_version
4951
random_oracle
5052
transition_frontier_base
5153
)
5254
(instrumentation (backend bisect_ppx))
53-
(preprocess (pps ppx_coda ppx_version ppx_jane ppx_compare)))
55+
(preprocessor_deps ../../config.mlh)
56+
(preprocess (pps ppx_coda ppx_version ppx_let ppx_optcomp ppx_custom_printf ppx_compare)))

src/lib/mina_commands/mina_commands.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[%%import "/src/config.mlh"]
2+
13
open Core
24
open Async
35
open Signature_lib
@@ -175,6 +177,8 @@ module Receipt_chain_verifier = Merkle_list_verifier.Make (struct
175177
Receipt.Chain_hash.cons_parties_commitment fee_payer_index elt parent_hash *)
176178
end)
177179

180+
[%%inject "compile_time_current_protocol_version", current_protocol_version]
181+
178182
let chain_id_inputs (t : Mina_lib.t) =
179183
(* these are the inputs to Blake2.digest_string in Mina.chain_id *)
180184
let config = Mina_lib.config t in
@@ -187,7 +191,11 @@ let chain_id_inputs (t : Mina_lib.t) =
187191
Lazy.force precomputed_values.constraint_system_digests
188192
|> List.map ~f:(fun (_, digest) -> Md5.to_hex digest)
189193
in
190-
(genesis_state_hash, genesis_constants, snark_keys)
194+
let protocol_major_version =
195+
Protocol_version.of_string_exn compile_time_current_protocol_version
196+
|> Protocol_version.major
197+
in
198+
(genesis_state_hash, genesis_constants, snark_keys, protocol_major_version)
191199

192200
let verify_payment t (addr : Account_id.t) (verifying_txn : User_command.t)
193201
(init_receipt, proof) =

src/lib/protocol_version/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
ppx_version.runtime
1313
)
1414
(preprocess
15-
(pps ppx_version ppx_bin_prot ppx_sexp_conv ppx_compare ppx_deriving_yojson))
15+
(pps ppx_version ppx_bin_prot ppx_fields_conv ppx_sexp_conv ppx_compare ppx_deriving_yojson))
1616
(instrumentation (backend bisect_ppx))
1717
(synopsis "Protocol version representation"))

src/lib/protocol_version/protocol_version.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open Core_kernel
66
module Stable = struct
77
module V1 = struct
88
type t = { major : int; minor : int; patch : int }
9-
[@@deriving compare, sexp, yojson]
9+
[@@deriving compare, sexp, yojson, fields]
1010

1111
let to_latest = Fn.id
1212
end

src/lib/protocol_version/protocol_version.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module Stable : sig
77
end
88
end]
99

10+
val major : t -> int
11+
12+
val minor : t -> int
13+
14+
val patch : t -> int
15+
1016
val create_exn : major:int -> minor:int -> patch:int -> t
1117

1218
val create_opt : major:int -> minor:int -> patch:int -> t option

0 commit comments

Comments
 (0)