Alpha: rename versions to alpha_{current,previous}
Remove initialization from protocol 002.
This commit is contained in:
parent
6194efa4e0
commit
356f4df169
@ -43,43 +43,7 @@ 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_002 ->
|
||||
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 ->
|
||||
| Alpha_previous ->
|
||||
return ctxt
|
||||
|
||||
let prepare ctxt ~level ~timestamp ~fitness =
|
||||
|
@ -318,7 +318,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_003"
|
||||
let version_value = "alpha_current"
|
||||
|
||||
let version = "v1"
|
||||
let first_level_key = [ version ; "first_level" ]
|
||||
@ -462,7 +462,7 @@ let prepare ~level ~timestamp ~fitness ctxt =
|
||||
|
||||
type 'a previous_protocol =
|
||||
| Genesis of 'a
|
||||
| Alpha_002
|
||||
| Alpha_previous
|
||||
|
||||
let check_first_block ctxt =
|
||||
Context.get ctxt version_key >>= function
|
||||
@ -474,22 +474,23 @@ 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_002") then
|
||||
return Alpha_002
|
||||
else if Compare.String.(s = "alpha_previous") then
|
||||
return Alpha_previous
|
||||
else
|
||||
storage_error (Incompatible_protocol_version s)
|
||||
|
||||
let prepare_first_block ~level ~timestamp ~fitness ctxt =
|
||||
check_first_block ctxt >>=? fun previous_protocol ->
|
||||
begin match previous_protocol with
|
||||
begin
|
||||
match previous_protocol with
|
||||
| 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_002 ->
|
||||
return (Alpha_002, ctxt)
|
||||
| Alpha_previous ->
|
||||
return (Alpha_previous, ctxt)
|
||||
end >>=? fun (previous_proto, ctxt) ->
|
||||
Context.set ctxt version_key
|
||||
(MBytes.of_string version_value) >>= fun ctxt ->
|
||||
|
@ -60,7 +60,7 @@ val prepare:
|
||||
|
||||
type 'a previous_protocol =
|
||||
| Genesis of 'a
|
||||
| Alpha_002
|
||||
| Alpha_previous
|
||||
|
||||
val prepare_first_block:
|
||||
level:int32 ->
|
||||
|
Loading…
Reference in New Issue
Block a user