Alpha: rename versions to alpha_{current,previous}

Remove initialization from protocol 002.
This commit is contained in:
Marco Stronati 2019-01-20 21:42:19 +01:00 committed by Grégoire Henry
parent 6194efa4e0
commit 356f4df169
No known key found for this signature in database
GPG Key ID: 827A020B224844F1
3 changed files with 10 additions and 45 deletions

View File

@ -43,43 +43,7 @@ let prepare_first_block ctxt ~typecheck ~level ~timestamp ~fitness =
Vote_storage.init ctxt >>=? fun ctxt -> Vote_storage.init ctxt >>=? fun ctxt ->
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt -> Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt ->
return ctxt return ctxt
| Alpha_002 -> | Alpha_previous ->
Storage.Delegates.fold ctxt ~init:(Ok ctxt) ~f:begin fun delegate ctxt ->
Lwt.return ctxt >>=? fun ctxt ->
Storage.Contract.Inactive_delegate.mem ctxt
(Contract_repr.implicit_contract delegate) >>= fun inactive ->
if inactive then
return ctxt
else
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
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 return ctxt
let prepare ctxt ~level ~timestamp ~fitness = let prepare ctxt ~level ~timestamp ~fitness =

View File

@ -318,7 +318,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_003" let version_value = "alpha_current"
let version = "v1" let version = "v1"
let first_level_key = [ version ; "first_level" ] let first_level_key = [ version ; "first_level" ]
@ -462,7 +462,7 @@ let prepare ~level ~timestamp ~fitness ctxt =
type 'a previous_protocol = type 'a previous_protocol =
| Genesis of 'a | Genesis of 'a
| Alpha_002 | Alpha_previous
let check_first_block ctxt = let check_first_block ctxt =
Context.get ctxt version_key >>= function Context.get ctxt version_key >>= function
@ -474,22 +474,23 @@ let check_first_block ctxt =
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 (Genesis ()) return (Genesis ())
else if Compare.String.(s = "alpha_002") then else if Compare.String.(s = "alpha_previous") then
return Alpha_002 return Alpha_previous
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 previous_protocol -> check_first_block ctxt >>=? fun previous_protocol ->
begin match previous_protocol with begin
match previous_protocol with
| Genesis () -> | Genesis () ->
Lwt.return (Raw_level_repr.of_int32 level) >>=? fun first_level -> Lwt.return (Raw_level_repr.of_int32 level) >>=? fun first_level ->
get_proto_param ctxt >>=? fun (param, ctxt) -> get_proto_param ctxt >>=? fun (param, ctxt) ->
set_first_level ctxt first_level >>=? fun ctxt -> set_first_level ctxt first_level >>=? fun ctxt ->
set_constants ctxt param.constants >>= fun ctxt -> set_constants ctxt param.constants >>= fun ctxt ->
return (Genesis param, ctxt) return (Genesis param, ctxt)
| Alpha_002 -> | Alpha_previous ->
return (Alpha_002, ctxt) return (Alpha_previous, ctxt)
end >>=? fun (previous_proto, 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 ->

View File

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