Alpha: receipts account for the paid storage space diff and storage space

This commit is contained in:
Pierre Chambart 2018-06-23 22:40:42 +02:00
parent 503e3c5679
commit d00cbaf081
8 changed files with 56 additions and 35 deletions

View File

@ -124,8 +124,8 @@ let estimated_storage_single
: kind Kind.manager contents_result) = : kind Kind.manager contents_result) =
let storage_size_diff (type kind) (result : kind manager_operation_result) = let storage_size_diff (type kind) (result : kind manager_operation_result) =
match result with match result with
| Applied (Transaction_result { storage_size_diff }) -> Ok storage_size_diff | Applied (Transaction_result { paid_storage_size_diff }) -> Ok paid_storage_size_diff
| Applied (Origination_result { storage_size_diff }) -> Ok storage_size_diff | Applied (Origination_result { paid_storage_size_diff }) -> Ok paid_storage_size_diff
| Applied Reveal_result -> Ok Z.zero | Applied Reveal_result -> Ok Z.zero
| Applied Delegation_result -> Ok Z.zero | Applied Delegation_result -> Ok Z.zero
| Skipped _ -> assert false | Skipped _ -> assert false

View File

@ -157,7 +157,8 @@ let pp_manager_operation_contents_and_result ppf
"This delegation was successfully applied" "This delegation was successfully applied"
| Applied (Transaction_result { balance_updates ; consumed_gas ; | Applied (Transaction_result { balance_updates ; consumed_gas ;
storage ; storage ;
originated_contracts ; storage_size_diff }) -> originated_contracts ;
storage_size ; paid_storage_size_diff }) ->
Format.fprintf ppf Format.fprintf ppf
"This transaction was successfully applied" ; "This transaction was successfully applied" ;
begin match originated_contracts with begin match originated_contracts with
@ -172,10 +173,15 @@ let pp_manager_operation_contents_and_result ppf
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_size_diff <> Z.zero then begin if storage_size <> Z.zero then
Format.fprintf ppf Format.fprintf ppf
"@,Storage size difference: %s bytes" "@,Storage size: %s bytes"
(Z.to_string storage_size_diff) (Z.to_string storage_size)
end ;
begin if paid_storage_size_diff <> Z.zero then
Format.fprintf ppf
"@,Paid storage size diff: %s bytes"
(Z.to_string paid_storage_size_diff)
end ; end ;
Format.fprintf ppf Format.fprintf ppf
"@,Consumed gas: %s" "@,Consumed gas: %s"
@ -188,7 +194,8 @@ let pp_manager_operation_contents_and_result ppf
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_size_diff }) -> originated_contracts ;
storage_size ; paid_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
@ -197,10 +204,15 @@ let pp_manager_operation_contents_and_result ppf
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_size_diff <> Z.zero then begin if storage_size <> Z.zero then
Format.fprintf ppf Format.fprintf ppf
"@,Storage size used: %s bytes" "@,Storage size: %s bytes"
(Z.to_string storage_size_diff) (Z.to_string storage_size)
end ;
begin if paid_storage_size_diff <> Z.zero then
Format.fprintf ppf
"@,Paid storage size diff: %s bytes"
(Z.to_string paid_storage_size_diff)
end ; end ;
Format.fprintf ppf Format.fprintf ppf
"@,Consumed gas: %s" "@,Consumed gas: %s"

View File

@ -900,7 +900,7 @@ module Fees : sig
context -> payer:Contract.t -> (context * Tez.t) tzresult Lwt.t context -> payer:Contract.t -> (context * Tez.t) tzresult Lwt.t
val record_paid_storage_space: val record_paid_storage_space:
context -> Contract.t -> (context * Z.t * Tez.t) tzresult Lwt.t context -> Contract.t -> (context * Z.t * Z.t * Tez.t) tzresult Lwt.t
val with_fees_for_storage: val with_fees_for_storage:
context -> payer:Contract.t -> context -> payer:Contract.t ->

View File

@ -379,7 +379,9 @@ let apply_manager_operation_content :
Contract destination, Credited amount ] ; Contract destination, Credited amount ] ;
originated_contracts = [] ; originated_contracts = [] ;
consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt ; consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt ;
storage_size_diff = Z.zero } in storage_size = Z.zero ;
paid_storage_size_diff = Z.zero ;
} in
return (ctxt, result, []) return (ctxt, result, [])
| Some script -> | Some script ->
begin match parameters with begin match parameters with
@ -395,11 +397,10 @@ let apply_manager_operation_content :
ctxt mode ctxt mode
~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.record_paid_storage_space Fees.record_paid_storage_space
ctxt destination >>=? fun (ctxt, new_size, fees) -> ctxt destination >>=? fun (ctxt, new_size, paid_storage_size_diff, fees) ->
Contract.originated_from_current_nonce Contract.originated_from_current_nonce
~since: before_operation ~since: before_operation
~until: ctxt >>=? fun originated_contracts -> ~until: ctxt >>=? fun originated_contracts ->
@ -413,7 +414,8 @@ let apply_manager_operation_content :
Contract destination, Credited amount ] ; Contract destination, Credited amount ] ;
originated_contracts ; originated_contracts ;
consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt ; consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt ;
storage_size_diff = Z.sub new_size old_size } in storage_size = new_size ;
paid_storage_size_diff } in
return (ctxt, result, operations) return (ctxt, result, operations)
end end
| Origination { manager ; delegate ; script ; preorigination ; | Origination { manager ; delegate ; script ; preorigination ;
@ -441,7 +443,7 @@ let apply_manager_operation_content :
?script ?script
~spendable ~delegatable >>=? fun ctxt -> ~spendable ~delegatable >>=? fun ctxt ->
Fees.origination_burn ctxt ~payer >>=? fun (ctxt, orignation_burn) -> Fees.origination_burn ctxt ~payer >>=? fun (ctxt, orignation_burn) ->
Fees.record_paid_storage_space ctxt contract >>=? fun (ctxt, size, fees) -> Fees.record_paid_storage_space ctxt contract >>=? fun (ctxt, size, paid_storage_size_diff, fees) ->
Lwt.return Tez.(orignation_burn +? fees) >>=? fun all_fees -> Lwt.return Tez.(orignation_burn +? fees) >>=? fun all_fees ->
let result = let result =
Origination_result Origination_result
@ -452,7 +454,8 @@ let apply_manager_operation_content :
Contract contract, Credited credit ] ; Contract contract, Credited credit ] ;
originated_contracts = [ contract ] ; originated_contracts = [ contract ] ;
consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt ; consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt ;
storage_size_diff = size } in storage_size = size ;
paid_storage_size_diff } 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

@ -112,13 +112,15 @@ 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_size_diff : Z.t ; storage_size : Z.t ;
paid_storage_size_diff : Z.t ;
} -> Kind.transaction successful_manager_operation_result } -> Kind.transaction successful_manager_operation_result
| Origination_result : | Origination_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_size_diff : Z.t ; storage_size : Z.t ;
paid_storage_size_diff : Z.t ;
} -> Kind.origination successful_manager_operation_result } -> Kind.origination successful_manager_operation_result
| Delegation_result : Kind.delegation successful_manager_operation_result | Delegation_result : Kind.delegation successful_manager_operation_result
@ -209,12 +211,13 @@ module Manager_result = struct
make make
~op_case: Operation.Encoding.Manager_operations.transaction_case ~op_case: Operation.Encoding.Manager_operations.transaction_case
~encoding: ~encoding:
(obj5 (obj6
(opt "storage" Script.expr_encoding) (opt "storage" Script.expr_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_size_diff" z Z.zero)) (dft "storage_size" z Z.zero)
(dft "paid_storage_size_diff" z Z.zero))
~iselect: ~iselect:
(function (function
| Internal_operation_result | Internal_operation_result
@ -231,27 +234,28 @@ module Manager_result = struct
| Transaction_result | Transaction_result
{ storage ; balance_updates ; { storage ; balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_size_diff } -> storage_size ; paid_storage_size_diff } ->
(storage, balance_updates, (storage, balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_size_diff)) storage_size, paid_storage_size_diff))
~inj: ~inj:
(fun (storage, balance_updates, (fun (storage, balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_size_diff) -> storage_size, paid_storage_size_diff) ->
Transaction_result { storage ; balance_updates ; Transaction_result { storage ; balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_size_diff }) storage_size ; paid_storage_size_diff })
let origination_case = let origination_case =
make make
~op_case: Operation.Encoding.Manager_operations.origination_case ~op_case: Operation.Encoding.Manager_operations.origination_case
~encoding: ~encoding:
(obj4 (obj5
(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_size_diff" z Z.zero)) (dft "storage_size" z Z.zero)
(dft "paid_storage_size_diff" z Z.zero))
~iselect: ~iselect:
(function (function
| Internal_operation_result | Internal_operation_result
@ -267,19 +271,19 @@ module Manager_result = struct
| Origination_result | Origination_result
{ balance_updates ; { balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_size_diff } -> storage_size ; paid_storage_size_diff } ->
(balance_updates, (balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_size_diff)) storage_size, paid_storage_size_diff))
~kind: Kind.Origination_manager_kind ~kind: Kind.Origination_manager_kind
~inj: ~inj:
(fun (balance_updates, (fun (balance_updates,
originated_contracts, consumed_gas, originated_contracts, consumed_gas,
storage_size_diff) -> storage_size, paid_storage_size_diff) ->
Origination_result Origination_result
{ balance_updates ; { balance_updates ;
originated_contracts ; consumed_gas ; originated_contracts ; consumed_gas ;
storage_size_diff }) storage_size ; paid_storage_size_diff })
let delegation_case = let delegation_case =
make make

View File

@ -90,13 +90,15 @@ 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_size_diff : Z.t ; storage_size : Z.t ;
paid_storage_size_diff : Z.t ;
} -> Kind.transaction successful_manager_operation_result } -> Kind.transaction successful_manager_operation_result
| Origination_result : | Origination_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_size_diff : Z.t ; storage_size : Z.t ;
paid_storage_size_diff : Z.t ;
} -> Kind.origination successful_manager_operation_result } -> Kind.origination successful_manager_operation_result
| Delegation_result : Kind.delegation successful_manager_operation_result | Delegation_result : Kind.delegation successful_manager_operation_result

View File

@ -32,7 +32,7 @@ let record_paid_storage_space c contract =
Lwt.return (Raw_context.update_storage_space_to_pay c to_be_paid) >>=? fun c -> Lwt.return (Raw_context.update_storage_space_to_pay c to_be_paid) >>=? fun c ->
let cost_per_byte = Constants_storage.cost_per_byte c in let cost_per_byte = Constants_storage.cost_per_byte c in
Lwt.return (Tez_repr.(cost_per_byte *? (Z.to_int64 to_be_paid))) >>=? fun to_burn -> Lwt.return (Tez_repr.(cost_per_byte *? (Z.to_int64 to_be_paid))) >>=? fun to_burn ->
return (c, size, to_burn) return (c, size, to_be_paid, to_burn)
let burn_fees_for_storage c ~payer = let burn_fees_for_storage c ~payer =
let c, storage_space_to_pay = Raw_context.clear_storage_space_to_pay c in let c, storage_space_to_pay = Raw_context.clear_storage_space_to_pay c in

View File

@ -15,7 +15,7 @@ val origination_burn:
(** The returned Tez quantity is for logging purpose only *) (** The returned Tez quantity is for logging purpose only *)
val record_paid_storage_space: val record_paid_storage_space:
Raw_context.t -> Contract_repr.t -> Raw_context.t -> Contract_repr.t ->
(Raw_context.t * Z.t * Tez_repr.t) tzresult Lwt.t (Raw_context.t * Z.t * Z.t * Tez_repr.t) tzresult Lwt.t
val with_fees_for_storage: val with_fees_for_storage:
Raw_context.t -> payer:Contract_repr.t -> Raw_context.t -> payer:Contract_repr.t ->