Alpha: increment version string and update context stitching

This commit is contained in:
Benjamin Canou 2018-11-21 16:36:41 +01:00 committed by Pierre Boutillier
parent c656d54500
commit fc42bd5a91
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C
3 changed files with 45 additions and 30 deletions

View File

@ -43,29 +43,44 @@ let prepare_first_block ctxt ~typecheck ~level ~timestamp ~fitness =
Vote_storage.init ctxt >>=? fun ctxt ->
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt ->
return ctxt
| Alpha ->
Storage.Contract.fold ctxt ~init:(ok ctxt)
~f:(fun contract ctxt ->
| Alpha_002 ->
Storage.Delegates.fold ctxt ~init:(Ok ctxt) ~f:begin fun delegate ctxt ->
Lwt.return ctxt >>=? fun ctxt ->
match contract with
| Implicit _ -> return ctxt
| Originated _contract_hash ->
Roll_storage.get_contract_delegate ctxt contract >>=? fun delegate ->
match delegate with
| None -> return ctxt
| Some delegate ->
Delegate_storage.registered ctxt delegate >>= fun registered ->
if registered then
Storage.Contract.Inactive_delegate.mem ctxt
(Contract_repr.implicit_contract delegate) >>= fun inactive ->
if inactive then
return ctxt
else
Contract_storage.is_manager_key_revealed
ctxt (Contract_repr.implicit_contract delegate) >>=? fun revealed ->
if revealed then
Delegate_storage.set ctxt
(Contract_repr.implicit_contract delegate)
(Some delegate)
Storage.Roll.Delegate_roll_list.get_option ctxt delegate >>=? function
| None ->
return ctxt
| Some _ ->
Storage.Active_delegates_with_rolls.add ctxt delegate >>= fun ctxt ->
return ctxt
end >>=? fun ctxt ->
let { Level_repr.cycle = current_cycle } = Raw_context.current_level ctxt in
let { Constants_repr.preserved_cycles } = Raw_context.constants ctxt in
let first_cycle =
match Cycle_repr.sub current_cycle preserved_cycles with
| None -> Cycle_repr.root
| Some first_cycle -> first_cycle in
Storage.Delegates.fold ctxt ~init:(Ok ctxt) ~f:begin fun delegate ctxt ->
Lwt.return ctxt >>=? fun ctxt ->
let rec loop ctxt cycle =
if Cycle_repr.(cycle > current_cycle) then
return ctxt
else
return ctxt)
Delegate_storage.has_frozen_balance ctxt delegate cycle >>=? fun has_frozen_balance ->
begin
if has_frozen_balance then
Storage.Delegates_with_frozen_balance.add (ctxt, cycle) delegate
else
Lwt.return ctxt
end >>= fun ctxt ->
loop ctxt (Cycle_repr.succ cycle) in
loop ctxt first_cycle
end >>=? fun ctxt ->
return ctxt
let prepare ctxt ~level ~timestamp ~fitness =
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
protocol. It's absence meaning that the context is empty. *)
let version_key = ["version"]
let version_value = "alpha_002"
let version_value = "alpha_003"
let version = "v1"
let first_level_key = [ version ; "first_level" ]
@ -450,7 +450,7 @@ let prepare ~level ~timestamp ~fitness ctxt =
type 'a previous_protocol =
| Genesis of 'a
| Alpha
| Alpha_002
let check_first_block ctxt =
Context.get ctxt version_key >>= function
@ -462,8 +462,8 @@ let check_first_block ctxt =
failwith "Internal error: previously initialized context."
else if Compare.String.(s = "genesis") then
return (Genesis ())
else if Compare.String.(s = "alpha") then
return Alpha
else if Compare.String.(s = "alpha_002") then
return Alpha_002
else
storage_error (Incompatible_protocol_version s)
@ -476,8 +476,8 @@ let prepare_first_block ~level ~timestamp ~fitness ctxt =
set_first_level ctxt first_level >>=? fun ctxt ->
set_constants ctxt param.constants >>= fun ctxt ->
return (Genesis param, ctxt)
| Alpha ->
return (Alpha, ctxt)
| Alpha_002 ->
return (Alpha_002, ctxt)
end >>=? fun (previous_proto, ctxt) ->
Context.set ctxt version_key
(MBytes.of_string version_value) >>= fun ctxt ->

View File

@ -60,7 +60,7 @@ val prepare:
type 'a previous_protocol =
| Genesis of 'a
| Alpha
| Alpha_002
val prepare_first_block:
level:int32 ->