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