From 7f4d4c5606e06dcea3868d1185d1e7b68f2a6dae Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 7 Jan 2025 10:20:22 +0100 Subject: [PATCH 1/6] alpha/baker: add manager operation informations in forged block --- .../lib_delegate/baking_actions.ml | 14 ++++-- src/proto_alpha/lib_delegate/baking_state.ml | 50 +++++++++++++++++-- src/proto_alpha/lib_delegate/baking_state.mli | 10 ++++ src/proto_alpha/lib_delegate/block_forge.ml | 36 ++++++++++--- src/proto_alpha/lib_delegate/block_forge.mli | 1 + .../lib_delegate/operation_selection.ml | 27 ++++++---- .../lib_delegate/operation_selection.mli | 1 + 7 files changed, 115 insertions(+), 24 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index c452a3b78a41..75be6f7ef139 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -399,7 +399,7 @@ let prepare_block (global_state : global_state) (block_to_bake : block_to_bake) ~block:pred_block () [@profiler.record_s {verbosity = Info} "live blocks"]) in - let* {unsigned_block_header; operations} = + let* {unsigned_block_header; operations; manager_operations_infos} = (Block_forge.forge cctxt ~chain_id @@ -446,7 +446,15 @@ let prepare_block (global_state : global_state) (block_to_bake : block_to_bake) let baking_votes = {Per_block_votes.liquidity_baking_vote; adaptive_issuance_vote} in - return {signed_block_header; round; delegate; operations; baking_votes} + return + { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } let only_if_dal_feature_enabled = let no_dal_node_warning_counter = ref 0 in @@ -790,7 +798,7 @@ let inject_consensus_votes state signed_consensus_vote_batch = let inject_block ?(force_injection = false) ?(asynchronous = true) state prepared_block = let open Lwt_result_syntax in - let {signed_block_header; round; delegate; operations; baking_votes} = + let {signed_block_header; round; delegate; operations; baking_votes; _} = prepared_block in (* Cache last per-block votes to use in case of vote file errors *) diff --git a/src/proto_alpha/lib_delegate/baking_state.ml b/src/proto_alpha/lib_delegate/baking_state.ml index 121a62d6a17d..fc9e2f0bea0d 100644 --- a/src/proto_alpha/lib_delegate/baking_state.ml +++ b/src/proto_alpha/lib_delegate/baking_state.ml @@ -273,11 +273,17 @@ type elected_block = { attestation_qc : Kind.attestation Operation.t list; } +type manager_operations_infos = { + manager_operation_number : int; + total_fees : Int64.t; +} + type prepared_block = { signed_block_header : block_header; round : Round.t; delegate : consensus_key_and_delegate; operations : Tezos_base.Operation.t list list; + manager_operations_infos : manager_operations_infos option; baking_votes : Per_block_votes_repr.per_block_votes; } @@ -741,21 +747,55 @@ let signed_consensus_vote_encoding = (req "unsigned_consensus_vote" unsigned_consensus_vote_encoding) (req "signed_operation" (dynamic_size Operation.encoding))) +let manager_operations_infos_encoding = + let open Data_encoding in + conv + (fun {manager_operation_number; total_fees} -> + (manager_operation_number, total_fees)) + (fun (manager_operation_number, total_fees) -> + {manager_operation_number; total_fees}) + (obj2 (req "manager_operation_number" int31) (req "total_fees" int64)) + let forge_event_encoding = let open Data_encoding in let prepared_block_encoding = conv - (fun {signed_block_header; round; delegate; operations; baking_votes} -> - (signed_block_header, round, delegate, operations, baking_votes)) - (fun (signed_block_header, round, delegate, operations, baking_votes) -> - {signed_block_header; round; delegate; operations; baking_votes}) - (obj5 + (fun { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } -> + ( signed_block_header, + round, + delegate, + operations, + manager_operations_infos, + baking_votes )) + (fun ( signed_block_header, + round, + delegate, + operations, + manager_operations_infos, + baking_votes ) -> + { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + }) + (obj6 (req "header" (dynamic_size Block_header.encoding)) (req "round" Round.encoding) (req "delegate" consensus_key_and_delegate_encoding) (req "operations" (list (list (dynamic_size Tezos_base.Operation.encoding)))) + (opt "operations_infos" manager_operations_infos_encoding) (req "baking_votes" Per_block_votes.per_block_votes_encoding)) in union diff --git a/src/proto_alpha/lib_delegate/baking_state.mli b/src/proto_alpha/lib_delegate/baking_state.mli index 7986a8b583c1..8da69e3b1687 100644 --- a/src/proto_alpha/lib_delegate/baking_state.mli +++ b/src/proto_alpha/lib_delegate/baking_state.mli @@ -379,6 +379,15 @@ type forge_request = unsigned_attestations : unsigned_consensus_vote_batch; } +(** [manager_operations_infos] contains information about the number of manager + operations in the forged block and the summing fees from these operations *) +type manager_operations_infos = { + manager_operation_number : int; + total_fees : Int64.t; +} + +val manager_operations_infos_encoding : manager_operations_infos Data_encoding.t + (** [prepared_block] type returned by the forge worker and that contains all information useful for block injection. *) type prepared_block = { @@ -386,6 +395,7 @@ type prepared_block = { round : Round.t; delegate : consensus_key_and_delegate; operations : Tezos_base.Operation.t list list; + manager_operations_infos : manager_operations_infos option; baking_votes : Per_block_votes_repr.per_block_votes; } diff --git a/src/proto_alpha/lib_delegate/block_forge.ml b/src/proto_alpha/lib_delegate/block_forge.ml index 7338ce67d0db..61985125b2fb 100644 --- a/src/proto_alpha/lib_delegate/block_forge.ml +++ b/src/proto_alpha/lib_delegate/block_forge.ml @@ -29,6 +29,7 @@ open Alpha_context type unsigned_block = { unsigned_block_header : Block_header.t; operations : Tezos_base.Operation.t list list; + manager_operations_infos : Baking_state.manager_operations_infos option; } type simulation_kind = @@ -198,7 +199,12 @@ let filter_via_node ~chain_id ~fees_config ~hard_gas_limit_per_block ~payload_round operation_hashes in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [filter_with_context] filters operations using a local context via {!Operation_selection.filter_operations_with_simulation} and a fresh state @@ -221,7 +227,13 @@ let filter_with_context ~chain_id ~fees_config ~hard_gas_limit_per_block pred_info chain_id in - let* {Operation_selection.operations; validation_result; operations_hash; _} = + let* { + Operation_selection.operations; + validation_result; + operations_hash; + manager_operations_infos; + _; + } = Operation_selection.filter_operations_with_simulation incremental fees_config @@ -269,7 +281,7 @@ let filter_with_context ~chain_id ~fees_config ~hard_gas_limit_per_block ~payload_round operation_hashes in - return (shell_header, operations, payload_hash) + return (shell_header, operations, manager_operations_infos, payload_hash) (* [apply_via_node] applies already filtered and validated operations in a block via {!Node_rpc.preapply_block}. A [shell_header] is recovered from this call @@ -289,7 +301,12 @@ let apply_via_node ~chain_id ~faked_protocol_data ~timestamp operations in let operations = List.map (List.map convert_operation) operations in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [apply_with_context] is similar to [filter_with_context] but filters consensus operations only from an [ordered_pool] via @@ -372,7 +389,12 @@ let apply_with_context ~chain_id ~faked_protocol_data ~user_activated_upgrades ~locked_round:locked_round_when_no_validation_result in let operations = List.map (List.map convert_operation) operations in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [forge] a new [unsigned_block] in accordance with [simulation_kind] and [simulation_mode] *) @@ -398,7 +420,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id Filter filtered_pool | Apply _ as x -> x in - let* shell_header, operations, payload_hash = + let* shell_header, operations, manager_operations_infos, payload_hash = match (simulation_mode, simulation_kind) with | Baking_state.Node, Filter operation_pool -> let faked_protocol_data = @@ -508,4 +530,4 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id protocol_data = {contents; signature = Signature.zero}; } in - return {unsigned_block_header; operations} + return {unsigned_block_header; operations; manager_operations_infos} diff --git a/src/proto_alpha/lib_delegate/block_forge.mli b/src/proto_alpha/lib_delegate/block_forge.mli index e85bc5f1fc61..81efcfcc71c3 100644 --- a/src/proto_alpha/lib_delegate/block_forge.mli +++ b/src/proto_alpha/lib_delegate/block_forge.mli @@ -29,6 +29,7 @@ open Alpha_context type unsigned_block = { unsigned_block_header : Block_header.t; operations : Tezos_base.Operation.t list list; + manager_operations_infos : Baking_state.manager_operations_infos option; } (** The simulation kind specifies whether the baker should first filter (and diff --git a/src/proto_alpha/lib_delegate/operation_selection.ml b/src/proto_alpha/lib_delegate/operation_selection.ml index d83f7c55369a..313c727ca0cd 100644 --- a/src/proto_alpha/lib_delegate/operation_selection.ml +++ b/src/proto_alpha/lib_delegate/operation_selection.ml @@ -166,6 +166,7 @@ type simulation_result = { block_header_metadata : block_header_metadata option; operations : packed_operation list list; operations_hash : Operation_list_list_hash.t; + manager_operations_infos : Baking_state.manager_operations_infos option; } let validate_operation inc op = @@ -230,28 +231,33 @@ let filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block (ops, quota) = let open Lwt_syntax in let {Tezos_protocol_environment.max_size; max_op} = quota in - let rec loop (inc, curr_size, nb_ops, remaining_gas, acc) = function - | [] -> return (inc, List.rev acc) - | {op; size = op_size; gas = op_gas; _} :: l -> ( + let rec loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) = + function + | [] -> return (inc, nb_ops, total_fees, List.rev acc) + | {op; size = op_size; gas = op_gas; fee; _} :: l -> ( match max_op with - | Some max_op when max_op = nb_ops + 1 -> return (inc, List.rev acc) + | Some max_op when max_op = nb_ops + 1 -> + return (inc, nb_ops, total_fees, List.rev acc) | None | Some _ -> ( if Gas.Arith.(remaining_gas < op_gas) then (* If the remaining available gas is lower than the considered operation's gas, we ignore this operation. *) - loop (inc, curr_size, nb_ops, remaining_gas, acc) l + loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) l else let new_size = curr_size + op_size in if new_size > max_size then (* We ignore the operation if summing its size to the size of managers operations already validated is greater than the quota. *) - loop (inc, curr_size, nb_ops, remaining_gas, acc) l + loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) l else let packed_op = Prioritized_operation.packed op in let* inc'_opt = validate_operation inc packed_op in match inc'_opt with - | None -> loop (inc, curr_size, nb_ops, remaining_gas, acc) l + | None -> + loop + (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) + l | Some inc' -> let new_remaining_gas = Gas.Arith.sub remaining_gas op_gas @@ -260,11 +266,12 @@ let filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block (ops, quota) ( inc', new_size, succ nb_ops, + Int64.add total_fees (Tez.to_mutez fee), new_remaining_gas, packed_op :: acc ) l)) in - loop (inc, 0, 0, hard_gas_limit_per_block, []) ops + loop (inc, 0, 0, Int64.zero, hard_gas_limit_per_block, []) ops let filter_operations_with_simulation initial_inc fees_config ~hard_gas_limit_per_block {consensus; votes; anonymous; managers} = @@ -300,7 +307,7 @@ let filter_operations_with_simulation initial_inc fees_config ~minimal_nanotez_per_byte managers in - let*! inc, managers = + let*! inc, manager_operation_number, total_fees, managers = filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block @@ -324,6 +331,7 @@ let filter_operations_with_simulation initial_inc fees_config block_header_metadata = Some block_header_metadata; operations; operations_hash; + manager_operations_infos = Some {manager_operation_number; total_fees}; } | None -> return @@ -332,6 +340,7 @@ let filter_operations_with_simulation initial_inc fees_config block_header_metadata = None; operations; operations_hash; + manager_operations_infos = None; } let filter_valid_operations_up_to_quota_without_simulation (ops, quota) = diff --git a/src/proto_alpha/lib_delegate/operation_selection.mli b/src/proto_alpha/lib_delegate/operation_selection.mli index d83fd0dda258..af0ca7658096 100644 --- a/src/proto_alpha/lib_delegate/operation_selection.mli +++ b/src/proto_alpha/lib_delegate/operation_selection.mli @@ -32,6 +32,7 @@ type simulation_result = { block_header_metadata : Apply_results.block_metadata option; operations : packed_operation list list; operations_hash : Operation_list_list_hash.t; + manager_operations_infos : Baking_state.manager_operations_infos option; } (** [filter_operations_with_simulation incremental fees_config -- GitLab From 058f622d1b726634ef43ef0ba0b1a70b8ae9766d Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 7 Jan 2025 10:22:40 +0100 Subject: [PATCH 2/6] alpha/baker: add manager operations informations in injected block event --- src/proto_alpha/lib_delegate/baking_actions.ml | 15 +++++++++++++-- src/proto_alpha/lib_delegate/baking_events.ml | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index 75be6f7ef139..fcca27f9629f 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -798,7 +798,14 @@ let inject_consensus_votes state signed_consensus_vote_batch = let inject_block ?(force_injection = false) ?(asynchronous = true) state prepared_block = let open Lwt_result_syntax in - let {signed_block_header; round; delegate; operations; baking_votes; _} = + let { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } = prepared_block in (* Cache last per-block votes to use in case of vote file errors *) @@ -838,7 +845,11 @@ let inject_block ?(force_injection = false) ?(asynchronous = true) state Events.( emit block_injected - (bh, signed_block_header.shell.level, round, delegate)) + ( bh, + signed_block_header.shell.level, + round, + delegate, + manager_operations_infos )) in return_unit in diff --git a/src/proto_alpha/lib_delegate/baking_events.ml b/src/proto_alpha/lib_delegate/baking_events.ml index 2d18a35865f0..958ba6f3e962 100644 --- a/src/proto_alpha/lib_delegate/baking_events.ml +++ b/src/proto_alpha/lib_delegate/baking_events.ml @@ -992,21 +992,33 @@ module Actions = struct ("delegate", Baking_state.consensus_key_and_delegate_encoding) let block_injected = - declare_4 + declare_5 ~alternative_color:Internal_event.Blue ~section ~name:"block_injected" ~level:Notice ~msg: - "block {block} at level {level}, round {round} injected for {delegate}" + "block {block} at level {level}, round {round} injected for \ + {delegate}{manager_operations_infos}" ~pp1:Block_hash.pp ~pp2:pp_int32 ~pp3:Round.pp ~pp4:Baking_state.pp_consensus_key_and_delegate + ~pp5: + (Format.pp_print_option + (fun fmt Baking_state.{manager_operation_number; total_fees} -> + Format.fprintf + fmt + " with %d manager operations summing %a μtz in fees" + manager_operation_number + pp_int64 + total_fees)) ("block", Block_hash.encoding) ("level", Data_encoding.int32) ("round", Round.encoding) ("delegate", Baking_state.consensus_key_and_delegate_encoding) + ( "manager_operations_infos", + Data_encoding.option Baking_state.manager_operations_infos_encoding ) let block_injection_failed = declare_2 -- GitLab From f9599ee0eda40cd15750bdc02ff4474b891452f9 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 7 Jan 2025 15:15:41 +0100 Subject: [PATCH 3/6] ParisC/baker: add manager operation informations in forged block --- .../lib_delegate/baking_actions.ml | 14 ++++-- .../lib_delegate/baking_state.ml | 50 +++++++++++++++++-- .../lib_delegate/baking_state.mli | 10 ++++ .../lib_delegate/block_forge.ml | 36 ++++++++++--- .../lib_delegate/block_forge.mli | 1 + .../lib_delegate/operation_selection.ml | 27 ++++++---- .../lib_delegate/operation_selection.mli | 1 + 7 files changed, 115 insertions(+), 24 deletions(-) diff --git a/src/proto_020_PsParisC/lib_delegate/baking_actions.ml b/src/proto_020_PsParisC/lib_delegate/baking_actions.ml index 8ffaeb625298..5513477a3092 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_actions.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_actions.ml @@ -389,7 +389,7 @@ let prepare_block (global_state : global_state) (block_to_bake : block_to_bake) ~block:pred_block () [@profiler.record_s {verbosity = Info} "live blocks"]) in - let* {unsigned_block_header; operations} = + let* {unsigned_block_header; operations; manager_operations_infos} = (Block_forge.forge cctxt ~chain_id @@ -436,7 +436,15 @@ let prepare_block (global_state : global_state) (block_to_bake : block_to_bake) let baking_votes = {Per_block_votes.liquidity_baking_vote; adaptive_issuance_vote} in - return {signed_block_header; round; delegate; operations; baking_votes} + return + { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } let only_if_dal_feature_enabled = let no_dal_node_warning_counter = ref 0 in @@ -777,7 +785,7 @@ let inject_consensus_votes state signed_consensus_vote_batch = let inject_block ?(force_injection = false) ?(asynchronous = true) state prepared_block = let open Lwt_result_syntax in - let {signed_block_header; round; delegate; operations; baking_votes} = + let {signed_block_header; round; delegate; operations; baking_votes; _} = prepared_block in (* Cache last per-block votes to use in case of vote file errors *) diff --git a/src/proto_020_PsParisC/lib_delegate/baking_state.ml b/src/proto_020_PsParisC/lib_delegate/baking_state.ml index 7319e1cc63e7..13578c56158d 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_state.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_state.ml @@ -281,11 +281,17 @@ type elected_block = { attestation_qc : Kind.attestation Operation.t list; } +type manager_operations_infos = { + manager_operation_number : int; + total_fees : Int64.t; +} + type prepared_block = { signed_block_header : block_header; round : Round.t; delegate : consensus_key_and_delegate; operations : Tezos_base.Operation.t list list; + manager_operations_infos : manager_operations_infos option; baking_votes : Per_block_votes_repr.per_block_votes; } @@ -723,21 +729,55 @@ let signed_consensus_vote_encoding = (req "unsigned_consensus_vote" unsigned_consensus_vote_encoding) (req "signed_operation" (dynamic_size Operation.encoding))) +let manager_operations_infos_encoding = + let open Data_encoding in + conv + (fun {manager_operation_number; total_fees} -> + (manager_operation_number, total_fees)) + (fun (manager_operation_number, total_fees) -> + {manager_operation_number; total_fees}) + (obj2 (req "manager_operation_number" int31) (req "total_fees" int64)) + let forge_event_encoding = let open Data_encoding in let prepared_block_encoding = conv - (fun {signed_block_header; round; delegate; operations; baking_votes} -> - (signed_block_header, round, delegate, operations, baking_votes)) - (fun (signed_block_header, round, delegate, operations, baking_votes) -> - {signed_block_header; round; delegate; operations; baking_votes}) - (obj5 + (fun { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } -> + ( signed_block_header, + round, + delegate, + operations, + manager_operations_infos, + baking_votes )) + (fun ( signed_block_header, + round, + delegate, + operations, + manager_operations_infos, + baking_votes ) -> + { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + }) + (obj6 (req "header" (dynamic_size Block_header.encoding)) (req "round" Round.encoding) (req "delegate" consensus_key_and_delegate_encoding) (req "operations" (list (list (dynamic_size Tezos_base.Operation.encoding)))) + (opt "operations_infos" manager_operations_infos_encoding) (req "baking_votes" Per_block_votes.per_block_votes_encoding)) in union diff --git a/src/proto_020_PsParisC/lib_delegate/baking_state.mli b/src/proto_020_PsParisC/lib_delegate/baking_state.mli index 35e74c776d3b..e8260a03c492 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_state.mli +++ b/src/proto_020_PsParisC/lib_delegate/baking_state.mli @@ -156,11 +156,21 @@ type elected_block = { attestation_qc : Kind.attestation operation list; } +(** [manager_operations_infos] contains information about the number of manager + operations in the forged block and the summing fees from these operations *) +type manager_operations_infos = { + manager_operation_number : int; + total_fees : Int64.t; +} + +val manager_operations_infos_encoding : manager_operations_infos Data_encoding.t + type prepared_block = { signed_block_header : block_header; round : Round.t; delegate : consensus_key_and_delegate; operations : Tezos_base.Operation.t list list; + manager_operations_infos : manager_operations_infos option; baking_votes : Per_block_votes_repr.per_block_votes; } diff --git a/src/proto_020_PsParisC/lib_delegate/block_forge.ml b/src/proto_020_PsParisC/lib_delegate/block_forge.ml index 7338ce67d0db..61985125b2fb 100644 --- a/src/proto_020_PsParisC/lib_delegate/block_forge.ml +++ b/src/proto_020_PsParisC/lib_delegate/block_forge.ml @@ -29,6 +29,7 @@ open Alpha_context type unsigned_block = { unsigned_block_header : Block_header.t; operations : Tezos_base.Operation.t list list; + manager_operations_infos : Baking_state.manager_operations_infos option; } type simulation_kind = @@ -198,7 +199,12 @@ let filter_via_node ~chain_id ~fees_config ~hard_gas_limit_per_block ~payload_round operation_hashes in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [filter_with_context] filters operations using a local context via {!Operation_selection.filter_operations_with_simulation} and a fresh state @@ -221,7 +227,13 @@ let filter_with_context ~chain_id ~fees_config ~hard_gas_limit_per_block pred_info chain_id in - let* {Operation_selection.operations; validation_result; operations_hash; _} = + let* { + Operation_selection.operations; + validation_result; + operations_hash; + manager_operations_infos; + _; + } = Operation_selection.filter_operations_with_simulation incremental fees_config @@ -269,7 +281,7 @@ let filter_with_context ~chain_id ~fees_config ~hard_gas_limit_per_block ~payload_round operation_hashes in - return (shell_header, operations, payload_hash) + return (shell_header, operations, manager_operations_infos, payload_hash) (* [apply_via_node] applies already filtered and validated operations in a block via {!Node_rpc.preapply_block}. A [shell_header] is recovered from this call @@ -289,7 +301,12 @@ let apply_via_node ~chain_id ~faked_protocol_data ~timestamp operations in let operations = List.map (List.map convert_operation) operations in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [apply_with_context] is similar to [filter_with_context] but filters consensus operations only from an [ordered_pool] via @@ -372,7 +389,12 @@ let apply_with_context ~chain_id ~faked_protocol_data ~user_activated_upgrades ~locked_round:locked_round_when_no_validation_result in let operations = List.map (List.map convert_operation) operations in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [forge] a new [unsigned_block] in accordance with [simulation_kind] and [simulation_mode] *) @@ -398,7 +420,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id Filter filtered_pool | Apply _ as x -> x in - let* shell_header, operations, payload_hash = + let* shell_header, operations, manager_operations_infos, payload_hash = match (simulation_mode, simulation_kind) with | Baking_state.Node, Filter operation_pool -> let faked_protocol_data = @@ -508,4 +530,4 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id protocol_data = {contents; signature = Signature.zero}; } in - return {unsigned_block_header; operations} + return {unsigned_block_header; operations; manager_operations_infos} diff --git a/src/proto_020_PsParisC/lib_delegate/block_forge.mli b/src/proto_020_PsParisC/lib_delegate/block_forge.mli index e85bc5f1fc61..81efcfcc71c3 100644 --- a/src/proto_020_PsParisC/lib_delegate/block_forge.mli +++ b/src/proto_020_PsParisC/lib_delegate/block_forge.mli @@ -29,6 +29,7 @@ open Alpha_context type unsigned_block = { unsigned_block_header : Block_header.t; operations : Tezos_base.Operation.t list list; + manager_operations_infos : Baking_state.manager_operations_infos option; } (** The simulation kind specifies whether the baker should first filter (and diff --git a/src/proto_020_PsParisC/lib_delegate/operation_selection.ml b/src/proto_020_PsParisC/lib_delegate/operation_selection.ml index d83f7c55369a..313c727ca0cd 100644 --- a/src/proto_020_PsParisC/lib_delegate/operation_selection.ml +++ b/src/proto_020_PsParisC/lib_delegate/operation_selection.ml @@ -166,6 +166,7 @@ type simulation_result = { block_header_metadata : block_header_metadata option; operations : packed_operation list list; operations_hash : Operation_list_list_hash.t; + manager_operations_infos : Baking_state.manager_operations_infos option; } let validate_operation inc op = @@ -230,28 +231,33 @@ let filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block (ops, quota) = let open Lwt_syntax in let {Tezos_protocol_environment.max_size; max_op} = quota in - let rec loop (inc, curr_size, nb_ops, remaining_gas, acc) = function - | [] -> return (inc, List.rev acc) - | {op; size = op_size; gas = op_gas; _} :: l -> ( + let rec loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) = + function + | [] -> return (inc, nb_ops, total_fees, List.rev acc) + | {op; size = op_size; gas = op_gas; fee; _} :: l -> ( match max_op with - | Some max_op when max_op = nb_ops + 1 -> return (inc, List.rev acc) + | Some max_op when max_op = nb_ops + 1 -> + return (inc, nb_ops, total_fees, List.rev acc) | None | Some _ -> ( if Gas.Arith.(remaining_gas < op_gas) then (* If the remaining available gas is lower than the considered operation's gas, we ignore this operation. *) - loop (inc, curr_size, nb_ops, remaining_gas, acc) l + loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) l else let new_size = curr_size + op_size in if new_size > max_size then (* We ignore the operation if summing its size to the size of managers operations already validated is greater than the quota. *) - loop (inc, curr_size, nb_ops, remaining_gas, acc) l + loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) l else let packed_op = Prioritized_operation.packed op in let* inc'_opt = validate_operation inc packed_op in match inc'_opt with - | None -> loop (inc, curr_size, nb_ops, remaining_gas, acc) l + | None -> + loop + (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) + l | Some inc' -> let new_remaining_gas = Gas.Arith.sub remaining_gas op_gas @@ -260,11 +266,12 @@ let filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block (ops, quota) ( inc', new_size, succ nb_ops, + Int64.add total_fees (Tez.to_mutez fee), new_remaining_gas, packed_op :: acc ) l)) in - loop (inc, 0, 0, hard_gas_limit_per_block, []) ops + loop (inc, 0, 0, Int64.zero, hard_gas_limit_per_block, []) ops let filter_operations_with_simulation initial_inc fees_config ~hard_gas_limit_per_block {consensus; votes; anonymous; managers} = @@ -300,7 +307,7 @@ let filter_operations_with_simulation initial_inc fees_config ~minimal_nanotez_per_byte managers in - let*! inc, managers = + let*! inc, manager_operation_number, total_fees, managers = filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block @@ -324,6 +331,7 @@ let filter_operations_with_simulation initial_inc fees_config block_header_metadata = Some block_header_metadata; operations; operations_hash; + manager_operations_infos = Some {manager_operation_number; total_fees}; } | None -> return @@ -332,6 +340,7 @@ let filter_operations_with_simulation initial_inc fees_config block_header_metadata = None; operations; operations_hash; + manager_operations_infos = None; } let filter_valid_operations_up_to_quota_without_simulation (ops, quota) = diff --git a/src/proto_020_PsParisC/lib_delegate/operation_selection.mli b/src/proto_020_PsParisC/lib_delegate/operation_selection.mli index d83fd0dda258..af0ca7658096 100644 --- a/src/proto_020_PsParisC/lib_delegate/operation_selection.mli +++ b/src/proto_020_PsParisC/lib_delegate/operation_selection.mli @@ -32,6 +32,7 @@ type simulation_result = { block_header_metadata : Apply_results.block_metadata option; operations : packed_operation list list; operations_hash : Operation_list_list_hash.t; + manager_operations_infos : Baking_state.manager_operations_infos option; } (** [filter_operations_with_simulation incremental fees_config -- GitLab From aaeea8fefb781192cbfbe0b708aee2a9c3661a3b Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 7 Jan 2025 15:16:00 +0100 Subject: [PATCH 4/6] ParisC/baker: add manager operations informations in injected block event --- .../lib_delegate/baking_actions.ml | 15 +++++++++++++-- .../lib_delegate/baking_events.ml | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/proto_020_PsParisC/lib_delegate/baking_actions.ml b/src/proto_020_PsParisC/lib_delegate/baking_actions.ml index 5513477a3092..0e63577655e3 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_actions.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_actions.ml @@ -785,7 +785,14 @@ let inject_consensus_votes state signed_consensus_vote_batch = let inject_block ?(force_injection = false) ?(asynchronous = true) state prepared_block = let open Lwt_result_syntax in - let {signed_block_header; round; delegate; operations; baking_votes; _} = + let { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } = prepared_block in (* Cache last per-block votes to use in case of vote file errors *) @@ -825,7 +832,11 @@ let inject_block ?(force_injection = false) ?(asynchronous = true) state Events.( emit block_injected - (bh, signed_block_header.shell.level, round, delegate)) + ( bh, + signed_block_header.shell.level, + round, + delegate, + manager_operations_infos )) in return_unit in diff --git a/src/proto_020_PsParisC/lib_delegate/baking_events.ml b/src/proto_020_PsParisC/lib_delegate/baking_events.ml index 583ba7344a62..27a904d4c5db 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_events.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_events.ml @@ -1010,21 +1010,33 @@ module Actions = struct ("delegate", Baking_state.consensus_key_and_delegate_encoding) let block_injected = - declare_4 + declare_5 ~alternative_color:Internal_event.Blue ~section ~name:"block_injected" ~level:Notice ~msg: - "block {block} at level {level}, round {round} injected for {delegate}" + "block {block} at level {level}, round {round} injected for \ + {delegate}{manager_operations_infos}" ~pp1:Block_hash.pp ~pp2:pp_int32 ~pp3:Round.pp ~pp4:Baking_state.pp_consensus_key_and_delegate + ~pp5: + (Format.pp_print_option + (fun fmt Baking_state.{manager_operation_number; total_fees} -> + Format.fprintf + fmt + " with %d manager operations summing %a μtz in fees" + manager_operation_number + pp_int64 + total_fees)) ("block", Block_hash.encoding) ("level", Data_encoding.int32) ("round", Round.encoding) ("delegate", Baking_state.consensus_key_and_delegate_encoding) + ( "manager_operations_infos", + Data_encoding.option Baking_state.manager_operations_infos_encoding ) let block_injection_failed = declare_2 -- GitLab From 399ac750fc902ff1ab927ab95742a10c595d3155 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 7 Jan 2025 15:15:46 +0100 Subject: [PATCH 5/6] Quebec/baker: add manager operation informations in forged block --- .../lib_delegate/baking_actions.ml | 14 ++++-- .../lib_delegate/baking_state.ml | 50 +++++++++++++++++-- .../lib_delegate/baking_state.mli | 10 ++++ .../lib_delegate/block_forge.ml | 36 ++++++++++--- .../lib_delegate/block_forge.mli | 1 + .../lib_delegate/operation_selection.ml | 27 ++++++---- .../lib_delegate/operation_selection.mli | 1 + 7 files changed, 115 insertions(+), 24 deletions(-) diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml b/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml index 4211c302bccd..b13f3fda6323 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml @@ -391,7 +391,7 @@ let prepare_block (global_state : global_state) (block_to_bake : block_to_bake) ~block:pred_block () [@profiler.record_s {verbosity = Info} "live blocks"]) in - let* {unsigned_block_header; operations} = + let* {unsigned_block_header; operations; manager_operations_infos} = (Block_forge.forge cctxt ~chain_id @@ -438,7 +438,15 @@ let prepare_block (global_state : global_state) (block_to_bake : block_to_bake) let baking_votes = {Per_block_votes.liquidity_baking_vote; adaptive_issuance_vote} in - return {signed_block_header; round; delegate; operations; baking_votes} + return + { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } let only_if_dal_feature_enabled = let no_dal_node_warning_counter = ref 0 in @@ -779,7 +787,7 @@ let inject_consensus_votes state signed_consensus_vote_batch = let inject_block ?(force_injection = false) ?(asynchronous = true) state prepared_block = let open Lwt_result_syntax in - let {signed_block_header; round; delegate; operations; baking_votes} = + let {signed_block_header; round; delegate; operations; baking_votes; _} = prepared_block in (* Cache last per-block votes to use in case of vote file errors *) diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_state.ml b/src/proto_021_PsQuebec/lib_delegate/baking_state.ml index 7319e1cc63e7..13578c56158d 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_state.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_state.ml @@ -281,11 +281,17 @@ type elected_block = { attestation_qc : Kind.attestation Operation.t list; } +type manager_operations_infos = { + manager_operation_number : int; + total_fees : Int64.t; +} + type prepared_block = { signed_block_header : block_header; round : Round.t; delegate : consensus_key_and_delegate; operations : Tezos_base.Operation.t list list; + manager_operations_infos : manager_operations_infos option; baking_votes : Per_block_votes_repr.per_block_votes; } @@ -723,21 +729,55 @@ let signed_consensus_vote_encoding = (req "unsigned_consensus_vote" unsigned_consensus_vote_encoding) (req "signed_operation" (dynamic_size Operation.encoding))) +let manager_operations_infos_encoding = + let open Data_encoding in + conv + (fun {manager_operation_number; total_fees} -> + (manager_operation_number, total_fees)) + (fun (manager_operation_number, total_fees) -> + {manager_operation_number; total_fees}) + (obj2 (req "manager_operation_number" int31) (req "total_fees" int64)) + let forge_event_encoding = let open Data_encoding in let prepared_block_encoding = conv - (fun {signed_block_header; round; delegate; operations; baking_votes} -> - (signed_block_header, round, delegate, operations, baking_votes)) - (fun (signed_block_header, round, delegate, operations, baking_votes) -> - {signed_block_header; round; delegate; operations; baking_votes}) - (obj5 + (fun { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } -> + ( signed_block_header, + round, + delegate, + operations, + manager_operations_infos, + baking_votes )) + (fun ( signed_block_header, + round, + delegate, + operations, + manager_operations_infos, + baking_votes ) -> + { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + }) + (obj6 (req "header" (dynamic_size Block_header.encoding)) (req "round" Round.encoding) (req "delegate" consensus_key_and_delegate_encoding) (req "operations" (list (list (dynamic_size Tezos_base.Operation.encoding)))) + (opt "operations_infos" manager_operations_infos_encoding) (req "baking_votes" Per_block_votes.per_block_votes_encoding)) in union diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_state.mli b/src/proto_021_PsQuebec/lib_delegate/baking_state.mli index 59c662b14f9c..b44af70c3658 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_state.mli +++ b/src/proto_021_PsQuebec/lib_delegate/baking_state.mli @@ -156,11 +156,21 @@ type elected_block = { attestation_qc : Kind.attestation operation list; } +(** [manager_operations_infos] contains information about the number of manager + operations in the forged block and the summing fees from these operations *) +type manager_operations_infos = { + manager_operation_number : int; + total_fees : Int64.t; +} + +val manager_operations_infos_encoding : manager_operations_infos Data_encoding.t + type prepared_block = { signed_block_header : block_header; round : Round.t; delegate : consensus_key_and_delegate; operations : Tezos_base.Operation.t list list; + manager_operations_infos : manager_operations_infos option; baking_votes : Per_block_votes_repr.per_block_votes; } diff --git a/src/proto_021_PsQuebec/lib_delegate/block_forge.ml b/src/proto_021_PsQuebec/lib_delegate/block_forge.ml index 7338ce67d0db..61985125b2fb 100644 --- a/src/proto_021_PsQuebec/lib_delegate/block_forge.ml +++ b/src/proto_021_PsQuebec/lib_delegate/block_forge.ml @@ -29,6 +29,7 @@ open Alpha_context type unsigned_block = { unsigned_block_header : Block_header.t; operations : Tezos_base.Operation.t list list; + manager_operations_infos : Baking_state.manager_operations_infos option; } type simulation_kind = @@ -198,7 +199,12 @@ let filter_via_node ~chain_id ~fees_config ~hard_gas_limit_per_block ~payload_round operation_hashes in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [filter_with_context] filters operations using a local context via {!Operation_selection.filter_operations_with_simulation} and a fresh state @@ -221,7 +227,13 @@ let filter_with_context ~chain_id ~fees_config ~hard_gas_limit_per_block pred_info chain_id in - let* {Operation_selection.operations; validation_result; operations_hash; _} = + let* { + Operation_selection.operations; + validation_result; + operations_hash; + manager_operations_infos; + _; + } = Operation_selection.filter_operations_with_simulation incremental fees_config @@ -269,7 +281,7 @@ let filter_with_context ~chain_id ~fees_config ~hard_gas_limit_per_block ~payload_round operation_hashes in - return (shell_header, operations, payload_hash) + return (shell_header, operations, manager_operations_infos, payload_hash) (* [apply_via_node] applies already filtered and validated operations in a block via {!Node_rpc.preapply_block}. A [shell_header] is recovered from this call @@ -289,7 +301,12 @@ let apply_via_node ~chain_id ~faked_protocol_data ~timestamp operations in let operations = List.map (List.map convert_operation) operations in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [apply_with_context] is similar to [filter_with_context] but filters consensus operations only from an [ordered_pool] via @@ -372,7 +389,12 @@ let apply_with_context ~chain_id ~faked_protocol_data ~user_activated_upgrades ~locked_round:locked_round_when_no_validation_result in let operations = List.map (List.map convert_operation) operations in - return (shell_header, operations, payload_hash) + let manager_operations_infos = + None + (* We do not compute operations infos from node results to avoid potential + costly computation *) + in + return (shell_header, operations, manager_operations_infos, payload_hash) (* [forge] a new [unsigned_block] in accordance with [simulation_kind] and [simulation_mode] *) @@ -398,7 +420,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id Filter filtered_pool | Apply _ as x -> x in - let* shell_header, operations, payload_hash = + let* shell_header, operations, manager_operations_infos, payload_hash = match (simulation_mode, simulation_kind) with | Baking_state.Node, Filter operation_pool -> let faked_protocol_data = @@ -508,4 +530,4 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id protocol_data = {contents; signature = Signature.zero}; } in - return {unsigned_block_header; operations} + return {unsigned_block_header; operations; manager_operations_infos} diff --git a/src/proto_021_PsQuebec/lib_delegate/block_forge.mli b/src/proto_021_PsQuebec/lib_delegate/block_forge.mli index e85bc5f1fc61..81efcfcc71c3 100644 --- a/src/proto_021_PsQuebec/lib_delegate/block_forge.mli +++ b/src/proto_021_PsQuebec/lib_delegate/block_forge.mli @@ -29,6 +29,7 @@ open Alpha_context type unsigned_block = { unsigned_block_header : Block_header.t; operations : Tezos_base.Operation.t list list; + manager_operations_infos : Baking_state.manager_operations_infos option; } (** The simulation kind specifies whether the baker should first filter (and diff --git a/src/proto_021_PsQuebec/lib_delegate/operation_selection.ml b/src/proto_021_PsQuebec/lib_delegate/operation_selection.ml index d83f7c55369a..313c727ca0cd 100644 --- a/src/proto_021_PsQuebec/lib_delegate/operation_selection.ml +++ b/src/proto_021_PsQuebec/lib_delegate/operation_selection.ml @@ -166,6 +166,7 @@ type simulation_result = { block_header_metadata : block_header_metadata option; operations : packed_operation list list; operations_hash : Operation_list_list_hash.t; + manager_operations_infos : Baking_state.manager_operations_infos option; } let validate_operation inc op = @@ -230,28 +231,33 @@ let filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block (ops, quota) = let open Lwt_syntax in let {Tezos_protocol_environment.max_size; max_op} = quota in - let rec loop (inc, curr_size, nb_ops, remaining_gas, acc) = function - | [] -> return (inc, List.rev acc) - | {op; size = op_size; gas = op_gas; _} :: l -> ( + let rec loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) = + function + | [] -> return (inc, nb_ops, total_fees, List.rev acc) + | {op; size = op_size; gas = op_gas; fee; _} :: l -> ( match max_op with - | Some max_op when max_op = nb_ops + 1 -> return (inc, List.rev acc) + | Some max_op when max_op = nb_ops + 1 -> + return (inc, nb_ops, total_fees, List.rev acc) | None | Some _ -> ( if Gas.Arith.(remaining_gas < op_gas) then (* If the remaining available gas is lower than the considered operation's gas, we ignore this operation. *) - loop (inc, curr_size, nb_ops, remaining_gas, acc) l + loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) l else let new_size = curr_size + op_size in if new_size > max_size then (* We ignore the operation if summing its size to the size of managers operations already validated is greater than the quota. *) - loop (inc, curr_size, nb_ops, remaining_gas, acc) l + loop (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) l else let packed_op = Prioritized_operation.packed op in let* inc'_opt = validate_operation inc packed_op in match inc'_opt with - | None -> loop (inc, curr_size, nb_ops, remaining_gas, acc) l + | None -> + loop + (inc, curr_size, nb_ops, total_fees, remaining_gas, acc) + l | Some inc' -> let new_remaining_gas = Gas.Arith.sub remaining_gas op_gas @@ -260,11 +266,12 @@ let filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block (ops, quota) ( inc', new_size, succ nb_ops, + Int64.add total_fees (Tez.to_mutez fee), new_remaining_gas, packed_op :: acc ) l)) in - loop (inc, 0, 0, hard_gas_limit_per_block, []) ops + loop (inc, 0, 0, Int64.zero, hard_gas_limit_per_block, []) ops let filter_operations_with_simulation initial_inc fees_config ~hard_gas_limit_per_block {consensus; votes; anonymous; managers} = @@ -300,7 +307,7 @@ let filter_operations_with_simulation initial_inc fees_config ~minimal_nanotez_per_byte managers in - let*! inc, managers = + let*! inc, manager_operation_number, total_fees, managers = filter_valid_managers_up_to_quota inc ~hard_gas_limit_per_block @@ -324,6 +331,7 @@ let filter_operations_with_simulation initial_inc fees_config block_header_metadata = Some block_header_metadata; operations; operations_hash; + manager_operations_infos = Some {manager_operation_number; total_fees}; } | None -> return @@ -332,6 +340,7 @@ let filter_operations_with_simulation initial_inc fees_config block_header_metadata = None; operations; operations_hash; + manager_operations_infos = None; } let filter_valid_operations_up_to_quota_without_simulation (ops, quota) = diff --git a/src/proto_021_PsQuebec/lib_delegate/operation_selection.mli b/src/proto_021_PsQuebec/lib_delegate/operation_selection.mli index d83fd0dda258..af0ca7658096 100644 --- a/src/proto_021_PsQuebec/lib_delegate/operation_selection.mli +++ b/src/proto_021_PsQuebec/lib_delegate/operation_selection.mli @@ -32,6 +32,7 @@ type simulation_result = { block_header_metadata : Apply_results.block_metadata option; operations : packed_operation list list; operations_hash : Operation_list_list_hash.t; + manager_operations_infos : Baking_state.manager_operations_infos option; } (** [filter_operations_with_simulation incremental fees_config -- GitLab From 88aefded2f38541cb3d847b01aba332ccea935ad Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 7 Jan 2025 15:15:57 +0100 Subject: [PATCH 6/6] Quebec/baker: add manager operations informations in injected block event --- .../lib_delegate/baking_actions.ml | 15 +++++++++++++-- .../lib_delegate/baking_events.ml | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml b/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml index b13f3fda6323..1cc0ab1e1561 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_actions.ml @@ -787,7 +787,14 @@ let inject_consensus_votes state signed_consensus_vote_batch = let inject_block ?(force_injection = false) ?(asynchronous = true) state prepared_block = let open Lwt_result_syntax in - let {signed_block_header; round; delegate; operations; baking_votes; _} = + let { + signed_block_header; + round; + delegate; + operations; + manager_operations_infos; + baking_votes; + } = prepared_block in (* Cache last per-block votes to use in case of vote file errors *) @@ -827,7 +834,11 @@ let inject_block ?(force_injection = false) ?(asynchronous = true) state Events.( emit block_injected - (bh, signed_block_header.shell.level, round, delegate)) + ( bh, + signed_block_header.shell.level, + round, + delegate, + manager_operations_infos )) in return_unit in diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_events.ml b/src/proto_021_PsQuebec/lib_delegate/baking_events.ml index 3b0dfceb6458..85f1afa35327 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_events.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_events.ml @@ -1013,21 +1013,33 @@ module Actions = struct ("delegate", Baking_state.consensus_key_and_delegate_encoding) let block_injected = - declare_4 + declare_5 ~alternative_color:Internal_event.Blue ~section ~name:"block_injected" ~level:Notice ~msg: - "block {block} at level {level}, round {round} injected for {delegate}" + "block {block} at level {level}, round {round} injected for \ + {delegate}{manager_operations_infos}" ~pp1:Block_hash.pp ~pp2:pp_int32 ~pp3:Round.pp ~pp4:Baking_state.pp_consensus_key_and_delegate + ~pp5: + (Format.pp_print_option + (fun fmt Baking_state.{manager_operation_number; total_fees} -> + Format.fprintf + fmt + " with %d manager operations summing %a μtz in fees" + manager_operation_number + pp_int64 + total_fees)) ("block", Block_hash.encoding) ("level", Data_encoding.int32) ("round", Round.encoding) ("delegate", Baking_state.consensus_key_and_delegate_encoding) + ( "manager_operations_infos", + Data_encoding.option Baking_state.manager_operations_infos_encoding ) let block_injection_failed = declare_2 -- GitLab