From 90c5314c4feeaaea4b9a1bf90442f1f0d0c043e2 Mon Sep 17 00:00:00 2001 From: Pierre Chambart Date: Mon, 13 Feb 2017 22:08:51 +0100 Subject: [PATCH] Proto: Initialize a nonce for the genesis block --- src/proto/bootstrap/init_storage.ml | 1 + src/proto/bootstrap/nonce_storage.ml | 3 +++ src/proto/bootstrap/nonce_storage.mli | 3 +++ src/proto/bootstrap/seed_repr.ml | 6 ++++-- src/proto/bootstrap/seed_repr.mli | 3 ++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/proto/bootstrap/init_storage.ml b/src/proto/bootstrap/init_storage.ml index b53baa0b0..e29bd2e39 100644 --- a/src/proto/bootstrap/init_storage.ml +++ b/src/proto/bootstrap/init_storage.ml @@ -21,6 +21,7 @@ let initialize (ctxt:Context.t) = Fitness_storage.init store >>=? fun store -> Level_storage.init store >>=? fun store -> Roll_storage.init store >>=? fun store -> + Nonce_storage.init store >>=? fun store -> Seed_storage.init store >>=? fun store -> Contract_storage.init store >>=? fun store -> Reward_storage.init store >>=? fun store -> diff --git a/src/proto/bootstrap/nonce_storage.ml b/src/proto/bootstrap/nonce_storage.ml index b1acbd0e8..9b6fdb52f 100644 --- a/src/proto/bootstrap/nonce_storage.ml +++ b/src/proto/bootstrap/nonce_storage.ml @@ -65,3 +65,6 @@ let get c level = Storage.Seed.Nonce.get c level let of_bytes = Seed_repr.make_nonce let hash = Seed_repr.hash let check_hash = Seed_repr.check_hash + +let init c = + Storage.Seed.Nonce.init c Level_repr.root (Revealed Seed_repr.initial_nonce_0) diff --git a/src/proto/bootstrap/nonce_storage.mli b/src/proto/bootstrap/nonce_storage.mli index 2c0ab5a53..ea9d22a0b 100644 --- a/src/proto/bootstrap/nonce_storage.mli +++ b/src/proto/bootstrap/nonce_storage.mli @@ -41,3 +41,6 @@ val get: Storage.t -> Level_repr.t -> status tzresult Lwt.t val of_bytes: MBytes.t -> nonce tzresult val hash: nonce -> Nonce_hash.t val check_hash: nonce -> Nonce_hash.t -> bool + +val init: + Storage.t -> Storage.t tzresult Lwt.t diff --git a/src/proto/bootstrap/seed_repr.ml b/src/proto/bootstrap/seed_repr.ml index c006b3d8b..c1c999f0a 100644 --- a/src/proto/bootstrap/seed_repr.ml +++ b/src/proto/bootstrap/seed_repr.ml @@ -94,8 +94,10 @@ let check_hash nonce hash = let nonce_hash_key_part = Nonce_hash.to_path let initial_nonce_0 = - hash - (MBytes.of_string (String.make Constants_repr.nonce_length '\000')) + MBytes.of_string (String.make Constants_repr.nonce_length '\000') + +let initial_nonce_hash_0 = + hash initial_nonce_0 let initial_seed_0 = B (State_hash.hash_bytes []) let initial_seed_1 = diff --git a/src/proto/bootstrap/seed_repr.mli b/src/proto/bootstrap/seed_repr.mli index bbb572dc8..47d7bad3e 100644 --- a/src/proto/bootstrap/seed_repr.mli +++ b/src/proto/bootstrap/seed_repr.mli @@ -71,7 +71,8 @@ val nonce_hash_key_part : Nonce_hash.t -> string list (** {2 Predefined nonce} *****************************************************) -val initial_nonce_0 : Nonce_hash.t +val initial_nonce_0 : nonce +val initial_nonce_hash_0 : Nonce_hash.t (** {2 Serializers} **********************************************************)