Alpha: fix gas consumption for manager operations

This commit is contained in:
Grégoire Henry 2018-11-23 20:24:11 +01:00 committed by Pierre Boutillier
parent ee722a237a
commit fa4b33aa47
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C
10 changed files with 61 additions and 41 deletions

View File

@ -132,7 +132,7 @@ init_contract_from_file () {
} }
bake () { bake () {
$client bake for bootstrap1 --max-priority 512 --minimal-timestamp --minimal-fees 0 --minimal-fees-per-byte 0 --minimal-fees-per-gas-unit 0 $client bake for bootstrap1 --max-priority 512 --minimal-timestamp --minimal-fees 0 --minimal-picotez-per-byte 0 --minimal-picotez-per-gas-unit 0
} }
bake_after () { bake_after () {

View File

@ -84,7 +84,7 @@ let reveal cctxt
let contents = let contents =
Single Single
(Manager_operation { source ; fee ; counter ; (Manager_operation { source ; fee ; counter ;
gas_limit = Z.zero ; storage_limit = Z.zero ; gas_limit = Z.of_int 10_000 ; storage_limit = Z.zero ;
operation = Reveal src_pk }) in operation = Reveal src_pk }) in
Injection.inject_operation cctxt ~chain ~block ?confirmations Injection.inject_operation cctxt ~chain ~block ?confirmations
?dry_run ?dry_run
@ -129,7 +129,7 @@ let originate_account
originate originate
cctxt ~chain ~block ?confirmations cctxt ~chain ~block ?confirmations
?dry_run ?dry_run
?branch ~source ~gas_limit:Z.zero ~src_pk ~src_sk ~fee origination ?branch ~source ~gas_limit:(Z.of_int 10_000) ~src_pk ~src_sk ~fee origination
let delegate_contract cctxt let delegate_contract cctxt
~chain ~block ?branch ?confirmations ~chain ~block ?branch ?confirmations
@ -140,7 +140,7 @@ let delegate_contract cctxt
Injection.inject_manager_operation Injection.inject_manager_operation
cctxt ~chain ~block ?confirmations cctxt ~chain ~block ?confirmations
?dry_run ?dry_run
?branch ~source ~fee ~gas_limit:Z.zero ~storage_limit:Z.zero ?branch ~source ~fee ~gas_limit:(Z.of_int 10_000) ~storage_limit:Z.zero
~src_pk ~src_sk operation >>=? fun res -> ~src_pk ~src_sk operation >>=? fun res ->
return res return res
@ -425,4 +425,4 @@ let display_receipt_for_operation
return_unit return_unit
| Some op -> | Some op ->
cctxt#message "%a" pp_operation op >>= fun () -> cctxt#message "%a" pp_operation op >>= fun () ->
return_unit return_unit

View File

@ -117,8 +117,8 @@ let estimated_gas_single
match result with match result with
| Applied (Transaction_result { consumed_gas }) -> Ok consumed_gas | Applied (Transaction_result { consumed_gas }) -> Ok consumed_gas
| Applied (Origination_result { consumed_gas }) -> Ok consumed_gas | Applied (Origination_result { consumed_gas }) -> Ok consumed_gas
| Applied Reveal_result -> Ok Z.zero | Applied (Reveal_result { consumed_gas }) -> Ok consumed_gas
| Applied Delegation_result -> Ok Z.zero | Applied (Delegation_result { consumed_gas }) -> Ok consumed_gas
| Skipped _ -> assert false | Skipped _ -> assert false
| Backtracked (_, None) -> Ok Z.zero (* there must be another error for this to happen *) | Backtracked (_, None) -> Ok Z.zero (* there must be another error for this to happen *)
| Backtracked (_, Some errs) -> Alpha_environment.wrap_error (Error errs) | Backtracked (_, Some errs) -> Alpha_environment.wrap_error (Error errs)
@ -154,8 +154,8 @@ let estimated_storage_single
Ok paid_storage_size_diff Ok paid_storage_size_diff
| Applied (Origination_result { paid_storage_size_diff }) -> | Applied (Origination_result { paid_storage_size_diff }) ->
Ok (Z.add paid_storage_size_diff origination_size) Ok (Z.add paid_storage_size_diff origination_size)
| 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
| Backtracked (_, None) -> Ok Z.zero (* there must be another error for this to happen *) | Backtracked (_, None) -> Ok Z.zero (* there must be another error for this to happen *)
| Backtracked (_, Some errs) -> Alpha_environment.wrap_error (Error errs) | Backtracked (_, Some errs) -> Alpha_environment.wrap_error (Error errs)
@ -188,8 +188,8 @@ let originated_contracts_single
match result with match result with
| Applied (Transaction_result { originated_contracts }) -> Ok originated_contracts | Applied (Transaction_result { originated_contracts }) -> Ok originated_contracts
| Applied (Origination_result { originated_contracts }) -> Ok originated_contracts | Applied (Origination_result { originated_contracts }) -> Ok originated_contracts
| Applied Reveal_result -> Ok [] | Applied (Reveal_result _) -> Ok []
| Applied Delegation_result -> Ok [] | Applied (Delegation_result _) -> Ok []
| Skipped _ -> assert false | Skipped _ -> assert false
| Backtracked (_, None) -> Ok [] (* there must be another error for this to happen *) | Backtracked (_, None) -> Ok [] (* there must be another error for this to happen *)
| Backtracked (_, Some errs) -> Alpha_environment.wrap_error (Error errs) | Backtracked (_, Some errs) -> Alpha_environment.wrap_error (Error errs)
@ -478,7 +478,7 @@ let inject_manager_operation
let contents = let contents =
Cons Cons
(Manager_operation { source ; fee = Tez.zero ; counter ; (Manager_operation { source ; fee = Tez.zero ; counter ;
gas_limit = Z.zero ; storage_limit = Z.zero ; gas_limit = Z.of_int 10_000 ; storage_limit = Z.zero ;
operation = Reveal src_pk }, operation = Reveal src_pk },
Single (Manager_operation { source ; fee ; counter = Z.succ counter ; Single (Manager_operation { source ; fee ; counter = Z.succ counter ;
gas_limit ; storage_limit ; operation })) in gas_limit ; storage_limit ; operation })) in

View File

@ -235,17 +235,23 @@ let pp_manager_operation_contents_and_result ppf
| Failed (_, _errs) -> | Failed (_, _errs) ->
Format.fprintf ppf Format.fprintf ppf
"This operation FAILED." "This operation FAILED."
| Applied Reveal_result -> | Applied (Reveal_result { consumed_gas }) ->
Format.fprintf ppf Format.fprintf ppf
"This revelation was successfully applied" "This revelation was successfully applied" ;
| Backtracked (Reveal_result, _) -> Format.fprintf ppf
"@,Consumed gas: %s"
(Z.to_string consumed_gas)
| Backtracked (Reveal_result _, _) ->
Format.fprintf ppf Format.fprintf ppf
"@[<v 0>This revelation was BACKTRACKED, \ "@[<v 0>This revelation was BACKTRACKED, \
its expected effects were NOT applied.@]" ; its expected effects were NOT applied.@]" ;
| Applied Delegation_result -> | Applied (Delegation_result { consumed_gas })->
Format.fprintf ppf Format.fprintf ppf
"This delegation was successfully applied" "This delegation was successfully applied" ;
| Backtracked (Delegation_result, _) -> Format.fprintf ppf
"@,Consumed gas: %s"
(Z.to_string consumed_gas)
| Backtracked (Delegation_result _, _) ->
Format.fprintf ppf Format.fprintf ppf
"@[<v 0>This delegation was BACKTRACKED, \ "@[<v 0>This delegation was BACKTRACKED, \
its expected effects were NOT applied.@]" ; its expected effects were NOT applied.@]" ;

View File

@ -367,10 +367,11 @@ let apply_manager_operation_content :
let set_delegate = let set_delegate =
(* Ignore the delegatable flag for smart contracts. *) (* Ignore the delegatable flag for smart contracts. *)
if internal then Delegate.set_from_script else Delegate.set in if internal then Delegate.set_from_script else Delegate.set in
Lwt.return (Gas.consume ctxt Michelson_v1_gas.Cost_of.manager_operation) >>=? fun ctxt ->
match operation with match operation with
| Reveal _ -> | Reveal _ ->
return (* No-op: action already performed by `precheck_manager_contents`. *) return (* No-op: action already performed by `precheck_manager_contents`. *)
(ctxt, (Reveal_result : kind successful_manager_operation_result), []) (ctxt, (Reveal_result { consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt } : kind successful_manager_operation_result), [])
| Transaction { amount ; parameters ; destination } -> begin | Transaction { amount ; parameters ; destination } -> begin
spend ctxt source amount >>=? fun ctxt -> spend ctxt source amount >>=? fun ctxt ->
begin match Contract.is_implicit destination with begin match Contract.is_implicit destination with
@ -501,7 +502,7 @@ let apply_manager_operation_content :
return (ctxt, result, []) return (ctxt, result, [])
| Delegation delegate -> | Delegation delegate ->
set_delegate ctxt source delegate >>=? fun ctxt -> set_delegate ctxt source delegate >>=? fun ctxt ->
return (ctxt, Delegation_result, []) return (ctxt, Delegation_result { consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt }, [])
let apply_internal_manager_operations ctxt mode ~payer ops = let apply_internal_manager_operations ctxt mode ~payer ops =
let rec apply ctxt applied worklist = let rec apply ctxt applied worklist =
@ -612,7 +613,7 @@ let skipped_operation_result
= function operation -> = function operation ->
match operation with match operation with
| Reveal _ -> | Reveal _ ->
Applied ( Reveal_result : kind successful_manager_operation_result ) Applied ( Reveal_result { consumed_gas = Z.zero } : kind successful_manager_operation_result )
| _ -> Skipped (manager_kind operation) | _ -> Skipped (manager_kind operation)
let rec mark_skipped let rec mark_skipped
@ -727,7 +728,7 @@ let mark_backtracked results =
: type kind. kind manager_operation_result -> kind manager_operation_result : type kind. kind manager_operation_result -> kind manager_operation_result
= function = function
| Failed _ | Skipped _ | Backtracked _ as result -> result | Failed _ | Skipped _ | Backtracked _ as result -> result
| Applied Reveal_result as result -> result | Applied (Reveal_result _) as result -> result
| Applied result -> Backtracked (result, None) in | Applied result -> Backtracked (result, None) in
mark_contents_list results mark_contents_list results

View File

@ -42,7 +42,9 @@ let error_encoding =
~binary:Error_monad.error_encoding ~binary:Error_monad.error_encoding
type _ successful_manager_operation_result = type _ successful_manager_operation_result =
| Reveal_result : Kind.reveal successful_manager_operation_result | Reveal_result :
{ consumed_gas : Z.t
} -> Kind.reveal successful_manager_operation_result
| Transaction_result : | Transaction_result :
{ storage : Script.expr option ; { storage : Script.expr option ;
big_map_diff : Contract.big_map_diff option ; big_map_diff : Contract.big_map_diff option ;
@ -60,7 +62,9 @@ type _ successful_manager_operation_result =
storage_size : Z.t ; storage_size : Z.t ;
paid_storage_size_diff : 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 :
{ consumed_gas : Z.t
} -> Kind.delegation successful_manager_operation_result
type packed_successful_manager_operation_result = type packed_successful_manager_operation_result =
| Successful_manager_result : | Successful_manager_result :
@ -146,7 +150,8 @@ module Manager_result = struct
let reveal_case = let reveal_case =
make make
~op_case: Operation.Encoding.Manager_operations.reveal_case ~op_case: Operation.Encoding.Manager_operations.reveal_case
~encoding: Data_encoding.empty ~encoding: Data_encoding.(obj1 (dft "consumed_gas" z Z.zero))
~iselect: ~iselect:
(function (function
| Internal_operation_result | Internal_operation_result
@ -155,11 +160,11 @@ module Manager_result = struct
| _ -> None) | _ -> None)
~select: ~select:
(function (function
| Successful_manager_result (Reveal_result as op) -> Some op | Successful_manager_result (Reveal_result _ as op) -> Some op
| _ -> None) | _ -> None)
~kind: Kind.Reveal_manager_kind ~kind: Kind.Reveal_manager_kind
~proj: (function Reveal_result -> ()) ~proj: (function Reveal_result { consumed_gas } -> consumed_gas)
~inj: (fun () -> Reveal_result) ~inj: (fun consumed_gas -> Reveal_result { consumed_gas })
let transaction_case = let transaction_case =
make make
@ -248,7 +253,7 @@ module Manager_result = struct
let delegation_case = let delegation_case =
make make
~op_case: Operation.Encoding.Manager_operations.delegation_case ~op_case: Operation.Encoding.Manager_operations.delegation_case
~encoding: Data_encoding.empty ~encoding: Data_encoding.(obj1 (dft "consumed_gas" z Z.zero))
~iselect: ~iselect:
(function (function
| Internal_operation_result | Internal_operation_result
@ -257,11 +262,11 @@ module Manager_result = struct
| _ -> None) | _ -> None)
~select: ~select:
(function (function
| Successful_manager_result (Delegation_result as op) -> Some op | Successful_manager_result (Delegation_result _ as op) -> Some op
| _ -> None) | _ -> None)
~kind: Kind.Delegation_manager_kind ~kind: Kind.Delegation_manager_kind
~proj: (function Delegation_result -> ()) ~proj: (function Delegation_result { consumed_gas } -> consumed_gas)
~inj: (fun () -> Delegation_result) ~inj: (fun consumed_gas -> Delegation_result { consumed_gas })
end end
@ -770,11 +775,11 @@ let kind_equal
| Manager_operation | Manager_operation
{ operation = Reveal _ ; _ }, { operation = Reveal _ ; _ },
Manager_operation_result Manager_operation_result
{ operation_result = Applied Reveal_result ; _ } -> Some Eq { operation_result = Applied (Reveal_result _); _ } -> Some Eq
| Manager_operation | Manager_operation
{ operation = Reveal _ ; _ }, { operation = Reveal _ ; _ },
Manager_operation_result Manager_operation_result
{ operation_result = Backtracked (Reveal_result, _) ; _ } -> Some Eq { operation_result = Backtracked (Reveal_result _, _) ; _ } -> Some Eq
| Manager_operation | Manager_operation
{ operation = Reveal _ ; _ }, { operation = Reveal _ ; _ },
Manager_operation_result Manager_operation_result
@ -827,11 +832,11 @@ let kind_equal
| Manager_operation | Manager_operation
{ operation = Delegation _ ; _ }, { operation = Delegation _ ; _ },
Manager_operation_result Manager_operation_result
{ operation_result = Applied Delegation_result ; _ } -> Some Eq { operation_result = Applied (Delegation_result _) ; _ } -> Some Eq
| Manager_operation | Manager_operation
{ operation = Delegation _ ; _ }, { operation = Delegation _ ; _ },
Manager_operation_result Manager_operation_result
{ operation_result = Backtracked (Delegation_result, _) ; _ } -> Some Eq { operation_result = Backtracked (Delegation_result _, _) ; _ } -> Some Eq
| Manager_operation | Manager_operation
{ operation = Delegation _ ; _ }, { operation = Delegation _ ; _ },
Manager_operation_result Manager_operation_result

View File

@ -86,7 +86,9 @@ and 'kind manager_operation_result =
(** Result of applying a {!manager_operation_content}, either internal (** Result of applying a {!manager_operation_content}, either internal
or external. *) or external. *)
and _ successful_manager_operation_result = and _ successful_manager_operation_result =
| Reveal_result : Kind.reveal successful_manager_operation_result | Reveal_result :
{ consumed_gas : Z.t
} -> Kind.reveal successful_manager_operation_result
| Transaction_result : | Transaction_result :
{ storage : Script.expr option ; { storage : Script.expr option ;
big_map_diff : Contract.big_map_diff option ; big_map_diff : Contract.big_map_diff option ;
@ -104,7 +106,9 @@ and _ successful_manager_operation_result =
storage_size : Z.t ; storage_size : Z.t ;
paid_storage_size_diff : 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 :
{ consumed_gas : Z.t
} -> Kind.delegation successful_manager_operation_result
and packed_successful_manager_operation_result = and packed_successful_manager_operation_result =
| Successful_manager_result : | Successful_manager_result :

View File

@ -235,6 +235,8 @@ module Cost_of = struct
let compare_timestamp t1 t2 = compare_zint (Script_timestamp.to_zint t1) (Script_timestamp.to_zint t2) let compare_timestamp t1 t2 = compare_zint (Script_timestamp.to_zint t1) (Script_timestamp.to_zint t2)
let compare_address _ _ = step_cost 20 let compare_address _ _ = step_cost 20
let manager_operation = step_cost 10_000
module Typechecking = struct module Typechecking = struct
let cycle = step_cost 1 let cycle = step_cost 1
let bool = free let bool = free

View File

@ -111,6 +111,8 @@ module Cost_of : sig
val compare_timestamp : Script_timestamp.t -> Script_timestamp.t -> Gas.cost val compare_timestamp : Script_timestamp.t -> Script_timestamp.t -> Gas.cost
val compare_address : Contract.t -> Contract.t -> Gas.cost val compare_address : Contract.t -> Contract.t -> Gas.cost
val manager_operation : Gas.cost
module Typechecking : sig module Typechecking : sig
val cycle : Gas.cost val cycle : Gas.cost
val unit : Gas.cost val unit : Gas.cost

View File

@ -98,7 +98,7 @@ let combine_operations
fee = Tez.zero ; fee = Tez.zero ;
counter ; counter ;
operation = Reveal public_key ; operation = Reveal public_key ;
gas_limit = Z.of_int 20 ; gas_limit = Z.of_int 10000 ;
storage_limit = Z.zero ; storage_limit = Z.zero ;
} in } in
return (Some (Contents reveal_op), Z.succ counter) return (Some (Contents reveal_op), Z.succ counter)
@ -153,7 +153,7 @@ let manager_operation
fee = Tez.zero ; fee = Tez.zero ;
counter ; counter ;
operation = Reveal public_key ; operation = Reveal public_key ;
gas_limit = Z.of_int 20 ; gas_limit = Z.of_int 10000 ;
storage_limit = Z.zero ; storage_limit = Z.zero ;
} in } in
let op = let op =
@ -181,7 +181,7 @@ let revelation ctxt public_key =
fee = Tez.zero ; fee = Tez.zero ;
counter ; counter ;
operation = Reveal public_key ; operation = Reveal public_key ;
gas_limit = Z.of_int 20 ; gas_limit = Z.of_int 10000 ;
storage_limit = Z.zero ; storage_limit = Z.zero ;
})) in })) in
return @@ sign account.sk ctxt sop return @@ sign account.sk ctxt sop