Alpha/Baker: use picotez for minimal_fees_per_{gas_unit,byte}

This commit is contained in:
Grégoire Henry 2018-11-23 17:08:45 +01:00 committed by Pierre Boutillier
parent e3111bc574
commit ee722a237a
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C
9 changed files with 74 additions and 75 deletions

View File

@ -256,25 +256,23 @@ let minimal_fees_arg =
| Some t -> return t | Some t -> return t
| None -> fail (Bad_minimal_fees s))) | None -> fail (Bad_minimal_fees s)))
let minimal_fees_per_gas_unit_arg = let minimal_picotez_per_gas_unit_arg =
arg arg
~long:"minimal-fees-per-gas-unit" ~long:"minimal-picotez-per-gas-unit"
~placeholder:"amount" ~placeholder:"amount"
~doc:"exclude operations with fees per gas lower than this threshold (in tez)" ~doc:"exclude operations with fees per gas lower than this threshold (in picotez)"
(parameter (fun _ s -> (parameter (fun _ s ->
match Tez.of_string s with try return (Z.of_string s)
| Some t -> return t with _ -> fail (Bad_minimal_fees s)))
| None -> fail (Bad_minimal_fees s)))
let minimal_fees_per_byte_arg = let minimal_picotez_per_byte_arg =
arg arg
~long:"minimal-fees-per-byte" ~long:"minimal-picotez-per-byte"
~placeholder:"amount" ~placeholder:"amount"
~doc:"exclude operations with fees per byte lower than this threshold (in tez)" ~doc:"exclude operations with fees per byte lower than this threshold (in tez)"
(parameter (fun _ s -> (parameter (fun _ s ->
match Tez.of_string s with try return (Z.of_string s)
| Some t -> return t with _ -> fail (Bad_minimal_fees s)))
| None -> fail (Bad_minimal_fees s)))
let no_waiting_for_endorsements_arg = let no_waiting_for_endorsements_arg =
switch switch

View File

@ -41,8 +41,8 @@ val delegatable_switch: (bool, Proto_alpha.full) Clic.arg
val spendable_switch: (bool, Proto_alpha.full) Clic.arg val spendable_switch: (bool, Proto_alpha.full) Clic.arg
val max_priority_arg: (int option, Proto_alpha.full) Clic.arg val max_priority_arg: (int option, Proto_alpha.full) Clic.arg
val minimal_fees_arg: (Tez.tez option, Proto_alpha.full) Clic.arg val minimal_fees_arg: (Tez.tez option, Proto_alpha.full) Clic.arg
val minimal_fees_per_gas_unit_arg: (Tez.tez option, Proto_alpha.full) Clic.arg val minimal_picotez_per_gas_unit_arg: (Z.t option, Proto_alpha.full) Clic.arg
val minimal_fees_per_byte_arg: (Tez.tez option, Proto_alpha.full) Clic.arg val minimal_picotez_per_byte_arg: (Z.t option, Proto_alpha.full) Clic.arg
val no_waiting_for_endorsements_arg: (bool, Proto_alpha.full) Clic.arg val no_waiting_for_endorsements_arg: (bool, Proto_alpha.full) Clic.arg
val await_endorsements_arg: (bool, Proto_alpha.full) Clic.arg val await_endorsements_arg: (bool, Proto_alpha.full) Clic.arg
val force_switch: (bool, Proto_alpha.full) Clic.arg val force_switch: (bool, Proto_alpha.full) Clic.arg

View File

@ -41,9 +41,8 @@ let managers_index = 3
let default_max_priority = 64 let default_max_priority = 64
let default_minimal_fees = Tez.zero let default_minimal_fees = Tez.zero
let default_minimal_fees_per_gas_unit = let default_minimal_picotez_per_gas_unit = Z.of_int 10000
Option.unopt_exn (Failure "bad conversion") (Tez.of_mutez 10L) let default_minimal_picotez_per_byte = Z.zero
let default_minimal_fees_per_byte = Tez.zero
let default_await_endorsements = true let default_await_endorsements = true
type state = { type state = {
@ -57,9 +56,9 @@ type state = {
(* Minimal operation fee required to include an operation in a block *) (* Minimal operation fee required to include an operation in a block *)
minimal_fees : Tez.t ; minimal_fees : Tez.t ;
(* Minimal operation fee per gas required to include an operation in a block *) (* Minimal operation fee per gas required to include an operation in a block *)
minimal_fees_per_gas_unit : Tez.t ; minimal_picotez_per_gas_unit : Z.t ;
(* Minimal operation fee per byte required to include an operation in a block *) (* Minimal operation fee per byte required to include an operation in a block *)
minimal_fees_per_byte : Tez.t ; minimal_picotez_per_byte : Z.t ;
(* Await endorsements *) (* Await endorsements *)
await_endorsements: bool ; await_endorsements: bool ;
(* truly mutable *) (* truly mutable *)
@ -68,8 +67,8 @@ type state = {
let create_state let create_state
?(minimal_fees = default_minimal_fees) ?(minimal_fees = default_minimal_fees)
?(minimal_fees_per_gas_unit = default_minimal_fees_per_gas_unit) ?(minimal_picotez_per_gas_unit = default_minimal_picotez_per_gas_unit)
?(minimal_fees_per_byte = default_minimal_fees_per_byte) ?(minimal_picotez_per_byte = default_minimal_picotez_per_byte)
?(await_endorsements = default_await_endorsements) ?(await_endorsements = default_await_endorsements)
genesis context_path index delegates constants = genesis context_path index delegates constants =
{ genesis ; { genesis ;
@ -78,8 +77,8 @@ let create_state
delegates ; delegates ;
constants ; constants ;
minimal_fees ; minimal_fees ;
minimal_fees_per_gas_unit ; minimal_picotez_per_gas_unit ;
minimal_fees_per_byte ; minimal_picotez_per_byte ;
await_endorsements ; await_endorsements ;
best_slot = None ; best_slot = None ;
} }
@ -192,8 +191,8 @@ let sort_manager_operations
~max_size ~max_size
~hard_gas_limit_per_block ~hard_gas_limit_per_block
~minimal_fees ~minimal_fees
~minimal_fees_per_gas_unit ~minimal_picotez_per_gas_unit
~minimal_fees_per_byte ~minimal_picotez_per_byte
(operations : Proto_alpha.operation list) = (operations : Proto_alpha.operation list) =
let compute_weight op (fee, gas) = let compute_weight op (fee, gas) =
let size = Data_encoding.Binary.length Operation.encoding op in let size = Data_encoding.Binary.length Operation.encoding op in
@ -212,15 +211,17 @@ let sort_manager_operations
else else
let (size, gas, _ratio) as weight = compute_weight op (fee, gas) in let (size, gas, _ratio) as weight = compute_weight op (fee, gas) in
let open Alpha_environment in let open Alpha_environment in
let enough_gas_fees = let fees_in_picotez =
match Tez.(minimal_fees_per_gas_unit *? Z.to_int64 gas) with Z.mul (Z.of_int64 (Tez.to_mutez fee)) (Z.of_int 1000) in
| Ok expected_fees -> Tez.(expected_fees <= fee) let enough_fees_for_gas =
| _ -> false in let minimal_fees_in_picotez =
let enough_size_fees = Z.mul minimal_picotez_per_gas_unit gas in
match Tez.(minimal_fees_per_byte *? Int64.of_int size) with Z.compare minimal_fees_in_picotez fees_in_picotez <= 0 in
| Ok fee_per_byte -> Tez.(fee_per_byte >= minimal_fees_per_byte) let enough_fees_for_size =
| Error _ -> false in let minimal_fees_in_picotez =
if enough_size_fees && enough_gas_fees then Z.mul minimal_picotez_per_byte (Z.of_int size) in
Z.compare minimal_fees_in_picotez fees_in_picotez <= 0 in
if enough_fees_for_size && enough_fees_for_gas then
return_some (op, weight) return_some (op, weight)
else else
return_none return_none
@ -283,8 +284,8 @@ let classify_operations
~block ~block
~hard_gas_limit_per_block ~hard_gas_limit_per_block
~minimal_fees ~minimal_fees
~minimal_fees_per_gas_unit ~minimal_picotez_per_gas_unit
~minimal_fees_per_byte ~minimal_picotez_per_byte
(ops: Proto_alpha.operation list) = (ops: Proto_alpha.operation list) =
Alpha_block_services.live_blocks cctxt ~chain:`Main ~block () Alpha_block_services.live_blocks cctxt ~chain:`Main ~block ()
>>=? fun live_blocks -> >>=? fun live_blocks ->
@ -311,8 +312,8 @@ let classify_operations
~max_size ~max_size
~hard_gas_limit_per_block ~hard_gas_limit_per_block
~minimal_fees ~minimal_fees
~minimal_fees_per_gas_unit ~minimal_picotez_per_gas_unit
~minimal_fees_per_byte ~minimal_picotez_per_byte
manager_operations manager_operations
>>=? fun ordered_operations -> >>=? fun ordered_operations ->
(* Greedy heuristic *) (* Greedy heuristic *)
@ -574,8 +575,8 @@ let forge_block
?(best_effort = operations = None) ?(best_effort = operations = None)
?(sort = best_effort) ?(sort = best_effort)
?(minimal_fees = default_minimal_fees) ?(minimal_fees = default_minimal_fees)
?(minimal_fees_per_gas_unit = default_minimal_fees_per_gas_unit) ?(minimal_picotez_per_gas_unit = default_minimal_picotez_per_gas_unit)
?(minimal_fees_per_byte = default_minimal_fees_per_byte) ?(minimal_picotez_per_byte = default_minimal_picotez_per_byte)
?(await_endorsements = default_await_endorsements) ?(await_endorsements = default_await_endorsements)
?timestamp ?timestamp
?mempool ?mempool
@ -598,8 +599,8 @@ let forge_block
~hard_gas_limit_per_block ~hard_gas_limit_per_block
~block:block ~block:block
~minimal_fees ~minimal_fees
~minimal_fees_per_gas_unit ~minimal_picotez_per_gas_unit
~minimal_fees_per_byte ~minimal_picotez_per_byte
operations_arg operations_arg
>>=? fun (operations, overflowing_ops) -> >>=? fun (operations, overflowing_ops) ->
(* Ensure that we retain operations up to the quota *) (* Ensure that we retain operations up to the quota *)
@ -649,8 +650,8 @@ let forge_block
best_slot = None ; best_slot = None ;
await_endorsements ; await_endorsements ;
minimal_fees = default_minimal_fees ; minimal_fees = default_minimal_fees ;
minimal_fees_per_gas_unit = default_minimal_fees_per_gas_unit ; minimal_picotez_per_gas_unit = default_minimal_picotez_per_gas_unit ;
minimal_fees_per_byte = default_minimal_fees_per_byte ; minimal_picotez_per_byte = default_minimal_picotez_per_byte ;
} in } in
filter_and_apply_operations ~timestamp ~protocol_data state bi (operations, overflowing_ops) filter_and_apply_operations ~timestamp ~protocol_data state bi (operations, overflowing_ops)
>>=? fun (final_context, validation_result, operations) -> >>=? fun (final_context, validation_result, operations) ->
@ -881,8 +882,8 @@ let build_block
classify_operations cctxt classify_operations cctxt
~hard_gas_limit_per_block ~hard_gas_limit_per_block
~minimal_fees:state.minimal_fees ~minimal_fees:state.minimal_fees
~minimal_fees_per_gas_unit:state.minimal_fees_per_gas_unit ~minimal_picotez_per_gas_unit:state.minimal_picotez_per_gas_unit
~minimal_fees_per_byte:state.minimal_fees_per_byte ~minimal_picotez_per_byte:state.minimal_picotez_per_byte
~block operations ~block operations
>>=? fun (operations, overflowing_ops) -> >>=? fun (operations, overflowing_ops) ->
let next_version = let next_version =
@ -1158,8 +1159,8 @@ let reveal_potential_nonces cctxt new_head =
let create let create
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
?minimal_fees ?minimal_fees
?minimal_fees_per_gas_unit ?minimal_picotez_per_gas_unit
?minimal_fees_per_byte ?minimal_picotez_per_byte
?await_endorsements ?await_endorsements
?max_priority ?max_priority
~context_path ~context_path
@ -1171,7 +1172,7 @@ let create
Client_baking_simulator.load_context ~context_path >>= fun index -> Client_baking_simulator.load_context ~context_path >>= fun index ->
Client_baking_simulator.check_context_consistency index bi.context >>=? fun () -> Client_baking_simulator.check_context_consistency index bi.context >>=? fun () ->
let state = create_state let state = create_state
?minimal_fees ?minimal_fees_per_gas_unit ?minimal_fees_per_byte ?minimal_fees ?minimal_picotez_per_gas_unit ?minimal_picotez_per_byte
?await_endorsements ?await_endorsements
genesis_hash context_path index delegates constants in genesis_hash context_path index delegates constants in
return state return state

View File

@ -72,8 +72,8 @@ val forge_block:
?best_effort:bool -> ?best_effort:bool ->
?sort:bool -> ?sort:bool ->
?minimal_fees: Tez.t -> ?minimal_fees: Tez.t ->
?minimal_fees_per_gas_unit: Tez.t -> ?minimal_picotez_per_gas_unit: Z.t ->
?minimal_fees_per_byte: Tez.t -> ?minimal_picotez_per_byte: Z.t ->
?await_endorsements: bool -> ?await_endorsements: bool ->
?timestamp:Time.t -> ?timestamp:Time.t ->
?mempool:string -> ?mempool:string ->
@ -107,8 +107,8 @@ val forge_block:
val create: val create:
#Proto_alpha.full -> #Proto_alpha.full ->
?minimal_fees: Tez.t -> ?minimal_fees: Tez.t ->
?minimal_fees_per_gas_unit: Tez.t -> ?minimal_picotez_per_gas_unit: Z.t ->
?minimal_fees_per_byte: Tez.t -> ?minimal_picotez_per_byte: Z.t ->
?await_endorsements: bool -> ?await_endorsements: bool ->
?max_priority: int -> ?max_priority: int ->
context_path: string -> context_path: string ->

View File

@ -30,8 +30,8 @@ let bake_block
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
?(chain = `Main) ?(chain = `Main)
?minimal_fees ?minimal_fees
?minimal_fees_per_gas_unit ?minimal_picotez_per_gas_unit
?minimal_fees_per_byte ?minimal_picotez_per_byte
?(await_endorsements = false) ?(await_endorsements = false)
?force ?force
?max_priority ?max_priority
@ -68,8 +68,8 @@ let bake_block
Client_baking_forge.forge_block cctxt Client_baking_forge.forge_block cctxt
?force ?force
?minimal_fees ?minimal_fees
?minimal_fees_per_gas_unit ?minimal_picotez_per_gas_unit
?minimal_fees_per_byte ?minimal_picotez_per_byte
~await_endorsements ~await_endorsements
?timestamp:(if minimal_timestamp then None else Some (Time.now ())) ?timestamp:(if minimal_timestamp then None else Some (Time.now ()))
?seed_nonce_hash ?seed_nonce_hash

View File

@ -31,8 +31,8 @@ val bake_block:
#Proto_alpha.full -> #Proto_alpha.full ->
?chain:Chain_services.chain -> ?chain:Chain_services.chain ->
?minimal_fees: Tez.t -> ?minimal_fees: Tez.t ->
?minimal_fees_per_gas_unit: Tez.t -> ?minimal_picotez_per_gas_unit: Z.t ->
?minimal_fees_per_byte: Tez.t -> ?minimal_picotez_per_byte: Z.t ->
?await_endorsements: bool -> ?await_endorsements: bool ->
?force:bool -> ?force:bool ->
?max_priority: int -> ?max_priority: int ->

View File

@ -49,8 +49,8 @@ module Baker = struct
let run let run
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
?minimal_fees ?minimal_fees
?minimal_fees_per_gas_unit ?minimal_picotez_per_gas_unit
?minimal_fees_per_byte ?minimal_picotez_per_byte
?await_endorsements ?await_endorsements
?max_priority ?max_priority
~context_path ~context_path
@ -62,8 +62,8 @@ module Baker = struct
cctxt#message "Baker started." >>= fun () -> cctxt#message "Baker started." >>= fun () ->
Client_baking_forge.create cctxt Client_baking_forge.create cctxt
?minimal_fees ?minimal_fees
?minimal_fees_per_gas_unit ?minimal_picotez_per_gas_unit
?minimal_fees_per_byte ?minimal_picotez_per_byte
?await_endorsements ?await_endorsements
?max_priority ?max_priority
~context_path delegates block_stream >>=? fun () -> ~context_path delegates block_stream >>=? fun () ->

View File

@ -37,8 +37,8 @@ module Baker : sig
val run: val run:
#Proto_alpha.full -> #Proto_alpha.full ->
?minimal_fees: Tez.t -> ?minimal_fees: Tez.t ->
?minimal_fees_per_gas_unit: Tez.t -> ?minimal_picotez_per_gas_unit: Z.t ->
?minimal_fees_per_byte: Tez.t -> ?minimal_picotez_per_byte: Z.t ->
?await_endorsements: bool -> ?await_endorsements: bool ->
?max_priority: int -> ?max_priority: int ->
context_path: string -> context_path: string ->

View File

@ -58,8 +58,8 @@ let delegate_commands () =
(args9 (args9
max_priority_arg max_priority_arg
minimal_fees_arg minimal_fees_arg
minimal_fees_per_gas_unit_arg minimal_picotez_per_gas_unit_arg
minimal_fees_per_byte_arg minimal_picotez_per_byte_arg
await_endorsements_arg await_endorsements_arg
force_switch force_switch
minimal_timestamp_switch minimal_timestamp_switch
@ -70,14 +70,14 @@ let delegate_commands () =
~name:"baker" ~desc: "name of the delegate owning the baking right" ~name:"baker" ~desc: "name of the delegate owning the baking right"
@@ stop) @@ stop)
(fun (max_priority, minimal_fees, (fun (max_priority, minimal_fees,
minimal_fees_per_gas_unit, minimal_fees_per_byte, minimal_picotez_per_gas_unit, minimal_picotez_per_byte,
await_endorsements, force, await_endorsements, force,
minimal_timestamp, mempool, context_path) minimal_timestamp, mempool, context_path)
delegate cctxt -> delegate cctxt ->
bake_block cctxt cctxt#block bake_block cctxt cctxt#block
?minimal_fees ?minimal_fees
?minimal_fees_per_gas_unit ?minimal_picotez_per_gas_unit
?minimal_fees_per_byte ?minimal_picotez_per_byte
~await_endorsements ~await_endorsements
~force ?max_priority ~minimal_timestamp ~force ?max_priority ~minimal_timestamp
?mempool ?context_path delegate) ; ?mempool ?context_path delegate) ;
@ -113,8 +113,8 @@ let baker_commands () =
(args5 (args5
max_priority_arg max_priority_arg
minimal_fees_arg minimal_fees_arg
minimal_fees_per_gas_unit_arg minimal_picotez_per_gas_unit_arg
minimal_fees_per_byte_arg minimal_picotez_per_byte_arg
no_waiting_for_endorsements_arg) no_waiting_for_endorsements_arg)
(prefixes [ "run" ; "with" ; "local" ; "node" ] (prefixes [ "run" ; "with" ; "local" ; "node" ]
@@ param @@ param
@ -122,15 +122,15 @@ let baker_commands () =
~desc:"Path to the node data directory (e.g. $HOME/.tezos-node)" ~desc:"Path to the node data directory (e.g. $HOME/.tezos-node)"
directory_parameter directory_parameter
@@ seq_of_param Client_keys.Public_key_hash.alias_param) @@ seq_of_param Client_keys.Public_key_hash.alias_param)
(fun (max_priority, minimal_fees, minimal_fees_per_gas_unit, (fun (max_priority, minimal_fees, minimal_picotez_per_gas_unit,
minimal_fees_per_byte, no_waiting_for_endorsements) minimal_picotez_per_byte, no_waiting_for_endorsements)
node_path delegates cctxt -> node_path delegates cctxt ->
Tezos_signer_backends.Encrypted.decrypt_list Tezos_signer_backends.Encrypted.decrypt_list
cctxt (List.map fst delegates) >>=? fun () -> cctxt (List.map fst delegates) >>=? fun () ->
Client_daemon.Baker.run cctxt Client_daemon.Baker.run cctxt
?minimal_fees ?minimal_fees
?minimal_fees_per_gas_unit ?minimal_picotez_per_gas_unit
?minimal_fees_per_byte ?minimal_picotez_per_byte
?max_priority ?max_priority
~await_endorsements:(not no_waiting_for_endorsements) ~await_endorsements:(not no_waiting_for_endorsements)
~context_path:(Filename.concat node_path "context") ~context_path:(Filename.concat node_path "context")