Alpha: keep the storage space in bytes instead of the premultiplied fees

This commit is contained in:
Benjamin Canou 2018-04-22 17:42:13 +02:00 committed by Grégoire Henry
parent 7d73605f5c
commit dd9cd8a1c3
14 changed files with 110 additions and 111 deletions

View File

@ -249,7 +249,7 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) =
"This delegation was successfully applied" "This delegation was successfully applied"
| Applied (Transaction_result { balance_updates ; consumed_gas ; | Applied (Transaction_result { balance_updates ; consumed_gas ;
operations ; storage ; operations ; storage ;
originated_contracts ; storage_fees_increment }) -> originated_contracts ; storage_size_diff }) ->
Format.fprintf ppf Format.fprintf ppf
"This transaction was successfully applied" ; "This transaction was successfully applied" ;
begin match operations with begin match operations with
@ -268,11 +268,10 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) =
Format.fprintf ppf "@,@[<hv 2>Updated storage:@ %a@]" Format.fprintf ppf "@,@[<hv 2>Updated storage:@ %a@]"
Michelson_v1_printer.print_expr expr Michelson_v1_printer.print_expr expr
end ; end ;
begin if storage_fees_increment <> Tez.zero then begin if storage_size_diff <> 0L then
Format.fprintf ppf Format.fprintf ppf
"@,Storage fees increment: %s%a" "@,Storage size difference: %Ld bytes"
Client_proto_args.tez_sym storage_size_diff
Tez.pp storage_fees_increment
end ; end ;
Format.fprintf ppf Format.fprintf ppf
"@,Consumed gas: %s" "@,Consumed gas: %s"
@ -285,7 +284,7 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) =
pp_balance_updates balance_updates pp_balance_updates balance_updates
end end
| Applied (Origination_result { balance_updates ; consumed_gas ; | Applied (Origination_result { balance_updates ; consumed_gas ;
originated_contracts ; storage_fees_increment }) -> originated_contracts ; storage_size_diff }) ->
Format.fprintf ppf Format.fprintf ppf
"This origination was successfully applied" ; "This origination was successfully applied" ;
begin match originated_contracts with begin match originated_contracts with
@ -294,11 +293,10 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) =
Format.fprintf ppf "@,@[<v 2>Originated contracts:@,%a@]" Format.fprintf ppf "@,@[<v 2>Originated contracts:@,%a@]"
(Format.pp_print_list Contract.pp) contracts (Format.pp_print_list Contract.pp) contracts
end ; end ;
begin if storage_fees_increment <> Tez.zero then begin if storage_size_diff <> 0L then
Format.fprintf ppf Format.fprintf ppf
"@,Storage fees increment: %s%a" "@,Storage size used: %Ld bytes"
Client_proto_args.tez_sym storage_size_diff
Tez.pp storage_fees_increment
end ; end ;
Format.fprintf ppf Format.fprintf ppf
"@,Consumed gas: %s" "@,Consumed gas: %s"

View File

@ -337,6 +337,7 @@ module Constants : sig
val endorsers_per_block: context -> int val endorsers_per_block: context -> int
val hard_gas_limit_per_operation: context -> Z.t val hard_gas_limit_per_operation: context -> Z.t
val hard_gas_limit_per_block: context -> Z.t val hard_gas_limit_per_block: context -> Z.t
val cost_per_byte: context -> Tez.t
val proof_of_work_threshold: context -> int64 val proof_of_work_threshold: context -> int64
val dictator_pubkey: context -> Signature.Public_key.t val dictator_pubkey: context -> Signature.Public_key.t
val max_operation_data_length: context -> int val max_operation_data_length: context -> int
@ -541,9 +542,9 @@ module Contract : sig
Script.expr -> big_map_diff option -> Script.expr -> big_map_diff option ->
context tzresult Lwt.t context tzresult Lwt.t
val fees: context -> t -> Tez.t tzresult Lwt.t val used_storage_space: context -> t -> Int64.t tzresult Lwt.t
val paid_fees: context -> t -> Tez.t tzresult Lwt.t val paid_storage_space_fees: context -> t -> Tez.t tzresult Lwt.t
val add_to_paid_fees: context -> t -> Tez.t -> context tzresult Lwt.t val pay_for_storage_space: context -> t -> Tez.t -> context tzresult Lwt.t
val increment_counter: val increment_counter:
context -> contract -> context tzresult Lwt.t context -> contract -> context tzresult Lwt.t

View File

@ -419,7 +419,7 @@ let apply_manager_operation_content ctxt ~payer ~source ~internal operation =
Contract destination, Credited amount ] ; Contract destination, Credited amount ] ;
originated_contracts = [] ; originated_contracts = [] ;
consumed_gas = gas_difference before_operation ctxt ; consumed_gas = gas_difference before_operation ctxt ;
storage_fees_increment = Tez.zero } in storage_size_diff = 0L } in
return (ctxt, result) return (ctxt, result)
| Some script -> | Some script ->
Lwt.return @@ Script_ir_translator.parse_toplevel script.code >>=? fun (arg_type, _, _) -> Lwt.return @@ Script_ir_translator.parse_toplevel script.code >>=? fun (arg_type, _, _) ->
@ -439,10 +439,11 @@ let apply_manager_operation_content ctxt ~payer ~source ~internal operation =
~check_operations:(not internal) ~check_operations:(not internal)
~source ~payer ~self:(destination, script) ~amount ~parameter ~source ~payer ~self:(destination, script) ~amount ~parameter
>>=? fun { ctxt ; storage ; big_map_diff ; operations } -> >>=? fun { ctxt ; storage ; big_map_diff ; operations } ->
Contract.used_storage_space ctxt destination >>=? fun old_size ->
Contract.update_script_storage Contract.update_script_storage
ctxt destination storage big_map_diff >>=? fun ctxt -> ctxt destination storage big_map_diff >>=? fun ctxt ->
Fees.update_script_storage Fees.update_script_storage
ctxt ~payer destination >>=? fun (ctxt, fees) -> ctxt ~payer destination >>=? fun (ctxt, new_size, fees) ->
new_contracts before_operation ctxt >>=? fun originated_contracts -> new_contracts before_operation ctxt >>=? fun originated_contracts ->
let result = let result =
Transaction_result Transaction_result
@ -455,7 +456,7 @@ let apply_manager_operation_content ctxt ~payer ~source ~internal operation =
Contract destination, Credited amount ] ; Contract destination, Credited amount ] ;
originated_contracts ; originated_contracts ;
consumed_gas = gas_difference before_operation ctxt ; consumed_gas = gas_difference before_operation ctxt ;
storage_fees_increment = fees } in storage_size_diff = Int64.sub new_size old_size } in
return (ctxt, result) return (ctxt, result)
end end
| Origination { manager ; delegate ; script ; preorigination ; | Origination { manager ; delegate ; script ; preorigination ;
@ -476,7 +477,7 @@ let apply_manager_operation_content ctxt ~payer ~source ~internal operation =
~manager ~delegate ~balance:credit ~manager ~delegate ~balance:credit
?script ?script
~spendable ~delegatable >>=? fun ctxt -> ~spendable ~delegatable >>=? fun ctxt ->
Fees.origination_burn ctxt ~payer contract >>=? fun (ctxt, fees) -> Fees.origination_burn ctxt ~payer contract >>=? fun (ctxt, size, fees) ->
let result = let result =
Origination_result Origination_result
{ balance_updates = { balance_updates =
@ -486,7 +487,7 @@ let apply_manager_operation_content ctxt ~payer ~source ~internal operation =
Contract contract, Credited credit ] ; Contract contract, Credited credit ] ;
originated_contracts = [ contract ] ; originated_contracts = [ contract ] ;
consumed_gas = gas_difference before_operation ctxt ; consumed_gas = gas_difference before_operation ctxt ;
storage_fees_increment = fees } in storage_size_diff = size } in
return (ctxt, result) return (ctxt, result)
| Delegation delegate -> | Delegation delegate ->
set_delegate ctxt source delegate >>=? fun ctxt -> set_delegate ctxt source delegate >>=? fun ctxt ->

View File

@ -110,12 +110,12 @@ type successful_manager_operation_result =
balance_updates : balance_updates ; balance_updates : balance_updates ;
originated_contracts : Contract.t list ; originated_contracts : Contract.t list ;
consumed_gas : Z.t ; consumed_gas : Z.t ;
storage_fees_increment : Tez.t } storage_size_diff : Int64.t }
| Origination_result of | Origination_result of
{ balance_updates : balance_updates ; { balance_updates : balance_updates ;
originated_contracts : Contract.t list ; originated_contracts : Contract.t list ;
consumed_gas : Z.t ; consumed_gas : Z.t ;
storage_fees_increment : Tez.t } storage_size_diff : Int64.t }
| Delegation_result | Delegation_result
type manager_operation_kind = type manager_operation_kind =
@ -153,23 +153,23 @@ let manager_operation_result_encoding =
(dft "balance_updates" balance_updates_encoding []) (dft "balance_updates" balance_updates_encoding [])
(dft "originated_contracts" (list Contract.encoding) []) (dft "originated_contracts" (list Contract.encoding) [])
(dft "consumed_gas" z Z.zero) (dft "consumed_gas" z Z.zero)
(dft "storage_fees_increment" Tez.encoding Tez.zero)) (dft "storage_size_diff" int64 0L))
(function (function
| Applied (Transaction_result | Applied (Transaction_result
{ operations ; storage ; balance_updates ; { operations ; storage ; balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_fees_increment }) -> storage_size_diff }) ->
Some ((), (), operations, storage, balance_updates, Some ((), (), operations, storage, balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_fees_increment) storage_size_diff)
| _ -> None) | _ -> None)
(fun ((), (), operations, storage, balance_updates, (fun ((), (), operations, storage, balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_fees_increment) -> storage_size_diff) ->
Applied (Transaction_result Applied (Transaction_result
{ operations ; storage ; balance_updates ; { operations ; storage ; balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_fees_increment })) ; storage_size_diff })) ;
case Json_only case Json_only
(obj6 (obj6
(req "status" (constant "applied")) (req "status" (constant "applied"))
@ -177,23 +177,23 @@ let manager_operation_result_encoding =
(dft "balance_updates" balance_updates_encoding []) (dft "balance_updates" balance_updates_encoding [])
(dft "originated_contracts" (list Contract.encoding) []) (dft "originated_contracts" (list Contract.encoding) [])
(dft "consumed_gas" z Z.zero) (dft "consumed_gas" z Z.zero)
(dft "storage_fees_increment" Tez.encoding Tez.zero)) (dft "storage_size_diff" int64 0L))
(function (function
| Applied (Origination_result | Applied (Origination_result
{ balance_updates ; { balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_fees_increment }) -> storage_size_diff }) ->
Some ((), (), balance_updates, Some ((), (), balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_fees_increment) storage_size_diff)
| _ -> None) | _ -> None)
(fun ((), (), balance_updates, (fun ((), (), balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_fees_increment) -> storage_size_diff) ->
Applied (Origination_result Applied (Origination_result
{ balance_updates ; { balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_fees_increment })) ; storage_size_diff })) ;
case Json_only case Json_only
(obj2 (obj2
(req "status" (constant "applied")) (req "status" (constant "applied"))

View File

@ -83,12 +83,12 @@ and successful_manager_operation_result =
balance_updates : balance_updates ; balance_updates : balance_updates ;
originated_contracts : Contract.t list ; originated_contracts : Contract.t list ;
consumed_gas : Z.t ; consumed_gas : Z.t ;
storage_fees_increment : Tez.t } storage_size_diff : Int64.t }
| Origination_result of | Origination_result of
{ balance_updates : balance_updates ; { balance_updates : balance_updates ;
originated_contracts : Contract.t list ; originated_contracts : Contract.t list ;
consumed_gas : Z.t ; consumed_gas : Z.t ;
storage_fees_increment : Tez.t } storage_size_diff : Int64.t }
| Delegation_result | Delegation_result
(** Serializer for {!proto_operation_result}. *) (** Serializer for {!proto_operation_result}. *)

View File

@ -88,6 +88,13 @@ module S = struct
~output: (obj2 (req "per_block" z) (req "per_operation" z)) ~output: (obj2 (req "per_block" z) (req "per_operation" z))
RPC_path.(custom_root / "hard_gas_limits") RPC_path.(custom_root / "hard_gas_limits")
let cost_per_byte =
RPC_service.post_service
~description: "The cost per bytes added to the storage"
~query: RPC_query.empty
~input: empty
~output: (obj1 (req "cost_per_byte" Tez.encoding))
RPC_path.(custom_root / "cost_per_byte")
let proof_of_work_threshold = let proof_of_work_threshold =
RPC_service.post_service RPC_service.post_service
@ -194,6 +201,9 @@ let () =
return (Constants.hard_gas_limit_per_block ctxt, return (Constants.hard_gas_limit_per_block ctxt,
Constants.hard_gas_limit_per_operation ctxt) Constants.hard_gas_limit_per_operation ctxt)
end ; end ;
register0 S.cost_per_byte begin fun ctxt () () ->
return (Constants.cost_per_byte ctxt)
end ;
register0 S.proof_of_work_threshold begin fun ctxt () () -> register0 S.proof_of_work_threshold begin fun ctxt () () ->
return (Constants.proof_of_work_threshold ctxt) return (Constants.proof_of_work_threshold ctxt)
end ; end ;
@ -242,6 +252,8 @@ let endorsers_per_block ctxt block =
RPC_context.make_call0 S.endorsers_per_block ctxt block () () RPC_context.make_call0 S.endorsers_per_block ctxt block () ()
let hard_gas_limits ctxt block = let hard_gas_limits ctxt block =
RPC_context.make_call0 S.hard_gas_limits ctxt block () () RPC_context.make_call0 S.hard_gas_limits ctxt block () ()
let cost_per_byte ctxt block =
RPC_context.make_call0 S.cost_per_byte ctxt block () ()
let proof_of_work_threshold ctxt block = let proof_of_work_threshold ctxt block =
RPC_context.make_call0 S.proof_of_work_threshold ctxt block () () RPC_context.make_call0 S.proof_of_work_threshold ctxt block () ()
let seed_nonce_revelation_tip ctxt block = let seed_nonce_revelation_tip ctxt block =

View File

@ -36,6 +36,10 @@ val endorsers_per_block:
val hard_gas_limits: val hard_gas_limits:
'a #RPC_context.simple -> 'a -> (Z.t * Z.t) shell_tzresult Lwt.t 'a #RPC_context.simple -> 'a -> (Z.t * Z.t) shell_tzresult Lwt.t
val cost_per_byte:
'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t
val proof_of_work_threshold: val proof_of_work_threshold:
'a #RPC_context.simple -> 'a -> Int64.t shell_tzresult Lwt.t 'a #RPC_context.simple -> 'a -> Int64.t shell_tzresult Lwt.t

View File

@ -37,6 +37,9 @@ let hard_gas_limit_per_operation c =
let hard_gas_limit_per_block c = let hard_gas_limit_per_block c =
let constants = Raw_context.constants c in let constants = Raw_context.constants c in
constants.hard_gas_limit_per_block constants.hard_gas_limit_per_block
let cost_per_byte c =
let constants = Raw_context.constants c in
constants.cost_per_byte
let proof_of_work_threshold c = let proof_of_work_threshold c =
let constants = Raw_context.constants c in let constants = Raw_context.constants c in
constants.proof_of_work_threshold constants.proof_of_work_threshold

View File

@ -182,34 +182,20 @@ let () =
let failwith msg = fail (Failure msg) let failwith msg = fail (Failure msg)
let add_fees_for_bytes c base added =
let open Tez_repr in
let cost_per_byte = (Raw_context.constants c).cost_per_byte in
Lwt.return begin
cost_per_byte *? Int64.of_int added >>? fun added ->
base +? added
end
type big_map_diff = (string * Script_repr.expr option) list type big_map_diff = (string * Script_repr.expr option) list
let update_script_big_map c contract = function let update_script_big_map c contract = function
| None -> return (c, Tez_repr.zero, Tez_repr.zero) | None -> return (c, 0L)
| Some diff -> | Some diff ->
fold_left_s (fun (c, total_added, total_freed) (key, value) -> fold_left_s (fun (c, total) (key, value) ->
match value with match value with
| None -> | None ->
Storage.Contract.Big_map.remove (c, contract) key >>=? fun (c, freed) -> Storage.Contract.Big_map.remove (c, contract) key >>=? fun (c, freed) ->
add_fees_for_bytes c total_freed freed >>=? fun total_freed -> return (c, Int64.sub total (Int64.of_int freed))
return (c, total_added, total_freed)
| Some v -> | Some v ->
Storage.Contract.Big_map.init_set (c, contract) key v >>=? fun (c, diff) -> Storage.Contract.Big_map.init_set (c, contract) key v >>=? fun (c, size_diff) ->
if Compare.Int.(diff > 0) then return (c, Int64.add total (Int64.of_int size_diff)))
add_fees_for_bytes c total_added diff >>=? fun total_added -> (c, 0L) diff
return (c, total_added, total_freed)
else
add_fees_for_bytes c total_freed (-diff) >>=? fun total_freed ->
return (c, total_added, total_freed))
(c, Tez_repr.zero, Tez_repr.zero) diff
let create_base c contract let create_base c contract
~balance ~manager ~delegate ?script ~spendable ~delegatable = ~balance ~manager ~delegate ?script ~spendable ~delegatable =
@ -229,16 +215,13 @@ let create_base c contract
Storage.Contract.Counter.init c contract counter >>=? fun c -> Storage.Contract.Counter.init c contract counter >>=? fun c ->
(match script with (match script with
| Some ({ Script_repr.code ; storage }, big_map_diff) -> | Some ({ Script_repr.code ; storage }, big_map_diff) ->
let fees = Tez_repr.zero in
Storage.Contract.Code.init c contract code >>=? fun (c, code_size) -> Storage.Contract.Code.init c contract code >>=? fun (c, code_size) ->
add_fees_for_bytes c fees code_size >>=? fun fees ->
Storage.Contract.Storage.init c contract storage >>=? fun (c, storage_size) -> Storage.Contract.Storage.init c contract storage >>=? fun (c, storage_size) ->
add_fees_for_bytes c fees storage_size >>=? fun fees -> update_script_big_map c contract big_map_diff >>=? fun (c, big_map_size) ->
update_script_big_map c contract big_map_diff >>=? fun (c, total_added, total_freed) -> let total_size = Int64.add (Int64.add (Int64.of_int code_size) (Int64.of_int storage_size)) big_map_size in
assert (Tez_repr.equal total_freed Tez_repr.zero) ; assert Compare.Int64.(total_size >= 0L) ;
Lwt.return (Tez_repr.(fees +? total_added)) >>=? fun fees -> Storage.Contract.Used_storage_space.init c contract total_size >>=? fun c ->
Storage.Contract.Fees.init c contract fees >>=? fun c -> Storage.Contract.Paid_storage_space_fees.init c contract Tez_repr.zero
Storage.Contract.Paid_fees.init c contract Tez_repr.zero
| None -> | None ->
return c) >>=? fun c -> return c) >>=? fun c ->
return c return c
@ -260,8 +243,8 @@ let delete c contract =
Storage.Contract.Counter.delete c contract >>=? fun c -> Storage.Contract.Counter.delete c contract >>=? fun c ->
Storage.Contract.Code.remove c contract >>=? fun (c, _) -> Storage.Contract.Code.remove c contract >>=? fun (c, _) ->
Storage.Contract.Storage.remove c contract >>=? fun (c, _) -> Storage.Contract.Storage.remove c contract >>=? fun (c, _) ->
Storage.Contract.Paid_fees.remove c contract >>= fun c -> Storage.Contract.Paid_storage_space_fees.remove c contract >>= fun c ->
Storage.Contract.Fees.remove c contract >>= fun c -> Storage.Contract.Used_storage_space.remove c contract >>= fun c ->
Storage.Contract.Big_map.clear (c, contract) >>=? fun (c, _) -> Storage.Contract.Big_map.clear (c, contract) >>=? fun (c, _) ->
return c return c
@ -387,20 +370,11 @@ let is_spendable c contract =
Storage.Contract.Spendable.mem c contract >>= return Storage.Contract.Spendable.mem c contract >>= return
let update_script_storage c contract storage big_map_diff = let update_script_storage c contract storage big_map_diff =
update_script_big_map c contract big_map_diff >>=? fun (c, total_added, total_freed) -> update_script_big_map c contract big_map_diff >>=? fun (c, big_map_size_diff) ->
Storage.Contract.Storage.set c contract storage >>=? fun (c, diff) -> Storage.Contract.Storage.set c contract storage >>=? fun (c, size_diff) ->
begin if Compare.Int.(diff > 0) then Storage.Contract.Used_storage_space.get c contract >>=? fun previous_size ->
add_fees_for_bytes c total_added diff >>=? fun total_added -> let new_size = Int64.add previous_size (Int64.add big_map_size_diff (Int64.of_int size_diff)) in
return (c, total_added, total_freed) Storage.Contract.Used_storage_space.set c contract new_size
else
add_fees_for_bytes c total_freed (-diff) >>=? fun total_freed ->
return (c, total_added, total_freed)
end >>=? fun (c, total_added, total_freed) ->
Storage.Contract.Fees.get c contract >>=? fun fees ->
Lwt.return (Tez_repr.(fees +? total_added)) >>=? fun fees ->
Lwt.return (Tez_repr.(fees -? total_freed)) >>=? fun fees ->
Storage.Contract.Fees.set c contract fees >>=? fun c ->
return c
let spend_from_script c contract amount = let spend_from_script c contract amount =
Storage.Contract.Balance.get c contract >>=? fun balance -> Storage.Contract.Balance.get c contract >>=? fun balance ->
@ -467,23 +441,23 @@ let spend c contract amount =
let init c = let init c =
Storage.Contract.Global_counter.init c 0l Storage.Contract.Global_counter.init c 0l
let fees c contract = let used_storage_space c contract =
Storage.Contract.Fees.get_option c contract >>=? function Storage.Contract.Used_storage_space.get_option c contract >>=? function
| None -> return Tez_repr.zero | None -> return 0L
| Some fees -> return fees | Some fees -> return fees
let paid_fees c contract = let paid_storage_space_fees c contract =
Storage.Contract.Paid_fees.get_option c contract >>=? function Storage.Contract.Paid_storage_space_fees.get_option c contract >>=? function
| None -> return Tez_repr.zero | None -> return Tez_repr.zero
| Some paid_fees -> return paid_fees | Some paid_fees -> return paid_fees
let add_to_paid_fees c contract fees = let pay_for_storage_space c contract fees =
if Tez_repr.equal fees Tez_repr.zero then if Tez_repr.equal fees Tez_repr.zero then
return c return c
else else
Storage.Contract.Paid_fees.get c contract >>=? fun paid_fees -> Storage.Contract.Paid_storage_space_fees.get c contract >>=? fun paid_fees ->
Lwt.return (Tez_repr.(paid_fees +? fees)) >>=? fun paid_fees -> Lwt.return (Tez_repr.(paid_fees +? fees)) >>=? fun paid_fees ->
Storage.Contract.Paid_fees.set c contract paid_fees Storage.Contract.Paid_storage_space_fees.set c contract paid_fees
module Big_map = struct module Big_map = struct
let mem ctxt contract key = let mem ctxt contract key =

View File

@ -100,10 +100,9 @@ val originated_from_current_nonce :
val init: val init:
Raw_context.t -> Raw_context.t tzresult Lwt.t Raw_context.t -> Raw_context.t tzresult Lwt.t
val fees: Raw_context.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t val used_storage_space: Raw_context.t -> Contract_repr.t -> Int64.t tzresult Lwt.t
val paid_fees: Raw_context.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t val paid_storage_space_fees: Raw_context.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t
val pay_for_storage_space: Raw_context.t -> Contract_repr.t -> Tez_repr.t -> Raw_context.t tzresult Lwt.t
val add_to_paid_fees: Raw_context.t -> Contract_repr.t -> Tez_repr.t -> Raw_context.t tzresult Lwt.t
module Big_map : sig module Big_map : sig
val mem : val mem :

View File

@ -26,22 +26,26 @@ let () =
let origination_burn c ~payer contract = let origination_burn c ~payer contract =
let origination_burn = Constants.origination_burn c in let origination_burn = Constants.origination_burn c in
Contract.spend_from_script c payer origination_burn >>=? fun c -> Contract.spend_from_script c payer origination_burn >>=? fun c ->
Contract.fees c contract >>=? fun fees -> Contract.used_storage_space c contract >>=? fun size ->
let cost_per_byte = Constants.cost_per_byte c in
Lwt.return (Tez.(cost_per_byte *? size)) >>=? fun fees ->
trace Cannot_pay_storage_fee trace Cannot_pay_storage_fee
(Contract.spend_from_script c payer fees >>=? fun c -> (Contract.spend_from_script c payer fees >>=? fun c ->
Contract.add_to_paid_fees c contract fees) >>=? fun c -> Contract.pay_for_storage_space c contract fees) >>=? fun c ->
return (c, fees) return (c, size, fees)
let update_script_storage c ~payer contract = let update_script_storage c ~payer contract =
Contract.paid_fees c contract >>=? fun paid_fees -> Contract.paid_storage_space_fees c contract >>=? fun paid_fees ->
Contract.fees c contract >>=? fun fees -> Contract.used_storage_space c contract >>=? fun size ->
let cost_per_byte = Constants.cost_per_byte c in
Lwt.return (Tez.(cost_per_byte *? size)) >>=? fun fees ->
match Tez.(fees -? paid_fees) with match Tez.(fees -? paid_fees) with
| Error _ -> | Error _ ->
(* Previously paid fees are greater than required fees. *) (* Previously paid fees are greater than required fees. *)
return (c, Tez.zero) return (c, size, Tez.zero)
| Ok to_be_paid -> | Ok to_be_paid ->
(* Burning the fees... *) (* Burning the fees... *)
trace Cannot_pay_storage_fee trace Cannot_pay_storage_fee
(Contract.spend_from_script c payer to_be_paid >>=? fun c -> (Contract.spend_from_script c payer to_be_paid >>=? fun c ->
Contract.add_to_paid_fees c contract to_be_paid) >>=? fun c -> Contract.pay_for_storage_space c contract to_be_paid) >>=? fun c ->
return (c, to_be_paid) return (c, size, to_be_paid)

View File

@ -13,9 +13,9 @@ type error += Cannot_pay_storage_fee
val origination_burn: val origination_burn:
Alpha_context.t -> payer:Contract.t -> Alpha_context.t -> payer:Contract.t ->
Contract.t -> (Alpha_context.t * Tez.t) tzresult Lwt.t Contract.t -> (Alpha_context.t * Int64.t * Tez.t) tzresult Lwt.t
val update_script_storage: val update_script_storage:
Alpha_context.t -> payer:Contract.t -> Alpha_context.t -> payer:Contract.t ->
Contract.t -> (Alpha_context.t * Tez.t) tzresult Lwt.t Contract.t -> (Alpha_context.t * Int64.t * Tez.t) tzresult Lwt.t

View File

@ -19,6 +19,11 @@ module Int32 = struct
let encoding = Data_encoding.int32 let encoding = Data_encoding.int32
end end
module Int64 = struct
type t = Int64.t
let encoding = Data_encoding.int64
end
module Int_index = struct module Int_index = struct
type t = int type t = int
let path_length = 1 let path_length = 1
@ -161,15 +166,15 @@ module Contract = struct
let encoding = Script_repr.expr_encoding let encoding = Script_repr.expr_encoding
end)) end))
module Paid_fees = module Paid_storage_space_fees =
Indexed_context.Make_map Indexed_context.Make_map
(struct let name = ["paid_fees"] end) (struct let name = ["paid_bytes"] end)
(Make_value(Tez_repr)) (Make_value(Tez_repr))
module Fees = module Used_storage_space =
Indexed_context.Make_map Indexed_context.Make_map
(struct let name = ["fees"] end) (struct let name = ["used_bytes"] end)
(Make_value(Tez_repr)) (Make_value(Int64))
module Roll_list = module Roll_list =
Indexed_context.Make_map Indexed_context.Make_map

View File

@ -172,17 +172,15 @@ module Contract : sig
and type value = Script_repr.expr and type value = Script_repr.expr
and type t := Raw_context.t and type t := Raw_context.t
(** Exact cost of current storage. (** Current storage space in bytes.
Includes code, global storage and big map elements. Includes code, global storage and big map elements. *)
Always less than or equal to {!Paid_fees}. *) module Used_storage_space : Indexed_data_storage
module Fees : Indexed_data_storage
with type key = Contract_repr.t with type key = Contract_repr.t
and type value = Tez_repr.t and type value = Int64.t
and type t := Raw_context.t and type t := Raw_context.t
(** Maximum cost of storage since the contract's origination. (** Total fees burnt for storage space. *)
Always greater than or equal to {!Fees}. *) module Paid_storage_space_fees : Indexed_data_storage
module Paid_fees : Indexed_data_storage
with type key = Contract_repr.t with type key = Contract_repr.t
and type value = Tez_repr.t and type value = Tez_repr.t
and type t := Raw_context.t and type t := Raw_context.t