Free roll freeze
This commit is contained in:
parent
3b4490129b
commit
cd30ff95e7
@ -17,9 +17,15 @@ let get_contract_delegate c contract =
|
||||
| Some manager -> return (Some manager)
|
||||
| None -> Storage.Contract.Delegate.get_option c contract
|
||||
|
||||
let get_contract_delegate_at_cycle c cycle contract =
|
||||
match Contract_repr.is_default contract with
|
||||
| Some manager -> return (Some manager)
|
||||
| None -> Storage.Contract.Delegate.Snapshot.get_option c (cycle, contract)
|
||||
|
||||
let clear_cycle c cycle =
|
||||
Storage.Roll.Last_for_cycle.delete c cycle >>=? fun c ->
|
||||
Storage.Roll.Owner_for_cycle.clear (c, cycle) >>= fun c ->
|
||||
Storage.Contract.Delegate.delete_snapshot c cycle >>= fun c ->
|
||||
Storage.Roll.Owner.delete_snapshot c cycle >>= fun c ->
|
||||
return c
|
||||
|
||||
let fold ctxt ~f init =
|
||||
@ -37,16 +43,10 @@ let fold ctxt ~f init =
|
||||
loop ctxt Roll_repr.first (return init)
|
||||
|
||||
let freeze_rolls_for_cycle ctxt cycle =
|
||||
fold ctxt (ctxt, Roll_repr.first)
|
||||
~f:(fun _roll contract (ctxt, promoted_roll as acc) ->
|
||||
get_contract_delegate ctxt contract >>=? function
|
||||
| None -> return acc
|
||||
| Some delegate ->
|
||||
Storage.Roll.Owner_for_cycle.init
|
||||
(ctxt, cycle) promoted_roll delegate >>=? fun ctxt ->
|
||||
return (ctxt, Roll_repr.succ promoted_roll))
|
||||
>>=? fun (ctxt, last_promoted_roll) ->
|
||||
Storage.Roll.Last_for_cycle.init ctxt cycle last_promoted_roll
|
||||
Storage.Contract.Delegate.snapshot ctxt cycle >>=? fun ctxt ->
|
||||
Storage.Roll.Owner.snapshot ctxt cycle >>=? fun ctxt ->
|
||||
Storage.Roll.Next.get ctxt >>=? fun last ->
|
||||
Storage.Roll.Last_for_cycle.init ctxt cycle last
|
||||
|
||||
(* Roll selection *)
|
||||
|
||||
@ -69,8 +69,19 @@ module Random = struct
|
||||
let rd = level_random random_seed kind level in
|
||||
let sequence = Seed_repr.sequence rd (Int32.of_int offset) in
|
||||
Storage.Roll.Last_for_cycle.get c cycle >>=? fun bound ->
|
||||
let roll, _ = Roll_repr.random sequence ~bound in
|
||||
Storage.Roll.Owner_for_cycle.get (c, cycle) roll
|
||||
let rec loop sequence =
|
||||
let roll, sequence = Roll_repr.random sequence ~bound in
|
||||
Storage.Roll.Owner.Snapshot.get_option c (cycle, roll) >>=? function
|
||||
| None ->
|
||||
loop sequence
|
||||
| Some contract ->
|
||||
get_contract_delegate_at_cycle c cycle contract >>=? function
|
||||
| None ->
|
||||
loop sequence
|
||||
| Some delegate ->
|
||||
return delegate
|
||||
in
|
||||
loop sequence
|
||||
|
||||
end
|
||||
|
||||
|
@ -70,8 +70,10 @@ module Contract = struct
|
||||
(Make_value(Bool))
|
||||
|
||||
module Delegate =
|
||||
Indexed_context.Make_map
|
||||
(struct let name = ["delegate"] end)
|
||||
Make_indexed_data_snapshotable_storage
|
||||
(Make_subcontext(Raw_context)(struct let name = ["delegate"] end))
|
||||
(Cycle_repr.Index)
|
||||
(Contract_repr.Index)
|
||||
(Make_value(Ed25519.Public_key_hash))
|
||||
|
||||
module Counter =
|
||||
@ -143,14 +145,6 @@ module Cycle = struct
|
||||
(struct let name = ["last_roll"] end)
|
||||
(Make_value(Roll_repr))
|
||||
|
||||
module Roll_owner =
|
||||
Make_indexed_data_storage
|
||||
(Make_subcontext
|
||||
(Indexed_context.Raw_context)
|
||||
(struct let name = ["roll_owners"] end))
|
||||
(Roll_repr.Index)
|
||||
(Make_value(Ed25519.Public_key_hash))
|
||||
|
||||
type nonce_status =
|
||||
| Unrevealed of {
|
||||
nonce_hash: Nonce_hash.t ;
|
||||
@ -247,12 +241,13 @@ module Roll = struct
|
||||
module Contract_change = Contract.Change
|
||||
|
||||
module Owner =
|
||||
Indexed_context.Make_map
|
||||
(struct let name = ["owner"] end)
|
||||
Make_indexed_data_snapshotable_storage
|
||||
(Make_subcontext(Raw_context)(struct let name = ["owner"] end))
|
||||
(Cycle_repr.Index)
|
||||
(Roll_repr.Index)
|
||||
(Make_value(Contract_repr))
|
||||
|
||||
module Last_for_cycle = Cycle.Last_roll
|
||||
module Owner_for_cycle = Cycle.Roll_owner
|
||||
|
||||
let clear = Indexed_context.clear
|
||||
|
||||
|
@ -25,8 +25,9 @@ module Roll : sig
|
||||
(** Storage from this submodule must only be accessed through the
|
||||
module `Roll`. *)
|
||||
|
||||
module Owner : Indexed_data_storage
|
||||
module Owner : Indexed_data_snapshotable_storage
|
||||
with type key = Roll_repr.t
|
||||
and type snapshot = Cycle_repr.t
|
||||
and type value = Contract_repr.t
|
||||
and type t := Raw_context.t
|
||||
|
||||
@ -70,11 +71,6 @@ module Roll : sig
|
||||
and type value = Roll_repr.t
|
||||
and type t := Raw_context.t
|
||||
|
||||
module Owner_for_cycle : Indexed_data_storage
|
||||
with type key = Roll_repr.t
|
||||
and type value = Ed25519.Public_key_hash.t
|
||||
and type t = Raw_context.t * Cycle_repr.t
|
||||
|
||||
end
|
||||
|
||||
module Contract : sig
|
||||
@ -107,8 +103,9 @@ module Contract : sig
|
||||
and type t := Raw_context.t
|
||||
|
||||
(** The delegate of a contract, if any. *)
|
||||
module Delegate : Indexed_data_storage
|
||||
module Delegate : Indexed_data_snapshotable_storage
|
||||
with type key = Contract_repr.t
|
||||
and type snapshot = Cycle_repr.t
|
||||
and type value = Ed25519.Public_key_hash.t
|
||||
and type t := Raw_context.t
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user