Alpha_002: prepare for Proto_alpha upgrade

This commit is contained in:
Pierre Chambart 2018-07-17 18:07:43 +02:00 committed by Grégoire Henry
parent e80839efe1
commit 15857d7e90
6 changed files with 52 additions and 28 deletions

View File

@ -13,7 +13,7 @@ $client -w none config update
sleep 2 sleep 2
#tests for the rpc service raw_context #tests for the rpc service raw_context
$client rpc get '/chains/main/blocks/head/context/raw/bytes/version' | assert '"616c706861"' $client rpc get '/chains/main/blocks/head/context/raw/bytes/version' | assert '"616c7068615f303032"'
$client rpc get '/chains/main/blocks/head/context/raw/bytes/non-existent' | assert 'No service found at this URL' $client rpc get '/chains/main/blocks/head/context/raw/bytes/non-existent' | assert 'No service found at this URL'
$client rpc get '/chains/main/blocks/head/context/raw/bytes/delegates/?depth=3' | assert '{ "ed25519": $client rpc get '/chains/main/blocks/head/context/raw/bytes/delegates/?depth=3' | assert '{ "ed25519":
{ "02": { "29": null }, "a9": { "ce": null }, "c5": { "5c": null }, { "02": { "29": null }, "a9": { "ce": null }, "c5": { "5c": null },

View File

@ -42,7 +42,7 @@ let run blkid =
in in
(* files and directories that are in context *) (* files and directories that are in context *)
let version = Key (MBytes.of_hex (`Hex "616c706861")) in let version = Key (MBytes.of_hex (`Hex "616c7068615f303032")) in
let dir_depth0 = Cut in let dir_depth0 = Cut in
let dir_depth2 = Dir [("02", Dir [("29", Cut)]); let dir_depth2 = Dir [("02", Dir [("29", Cut)]);
("a9", Dir [("ce", Cut)]); ("a9", Dir [("ce", Cut)]);

View File

@ -26,21 +26,25 @@
(* This is the genesis protocol: initialise the state *) (* This is the genesis protocol: initialise the state *)
let prepare_first_block ctxt ~typecheck ~level ~timestamp ~fitness = let prepare_first_block ctxt ~typecheck ~level ~timestamp ~fitness =
Raw_context.prepare_first_block Raw_context.prepare_first_block
~level ~timestamp ~fitness ctxt >>=? fun (param, ctxt) -> ~level ~timestamp ~fitness ctxt >>=? fun (previous_protocol, ctxt) ->
Commitment_storage.init ctxt param.commitments >>=? fun ctxt -> match previous_protocol with
Roll_storage.init ctxt >>=? fun ctxt -> | Genesis param ->
Seed_storage.init ctxt >>=? fun ctxt -> Commitment_storage.init ctxt param.commitments >>=? fun ctxt ->
Contract_storage.init ctxt >>=? fun ctxt -> Roll_storage.init ctxt >>=? fun ctxt ->
Bootstrap_storage.init ctxt Seed_storage.init ctxt >>=? fun ctxt ->
~typecheck Contract_storage.init ctxt >>=? fun ctxt ->
?ramp_up_cycles:param.security_deposit_ramp_up_cycles Bootstrap_storage.init ctxt
?no_reward_cycles:param.no_reward_cycles ~typecheck
param.bootstrap_accounts ?ramp_up_cycles:param.security_deposit_ramp_up_cycles
param.bootstrap_contracts >>=? fun ctxt -> ?no_reward_cycles:param.no_reward_cycles
Roll_storage.init_first_cycles ctxt >>=? fun ctxt -> param.bootstrap_accounts
Vote_storage.init ctxt >>=? fun ctxt -> param.bootstrap_contracts >>=? fun ctxt ->
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt -> Roll_storage.init_first_cycles ctxt >>=? fun ctxt ->
return ctxt Vote_storage.init ctxt >>=? fun ctxt ->
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt ->
return ctxt
| Alpha ->
return ctxt
let prepare ctxt ~level ~timestamp ~fitness = let prepare ctxt ~level ~timestamp ~fitness =
Raw_context.prepare ~level ~timestamp ~fitness ctxt Raw_context.prepare ~level ~timestamp ~fitness ctxt

View File

@ -307,7 +307,7 @@ let storage_error err = fail (Storage_error err)
(* This key should always be populated for every version of the (* This key should always be populated for every version of the
protocol. It's absence meaning that the context is empty. *) protocol. It's absence meaning that the context is empty. *)
let version_key = ["version"] let version_key = ["version"]
let version_value = "alpha" let version_value = "alpha_002"
let version = "v1" let version = "v1"
let first_level_key = [ version ; "first_level" ] let first_level_key = [ version ; "first_level" ]
@ -448,28 +448,41 @@ let prepare ~level ~timestamp ~fitness ctxt =
internal_nonces_used = Int_set.empty ; internal_nonces_used = Int_set.empty ;
} }
type 'a previous_protocol =
| Genesis of 'a
| Alpha
let check_first_block ctxt = let check_first_block ctxt =
Context.get ctxt version_key >>= function Context.get ctxt version_key >>= function
| None -> return_unit | None ->
failwith "Internal error: un-initialized context in check_first_block."
| Some bytes -> | Some bytes ->
let s = MBytes.to_string bytes in let s = MBytes.to_string bytes in
if Compare.String.(s = version_value) then if Compare.String.(s = version_value) then
failwith "Internal error: previously initialized context." failwith "Internal error: previously initialized context."
else if Compare.String.(s = "genesis") then else if Compare.String.(s = "genesis") then
return_unit return (Genesis ())
else if Compare.String.(s = "alpha") then
return Alpha
else else
storage_error (Incompatible_protocol_version s) storage_error (Incompatible_protocol_version s)
let prepare_first_block ~level ~timestamp ~fitness ctxt = let prepare_first_block ~level ~timestamp ~fitness ctxt =
check_first_block ctxt >>=? fun () -> check_first_block ctxt >>=? fun previous_protocol ->
Lwt.return (Raw_level_repr.of_int32 level) >>=? fun first_level -> begin match previous_protocol with
get_proto_param ctxt >>=? fun (param, ctxt) -> | Genesis () ->
Lwt.return (Raw_level_repr.of_int32 level) >>=? fun first_level ->
get_proto_param ctxt >>=? fun (param, ctxt) ->
set_first_level ctxt first_level >>=? fun ctxt ->
set_constants ctxt param.constants >>= fun ctxt ->
return (Genesis param, ctxt)
| Alpha ->
return (Alpha, ctxt)
end >>=? fun (previous_proto, ctxt) ->
Context.set ctxt version_key Context.set ctxt version_key
(MBytes.of_string version_value) >>= fun ctxt -> (MBytes.of_string version_value) >>= fun ctxt ->
set_first_level ctxt first_level >>=? fun ctxt ->
set_constants ctxt param.constants >>= fun ctxt ->
prepare ctxt ~level ~timestamp ~fitness >>=? fun ctxt -> prepare ctxt ~level ~timestamp ~fitness >>=? fun ctxt ->
return (param, ctxt) return (previous_proto, ctxt)
let activate ({ context = c ; _ } as s) h = let activate ({ context = c ; _ } as s) h =
Updater.activate c h >>= fun c -> Lwt.return { s with context = c } Updater.activate c h >>= fun c -> Lwt.return { s with context = c }

View File

@ -58,11 +58,15 @@ val prepare:
fitness: Fitness.t -> fitness: Fitness.t ->
Context.t -> context tzresult Lwt.t Context.t -> context tzresult Lwt.t
type 'a previous_protocol =
| Genesis of 'a
| Alpha
val prepare_first_block: val prepare_first_block:
level:int32 -> level:int32 ->
timestamp:Time.t -> timestamp:Time.t ->
fitness:Fitness.t -> fitness:Fitness.t ->
Context.t -> (Parameters_repr.t * context) tzresult Lwt.t Context.t -> (Parameters_repr.t previous_protocol * context) tzresult Lwt.t
val activate: context -> Protocol_hash.t -> t Lwt.t val activate: context -> Protocol_hash.t -> t Lwt.t
val fork_test_chain: context -> Protocol_hash.t -> Time.t -> t Lwt.t val fork_test_chain: context -> Protocol_hash.t -> Time.t -> t Lwt.t

View File

@ -222,7 +222,10 @@ let initial_context
Data_encoding.Binary.to_bytes_exn Data_encoding.json json Data_encoding.Binary.to_bytes_exn Data_encoding.json json
in in
Tezos_protocol_environment_memory.Context.( Tezos_protocol_environment_memory.Context.(
set empty protocol_param_key proto_params set empty ["version"] (MBytes.of_string "genesis")
) >>= fun ctxt ->
Tezos_protocol_environment_memory.Context.(
set ctxt protocol_param_key proto_params
) >>= fun ctxt -> ) >>= fun ctxt ->
Main.init ctxt header Main.init ctxt header
>|= Alpha_environment.wrap_error >>=? fun { context; _ } -> >|= Alpha_environment.wrap_error >>=? fun { context; _ } ->