From 13fb40a4c9be918640ee128f761c3cd2eb5be253 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Mon, 25 Jun 2018 21:01:50 +0200 Subject: [PATCH] Alpha: check hard storage limit in precheck --- .../lib_protocol/src/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/src/apply.ml | 3 ++- src/proto_alpha/lib_protocol/src/fees_storage.ml | 15 ++++++++------- src/proto_alpha/lib_protocol/src/fees_storage.mli | 3 +++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index 3c7697f88..b721d589f 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -902,6 +902,8 @@ module Fees : sig type error += Operation_quota_exceeded (* `Temporary *) type error += Storage_limit_too_high (* `Permanent *) + val check_storage_limit: context -> storage_limit:Z.t -> unit tzresult + end module Operation : sig diff --git a/src/proto_alpha/lib_protocol/src/apply.ml b/src/proto_alpha/lib_protocol/src/apply.ml index e86e3990f..1bd8fb49b 100644 --- a/src/proto_alpha/lib_protocol/src/apply.ml +++ b/src/proto_alpha/lib_protocol/src/apply.ml @@ -482,8 +482,9 @@ let apply_internal_manager_operations ctxt mode ~payer ops = let precheck_manager_contents (type kind) ctxt raw_operation (op : kind Kind.manager contents) : context tzresult Lwt.t = - let Manager_operation { source ; fee ; counter ; operation ; gas_limit } = op in + let Manager_operation { source ; fee ; counter ; operation ; gas_limit ; storage_limit } = op in Lwt.return (Gas.check_limit ctxt gas_limit) >>=? fun () -> + Lwt.return (Fees.check_storage_limit ctxt storage_limit) >>=? fun () -> Contract.must_be_allocated ctxt source >>=? fun () -> Contract.check_counter_increment ctxt source counter >>=? fun () -> begin diff --git a/src/proto_alpha/lib_protocol/src/fees_storage.ml b/src/proto_alpha/lib_protocol/src/fees_storage.ml index be34e97e1..b18786c75 100644 --- a/src/proto_alpha/lib_protocol/src/fees_storage.ml +++ b/src/proto_alpha/lib_protocol/src/fees_storage.ml @@ -74,13 +74,14 @@ let burn_fees_for_storage c ~storage_limit ~payer = Contract_storage.spend_from_script c payer to_burn) >>=? fun c -> return c -let with_fees_for_storage c ~storage_limit ~payer f = - begin if Compare.Z.(storage_limit > (Raw_context.constants c).hard_storage_limit_per_operation) - || Compare.Z.(storage_limit < Z.zero)then - fail Storage_limit_too_high - else - return () - end >>=? fun () -> +let check_storage_limit c ~storage_limit = + if Compare.Z.(storage_limit > (Raw_context.constants c).hard_storage_limit_per_operation) + || Compare.Z.(storage_limit < Z.zero)then + error Storage_limit_too_high + else + ok () + +let with_fees_for_storage c ~storage_limit ~payer f = Lwt.return (Raw_context.init_storage_space_to_pay c) >>=? fun c -> f c >>=? fun (c, ret) -> burn_fees_for_storage c ~storage_limit ~payer >>=? fun c -> diff --git a/src/proto_alpha/lib_protocol/src/fees_storage.mli b/src/proto_alpha/lib_protocol/src/fees_storage.mli index 0ba5f75e1..8250578b3 100644 --- a/src/proto_alpha/lib_protocol/src/fees_storage.mli +++ b/src/proto_alpha/lib_protocol/src/fees_storage.mli @@ -19,6 +19,9 @@ val record_paid_storage_space: Raw_context.t -> Contract_repr.t -> (Raw_context.t * Z.t * Z.t * Tez_repr.t) tzresult Lwt.t +val check_storage_limit: + Raw_context.t -> storage_limit:Z.t -> unit tzresult + val with_fees_for_storage: Raw_context.t -> storage_limit:Z.t -> payer:Contract_repr.t -> (Raw_context.t -> (Raw_context.t * 'a) tzresult Lwt.t) ->