Proto: generalize temporary big_map id too

parent 4351659c
......@@ -174,9 +174,7 @@ end
module Big_map = struct
type id = Z.t
let fresh ~temporary c =
if temporary then return (Raw_context.fresh_temporary_big_map c)
else Storage.Big_map.Next.incr c
let fresh ~temporary c = Lazy_storage.fresh Big_map ~temporary c
let mem c m k = Storage.Big_map.Contents.mem (c, m) k
......@@ -184,10 +182,6 @@ module Big_map = struct
let rpc_arg = Storage.Big_map.rpc_arg
let cleanup_temporary c =
Raw_context.temporary_big_maps c Storage.Big_map.remove_rec c
>>= fun c -> Lwt.return (Raw_context.reset_temporary_big_map c)
let exists c id =
Lwt.return
(Raw_context.consume_gas c (Gas_limit_repr.read_bytes_cost Z.zero))
......
......@@ -696,8 +696,6 @@ module Big_map : sig
val rpc_arg : id RPC_arg.t
val cleanup_temporary : context -> context Lwt.t
val exists :
context ->
id ->
......@@ -746,6 +744,8 @@ module Lazy_storage : sig
val encoding : diffs Data_encoding.t
val legacy_big_map_diff_encoding : diffs Data_encoding.t
val cleanup_temporaries : context -> context Lwt.t
end
module Contract : sig
......
......@@ -1055,7 +1055,8 @@ let apply_manager_contents_list ctxt mode baker chain_id contents_list =
| `Failure ->
Lwt.return (ctxt (* backtracked *), mark_backtracked results)
| `Success ctxt ->
Big_map.cleanup_temporary ctxt >>= fun ctxt -> Lwt.return (ctxt, results)
Lazy_storage.cleanup_temporaries ctxt
>>= fun ctxt -> Lwt.return (ctxt, results)
let apply_contents_list (type kind) ctxt chain_id mode pred_block baker
(operation : kind operation) (contents_list : kind contents_list) :
......
......@@ -51,6 +51,10 @@ module type OPS = sig
val apply_updates :
Raw_context.t -> Z.t -> updates -> (Raw_context.t * Z.t) tzresult Lwt.t
module Next : sig
val incr : Raw_context.t -> (Raw_context.t * Z.t) tzresult Lwt.t
end
module Total_bytes : sig
val init : Raw_context.t -> Z.t -> Z.t -> Raw_context.t tzresult Lwt.t
......@@ -267,3 +271,19 @@ let apply ctxt diffs =
else Z.add total_size added_size ))
(ctxt, Z.zero)
diffs
let fresh :
type a u.
(a, u) Lazy_storage_kind.t ->
temporary:bool ->
Raw_context.t ->
(Raw_context.t * Z.t) tzresult Lwt.t =
fun kind ~temporary ctxt ->
if temporary then return (Raw_context.fresh_temporary_lazy_storage kind ctxt)
else
let (module OPS) = get_ops kind in
OPS.Next.incr ctxt
let cleanup_temporaries =
let fs = Lazy_storage_kind.Record.{big_map = Big_map.remove_rec} in
fun ctxt -> Raw_context.cleanup_temporary_lazy_storage fs ctxt
......@@ -64,3 +64,11 @@ type diffs = diffs_item list
val encoding : diffs Data_encoding.t
val apply : Raw_context.t -> diffs -> (Raw_context.t * Z.t) tzresult Lwt.t
val fresh :
(_, _) Lazy_storage_kind.t ->
temporary:bool ->
Raw_context.t ->
(Raw_context.t * Z.t) tzresult Lwt.t
val cleanup_temporaries : Raw_context.t -> Raw_context.t Lwt.t
......@@ -73,3 +73,23 @@ let eq :
let compare : type a1 u1 a2 u2. (a1, u1) t -> (a2, u2) t -> int =
fun k1 k2 -> match (k1, k2) with (Big_map, Big_map) -> 0
module Record = struct
type ('a, 'u) kind = ('a, 'u) t
type 'a t = {big_map : 'a}
let init x = {big_map = x}
let map_get_one :
type a u. ('b -> 'c * 'd) -> (a, u) kind -> 'b t -> 'c t * 'd =
fun f k r ->
match k with
| Big_map ->
let (big_map, acc) = f r.big_map in
({big_map}, acc)
let fold2_s :
('a -> 'b -> 'acc -> 'acc Lwt.t) -> 'a t -> 'b t -> 'acc -> 'acc Lwt.t =
fun f r1 r2 acc -> f r1.big_map r2.big_map acc
end
......@@ -44,7 +44,7 @@ type t = {
storage_space_to_pay : Z.t option;
allocated_contracts : int option;
origination_nonce : Contract_repr.origination_nonce option;
temporary_big_map : Z.t;
temporary_lazy_storage : Z.t Lazy_storage_kind.Record.t;
internal_nonce : int;
internal_nonces_used : Int_set.t;
}
......@@ -535,7 +535,8 @@ let prepare ~level ~predecessor_timestamp ~timestamp ~fitness ctxt =
allocated_contracts = None;
block_gas = constants.Constants_repr.hard_gas_limit_per_block;
origination_nonce = None;
temporary_big_map = Z.sub Z.zero Z.one;
temporary_lazy_storage =
Lazy_storage_kind.Record.init (Z.sub Z.zero Z.one);
internal_nonce = 0;
internal_nonces_used = Int_set.empty;
}
......@@ -730,16 +731,28 @@ let absolute_key _ k = k
let description = Storage_description.create ()
let fresh_temporary_big_map ctxt =
( {ctxt with temporary_big_map = Z.sub ctxt.temporary_big_map Z.one},
ctxt.temporary_big_map )
let reset_temporary_big_map ctxt =
{ctxt with temporary_big_map = Z.sub Z.zero Z.one}
let temporary_big_maps ctxt f acc =
let rec iter acc id =
if Z.equal id ctxt.temporary_big_map then Lwt.return acc
else f acc id >>= fun acc -> iter acc (Z.sub id Z.one)
let fresh_temporary_lazy_storage kind ctxt =
let (temporary_lazy_storage, fresh_id) =
Lazy_storage_kind.Record.map_get_one
(fun temp_id -> (Z.(sub temp_id one), temp_id))
kind
ctxt.temporary_lazy_storage
in
iter acc (Z.sub Z.zero Z.one)
({ctxt with temporary_lazy_storage}, fresh_id)
let cleanup_temporary_lazy_storage fs ctxt =
Lazy_storage_kind.Record.fold2_s
(fun f temp_id ctxt ->
let rec iter acc id =
if Z.equal id temp_id then Lwt.return acc
else f acc id >>= fun acc -> iter acc Z.(sub id one)
in
iter ctxt Z.(sub zero one))
fs
ctxt.temporary_lazy_storage
ctxt
>|= fun ctxt ->
{
ctxt with
temporary_lazy_storage = Lazy_storage_kind.Record.init Z.(sub zero one);
}
......@@ -285,11 +285,13 @@ val init_endorsements :
(** Marks an endorsment in the map as used. *)
val record_endorsement : context -> Signature.Public_key_hash.t -> context
(** Provide a fresh identifier for a temporary big map (negative index). *)
val fresh_temporary_big_map : context -> context * Z.t
(** Reset the temporary big_map identifier generator to [-1]. *)
val reset_temporary_big_map : context -> context
(** Iterate over all created temporary big maps since the last {!reset_temporary_big_map}. *)
val temporary_big_maps : context -> ('a -> Z.t -> 'a Lwt.t) -> 'a -> 'a Lwt.t
(** Provide a fresh identifier for a temporary lazy storage (negative index). *)
val fresh_temporary_lazy_storage :
(_, _) Lazy_storage_kind.t -> context -> context * Z.t
(** Iterate over all created temporary lazy storage ids since the last call
and reset the identifier generators to [-1]. *)
val cleanup_temporary_lazy_storage :
(context -> Z.t -> context Lwt.t) Lazy_storage_kind.Record.t ->
context ->
context Lwt.t
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment