Alpha/Baker: rename threshold into fee_threshold and include it in the baker's state

This commit is contained in:
Vincent Botbol 2018-08-08 13:35:12 +02:00 committed by Grégoire Henry
parent 618dc5757c
commit bb82702fd6
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2
7 changed files with 59 additions and 38 deletions

View File

@ -48,18 +48,22 @@ type state = {
(* lazy-initialisation with retry-on-error *) (* lazy-initialisation with retry-on-error *)
constants: Constants.t tzlazy ; constants: Constants.t tzlazy ;
(* Minimum operation fee required to include in a block *)
fee_threshold : Tez.t ;
(* truly mutable *) (* truly mutable *)
mutable best: Client_baking_blocks.block_info ; mutable best: Client_baking_blocks.block_info ;
mutable future_slots: mutable future_slots:
(Time.t * (Client_baking_blocks.block_info * int * public_key_hash)) list ; (Time.t * (Client_baking_blocks.block_info * int * public_key_hash)) list ;
} }
let create_state genesis context_path index delegates constants best = let create_state genesis context_path index delegates constants ?(fee_threshold = Tez.zero) best =
{ genesis ; { genesis ;
context_path ; context_path ;
index ; index ;
delegates ; delegates ;
constants ; constants ;
fee_threshold ;
best ; best ;
future_slots = [] ; future_slots = [] ;
} }
@ -163,7 +167,7 @@ let get_manager_operation_gas_and_fee op =
let sort_manager_operations let sort_manager_operations
~max_size ~max_size
~hard_gas_limit_per_block ~hard_gas_limit_per_block
?(threshold = Tez.zero) ~fee_threshold
(operations : Proto_alpha.operation list) (operations : Proto_alpha.operation list)
= =
let compute_weight op (fee, gas) = let compute_weight op (fee, gas) =
@ -178,7 +182,7 @@ let sort_manager_operations
filter_map_s filter_map_s
(fun op -> (fun op ->
get_manager_operation_gas_and_fee op >>=? fun (fee, gas) -> get_manager_operation_gas_and_fee op >>=? fun (fee, gas) ->
if Tez.(<) fee threshold then if Tez.(<) fee fee_threshold then
return_none return_none
else else
return (Some (op, (compute_weight op (fee, gas)))) return (Some (op, (compute_weight op (fee, gas))))
@ -230,9 +234,9 @@ let trim_manager_operations ~max_size ~hard_gas_limit_per_block manager_operatio
(* Hypothesis : we suppose that the received manager operations have a valid gas_limit *) (* Hypothesis : we suppose that the received manager operations have a valid gas_limit *)
let classify_operations let classify_operations
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
?threshold
~block ~block
~hard_gas_limit_per_block ~hard_gas_limit_per_block
~fee_threshold
(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 ->
@ -255,7 +259,7 @@ let classify_operations
let manager_operations = t.(managers_index) in let manager_operations = t.(managers_index) in
let { Alpha_environment.Updater.max_size } = let { Alpha_environment.Updater.max_size } =
List.nth Proto_alpha.Main.validation_passes managers_index in List.nth Proto_alpha.Main.validation_passes managers_index in
sort_manager_operations ~max_size ~hard_gas_limit_per_block ?threshold manager_operations sort_manager_operations ~max_size ~hard_gas_limit_per_block ~fee_threshold manager_operations
>>=? fun ordered_operations -> >>=? fun ordered_operations ->
(* Greedy heuristic *) (* Greedy heuristic *)
trim_manager_operations ~max_size ~hard_gas_limit_per_block (List.map fst ordered_operations) trim_manager_operations ~max_size ~hard_gas_limit_per_block (List.map fst ordered_operations)
@ -369,9 +373,11 @@ let error_of_op (result: error Preapply_result.t) op =
with Not_found -> None with Not_found -> None
let forge_block cctxt ?(chain = `Main) block let forge_block cctxt ?(chain = `Main) block
?threshold
?force ?force
?operations ?(best_effort = operations = None) ?(sort = best_effort) ?operations
?(best_effort = operations = None)
?(sort = best_effort)
?(fee_threshold = Tez.zero)
?timestamp ?timestamp
~priority ~priority
?seed_nonce_hash ~src_sk () = ?seed_nonce_hash ~src_sk () =
@ -385,7 +391,7 @@ let forge_block cctxt ?(chain = `Main) block
let protocol_data = forge_faked_protocol_data ~priority ~seed_nonce_hash in let protocol_data = forge_faked_protocol_data ~priority ~seed_nonce_hash in
Alpha_services.Constants.all cctxt (`Main, block) >>=? Alpha_services.Constants.all cctxt (`Main, block) >>=?
fun Constants.{ parametric = { hard_gas_limit_per_block ; endorsers_per_block } } -> fun Constants.{ parametric = { hard_gas_limit_per_block ; endorsers_per_block } } ->
classify_operations cctxt ~hard_gas_limit_per_block ~block:block ?threshold operations_arg >>=? fun operations -> classify_operations cctxt ~hard_gas_limit_per_block ~block:block ~fee_threshold operations_arg >>=? fun operations ->
(* Ensure that we retain operations up to the quota *) (* Ensure that we retain operations up to the quota *)
let quota : Alpha_environment.Updater.quota list = Main.validation_passes in let quota : Alpha_environment.Updater.quota list = Main.validation_passes in
let endorsements = List.sub let endorsements = List.sub
@ -757,10 +763,30 @@ let shell_prevalidation
return return
(Some (bi, priority, shell_header, raw_ops, delegate, seed_nonce_hash)) (Some (bi, priority, shell_header, raw_ops, delegate, seed_nonce_hash))
(** Retrieve the operations present in the node's mempool and classify
them in 5 lists indexed as :
- 0 -> Endorsements
- 1 -> Votes and proposals
- 2 -> Anonymous operations
- 3 -> High-priority manager operations
- 4 -> Low-priority manager operations
*)
let fetch_operations
(cctxt : #Proto_alpha.full)
state
~chain
~block
=
(* Retrieve pending operations *)
Alpha_block_services.Mempool.pending_operations cctxt ~chain () >>=? fun mpool ->
let operations = ops_of_mempool mpool in
tzforce state.constants >>=? fun Constants.{ parametric = { hard_gas_limit_per_block } } ->
classify_operations cctxt
~hard_gas_limit_per_block ~fee_threshold:state.fee_threshold ~block operations
let bake_slot let bake_slot
cctxt cctxt
state state
?threshold
seed_nonce_hash seed_nonce_hash
((timestamp, (bi, priority, delegate)) as slot) ((timestamp, (bi, priority, delegate)) as slot)
= =
@ -768,6 +794,11 @@ let bake_slot
let block = `Hash (bi.hash, 0) in let block = `Hash (bi.hash, 0) in
Alpha_services.Helpers.current_level cctxt Alpha_services.Helpers.current_level cctxt
~offset:1l (chain, block) >>=? fun next_level -> ~offset:1l (chain, block) >>=? fun next_level ->
let seed_nonce_hash =
if next_level.Level.expected_commitment then
Some seed_nonce_hash
else
None in
let timestamp = let timestamp =
if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then if Block_hash.equal bi.Client_baking_blocks.hash state.genesis then
Time.now () Time.now ()
@ -781,16 +812,7 @@ let bake_slot
-% s bake_priorty_tag priority -% s bake_priorty_tag priority
-% s Client_keys.Logging.tag name -% s Client_keys.Logging.tag name
-% a timestamp_tag timestamp) >>= fun () -> -% a timestamp_tag timestamp) >>= fun () ->
(* Retrieve pending operations *) fetch_operations cctxt state ~chain ~block >>=? fun operations ->
Alpha_block_services.Mempool.pending_operations cctxt ~chain () >>=? fun mpool ->
let operations = ops_of_mempool mpool in
let seed_nonce_hash =
if next_level.expected_commitment then
Some seed_nonce_hash
else
None in
tzforce state.constants >>=? fun Constants.{ parametric = { hard_gas_limit_per_block } } ->
classify_operations cctxt ?threshold ~hard_gas_limit_per_block ~block operations >>=? fun operations ->
let next_version = let next_version =
match Tezos_base.Block_header.get_forced_protocol_upgrade ~level:(Raw_level.to_int32 next_level.Level.level) with match Tezos_base.Block_header.get_forced_protocol_upgrade ~level:(Raw_level.to_int32 next_level.Level.level) with
| None -> bi.next_protocol | None -> bi.next_protocol
@ -852,7 +874,6 @@ let pp_operation_list_list =
(* [bake] create a single block when woken up to do so. All the necessary (* [bake] create a single block when woken up to do so. All the necessary
information (e.g., slot) is available in the [state]. *) information (e.g., slot) is available in the [state]. *)
let bake let bake
?threshold
() ()
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
state state
@ -868,7 +889,7 @@ let bake
(* baking for each slot *) (* baking for each slot *)
filter_map_s filter_map_s
(bake_slot cctxt ?threshold state seed_nonce_hash) (bake_slot cctxt state seed_nonce_hash)
slots >>=? fun candidates -> slots >>=? fun candidates ->
(* FIXME: pick one block per-delegate *) (* FIXME: pick one block per-delegate *)
@ -925,7 +946,7 @@ let bake
the [delegates] *) the [delegates] *)
let create let create
(cctxt : #Proto_alpha.full) (cctxt : #Proto_alpha.full)
?threshold ?fee_threshold
?max_priority ?max_priority
~(context_path: string) ~(context_path: string)
(delegates: public_key_hash list) (delegates: public_key_hash list)
@ -936,7 +957,7 @@ let create
let constants = let constants =
tzlazy (fun () -> Alpha_services.Constants.all cctxt (`Main, `Head 0)) in tzlazy (fun () -> Alpha_services.Constants.all cctxt (`Main, `Head 0)) in
Client_baking_simulator.load_context ~context_path >>= fun index -> Client_baking_simulator.load_context ~context_path >>= fun index ->
let state = create_state genesis_hash context_path index delegates constants bi in let state = create_state genesis_hash context_path index delegates constants ?fee_threshold bi in
return state return state
in in
@ -947,5 +968,5 @@ let create
~state_maker ~state_maker
~pre_loop:(insert_block ?max_priority ()) ~pre_loop:(insert_block ?max_priority ())
~compute_timeout ~compute_timeout
~timeout_k:(bake ?threshold ()) ~timeout_k:(bake ())
~event_k:(insert_block ?max_priority ()) ~event_k:(insert_block ?max_priority ())

View File

@ -55,18 +55,18 @@ val forge_block:
#Proto_alpha.full -> #Proto_alpha.full ->
?chain:Chain_services.chain -> ?chain:Chain_services.chain ->
Block_services.block -> Block_services.block ->
?threshold:Tez.t ->
?force:bool -> ?force:bool ->
?operations: Operation.packed list -> ?operations: Operation.packed list ->
?best_effort:bool -> ?best_effort:bool ->
?sort:bool -> ?sort:bool ->
?fee_threshold:Tez.t ->
?timestamp:Time.t -> ?timestamp:Time.t ->
priority:[`Set of int | `Auto of (public_key_hash * int option)] -> priority:[`Set of int | `Auto of (public_key_hash * int option)] ->
?seed_nonce_hash:Nonce_hash.t -> ?seed_nonce_hash:Nonce_hash.t ->
src_sk:Client_keys.sk_uri -> src_sk:Client_keys.sk_uri ->
unit -> unit ->
Block_hash.t tzresult Lwt.t Block_hash.t tzresult Lwt.t
(** [forge_block cctxt parent_blk ?threshold ?force ?operations ?best_effort (** [forge_block cctxt parent_blk ?fee_threshold ?force ?operations ?best_effort
?sort ?timestamp ?max_priority ?priority ~seed_nonce ~src_sk ?sort ?timestamp ?max_priority ?priority ~seed_nonce ~src_sk
pk_hash] injects a block in the node. In addition of inject_block, pk_hash] injects a block in the node. In addition of inject_block,
it will: it will:
@ -83,7 +83,7 @@ val forge_block:
computed baking priority, it will be used. Otherwise, it will be computed baking priority, it will be used. Otherwise, it will be
set at the best baking priority. set at the best baking priority.
* Threshold: If [?threshold] is given, operations with fees lower than it * Fee Threshold: If [?fee_threshold] is given, operations with fees lower than it
are not added to the block. are not added to the block.
*) *)
@ -103,7 +103,7 @@ end
val create: val create:
#Proto_alpha.full -> #Proto_alpha.full ->
?threshold:Tez.t -> ?fee_threshold:Tez.t ->
?max_priority: int -> ?max_priority: int ->
context_path: string -> context_path: string ->
public_key_hash list -> public_key_hash list ->

View File

@ -28,7 +28,7 @@ open Alpha_context
let bake_block (cctxt : #Proto_alpha.full) let bake_block (cctxt : #Proto_alpha.full)
?(chain = `Main) block ?(chain = `Main) block
?threshold ?fee_threshold
?force ?max_priority ?(minimal_timestamp=false) ?force ?max_priority ?(minimal_timestamp=false)
?src_sk ?src_pk delegate = ?src_sk ?src_pk delegate =
begin begin
@ -56,7 +56,7 @@ let bake_block (cctxt : #Proto_alpha.full)
None, None in None, None in
Client_baking_forge.forge_block cctxt Client_baking_forge.forge_block cctxt
?timestamp:(if minimal_timestamp then None else Some (Time.now ())) ?timestamp:(if minimal_timestamp then None else Some (Time.now ()))
?threshold ?fee_threshold
?force ?force
?seed_nonce_hash ~src_sk block ?seed_nonce_hash ~src_sk block
~priority:(`Auto (delegate, max_priority)) () >>=? fun block_hash -> ~priority:(`Auto (delegate, max_priority)) () >>=? fun block_hash ->

View File

@ -31,7 +31,7 @@ val bake_block:
#Proto_alpha.full -> #Proto_alpha.full ->
?chain:Chain_services.chain -> ?chain:Chain_services.chain ->
Block_services.block -> Block_services.block ->
?threshold:Tez.t -> ?fee_threshold:Tez.t ->
?force:bool -> ?force:bool ->
?max_priority: int -> ?max_priority: int ->
?minimal_timestamp: bool -> ?minimal_timestamp: bool ->

View File

@ -37,12 +37,12 @@ end
module Baker = struct module Baker = struct
let run (cctxt : #Proto_alpha.full) ?threshold ?max_priority ?min_date ~context_path delegates = let run (cctxt : #Proto_alpha.full) ?fee_threshold ?max_priority ?min_date ~context_path delegates =
Client_baking_blocks.monitor_heads Client_baking_blocks.monitor_heads
~next_protocols:(Some [Proto_alpha.hash]) ~next_protocols:(Some [Proto_alpha.hash])
cctxt `Main >>=? fun block_stream -> cctxt `Main >>=? fun block_stream ->
Client_baking_forge.create cctxt Client_baking_forge.create cctxt
?threshold ?max_priority ~context_path delegates block_stream >>=? fun () -> ?fee_threshold ?max_priority ~context_path delegates block_stream >>=? fun () ->
ignore min_date; ignore min_date;
return_unit return_unit

View File

@ -37,7 +37,7 @@ end
module Baker : sig module Baker : sig
val run: val run:
#Proto_alpha.full -> #Proto_alpha.full ->
?threshold: Tez.tez -> ?fee_threshold: Tez.tez ->
?max_priority: int -> ?max_priority: int ->
?min_date: Time.t -> ?min_date: Time.t ->
context_path: string -> context_path: string ->

View File

@ -46,9 +46,9 @@ let delegate_commands () =
@@ Client_keys.Public_key_hash.source_param @@ Client_keys.Public_key_hash.source_param
~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, threshold, force, minimal_timestamp) delegate cctxt -> (fun (max_priority, fee_threshold, force, minimal_timestamp) delegate cctxt ->
bake_block cctxt cctxt#block bake_block cctxt cctxt#block
?threshold ~force ?max_priority ~minimal_timestamp delegate) ; ?fee_threshold ~force ?max_priority ~minimal_timestamp delegate) ;
command ~group ~desc: "Forge and inject a seed-nonce revelation operation." command ~group ~desc: "Forge and inject a seed-nonce revelation operation."
no_options no_options
(prefixes [ "reveal"; "nonce"; "for" ] (prefixes [ "reveal"; "nonce"; "for" ]
@ -85,11 +85,11 @@ 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, threshold) node_path delegates cctxt -> (fun (max_priority, fee_threshold) 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
?threshold ?fee_threshold
?max_priority ?max_priority
~min_date:((Time.add (Time.now ()) (Int64.neg 1800L))) ~min_date:((Time.add (Time.now ()) (Int64.neg 1800L)))
~context_path:(Filename.concat node_path "context") ~context_path:(Filename.concat node_path "context")