diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index cb32055208bfa28b5bd050e2feb47539bc296466..d3cbc05cf3b48b483c431e5233223b3d14b1a94f 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -52,7 +52,14 @@ Breaking Changes of validators for that level. Each element of this last list contains the fields present in the previous version of this RPC: ``delegate``, ``slots``, ``consensus_key``, and ``companion_key`` (optional). - (MR :gl:`!18931`) + Also include a new field for delegates, ``attesting_power``, with their attesting power + for the level. + (MR :gl:`!18931`, :gl:`!18959`) + +- Updated ``GET /chains//blocks//context/issuance/expected_issuance``, + changing ``baking_reward_bonus_per_slot`` with ``baking_reward_bonus_per_block``, and + ``attesting_reward_per_slot`` with ``ættesting_reward_per_block``. (MR :gl:`!18959`) + RPC Changes ----------- diff --git a/scripts/profile_alpha.patch b/scripts/profile_alpha.patch index 0228c13158aaacfda16e9e267bb83dd081c073c4..194da29ec6a19b59619a3ab2327965550084020e 100644 --- a/scripts/profile_alpha.patch +++ b/scripts/profile_alpha.patch @@ -1,7 +1,7 @@ -From b8aa886aa2185e7a7672d8d88023353ad2ce01da Mon Sep 17 00:00:00 2001 -From: Pierrick Couderc -Date: Tue, 29 Jul 2025 10:05:07 +0200 -Subject: [PATCH 1/1] [PATCH] Patch alpha +From 9fb4fb9d53fb048ac23bdb54abb939bfb55755cb Mon Sep 17 00:00:00 2001 +From: Lucas Randazzo +Date: Thu, 21 Aug 2025 16:23:33 +0200 +Subject: [PATCH 1/1] Patch alpha --- src/lib_protocol_environment/sigs/v15.in.ml | 2 + @@ -18,26 +18,26 @@ Subject: [PATCH 1/1] [PATCH] Patch alpha 11 files changed, 217 insertions(+), 85 deletions(-) diff --git a/src/lib_protocol_environment/sigs/v15.in.ml b/src/lib_protocol_environment/sigs/v15.in.ml -index e86731c9cb..05291026e6 100644 +index e86731c9cbd..05291026e6b 100644 --- a/src/lib_protocol_environment/sigs/v15.in.ml +++ b/src/lib_protocol_environment/sigs/v15.in.ml @@ -105,6 +105,8 @@ module type T = sig - + module Operation_list_list_hash : [%sig "v15/operation_list_list_hash.mli"] - + + module Profiler : [%sig "v15/profiler.mli"] + module Protocol_hash : [%sig "v15/protocol_hash.mli"] - + module Context_hash : [%sig "v15/context_hash.mli"] diff --git a/src/lib_protocol_environment/sigs/v15.ml b/src/lib_protocol_environment/sigs/v15.ml -index f412c985e9..313466717b 100644 +index f412c985e9c..313466717b9 100644 --- a/src/lib_protocol_environment/sigs/v15.ml +++ b/src/lib_protocol_environment/sigs/v15.ml @@ -10060,6 +10060,48 @@ end # 106 "v15.in.ml" - - + + + module Profiler : sig +# 1 "v15/profiler.mli" +(*****************************************************************************) @@ -89,17 +89,17 @@ index f412c985e9..313466717b 100644 end -# 108 "v15.in.ml" +# 110 "v15.in.ml" - - + + module Context_hash : sig @@ -10143,7 +10185,7 @@ end - + type version = Version.t end -# 110 "v15.in.ml" +# 112 "v15.in.ml" - - + + module Sapling : sig @@ -10291,7 +10333,7 @@ module Verification : sig val final_check : t -> UTXO.transaction -> string -> bool @@ -107,8 +107,8 @@ index f412c985e9..313466717b 100644 end -# 112 "v15.in.ml" +# 114 "v15.in.ml" - - + + module Timelock : sig @@ -10348,7 +10390,7 @@ val open_chest : chest -> chest_key -> time:int -> opening_result Used for gas accounting*) @@ -116,8 +116,8 @@ index f412c985e9..313466717b 100644 end -# 114 "v15.in.ml" +# 116 "v15.in.ml" - - + + module Vdf : sig @@ -10436,7 +10478,7 @@ val prove : discriminant -> challenge -> difficulty -> result * proof @raise Invalid_argument when inputs are invalid *) @@ -125,26 +125,26 @@ index f412c985e9..313466717b 100644 end -# 116 "v15.in.ml" +# 118 "v15.in.ml" - - + + module Micheline : sig @@ -10496,7 +10538,7 @@ val annotations : ('l, 'p) node -> string list - + val strip_locations : (_, 'p) node -> 'p canonical end -# 118 "v15.in.ml" +# 120 "v15.in.ml" - - + + module Block_header : sig @@ -10553,7 +10595,7 @@ type t = {shell : shell_header; protocol_data : bytes} - + include S.HASHABLE with type t := t and type hash := Block_hash.t end -# 120 "v15.in.ml" +# 122 "v15.in.ml" - - + + module Bounded : sig @@ -10702,7 +10744,7 @@ module Int8 (B : BOUNDS with type ocaml_type := int) : module Uint8 (B : BOUNDS with type ocaml_type := int) : @@ -152,8 +152,8 @@ index f412c985e9..313466717b 100644 end -# 122 "v15.in.ml" +# 124 "v15.in.ml" - - + + module Fitness : sig @@ -10736,7 +10778,7 @@ end compared in a lexicographical order (longer list are greater). *) @@ -161,17 +161,17 @@ index f412c985e9..313466717b 100644 end -# 124 "v15.in.ml" +# 126 "v15.in.ml" - - + + module Operation : sig @@ -10780,7 +10822,7 @@ type t = {shell : shell_header; proto : bytes} - + include S.HASHABLE with type t := t and type hash := Operation_hash.t end -# 126 "v15.in.ml" +# 128 "v15.in.ml" - - + + module Context : sig @@ -11417,7 +11459,7 @@ module Cache : and type key = cache_key @@ -179,8 +179,8 @@ index f412c985e9..313466717b 100644 end -# 128 "v15.in.ml" +# 130 "v15.in.ml" - - + + module Updater : sig @@ -11953,7 +11995,7 @@ end not complete until [init] in invoked. *) @@ -188,8 +188,8 @@ index f412c985e9..313466717b 100644 end -# 130 "v15.in.ml" +# 132 "v15.in.ml" - - + + module RPC_context : sig @@ -12107,7 +12149,7 @@ val make_opt_call3 : 'i -> @@ -197,17 +197,17 @@ index f412c985e9..313466717b 100644 end -# 132 "v15.in.ml" +# 134 "v15.in.ml" - - + + module Context_binary : sig @@ -12150,7 +12192,7 @@ module Tree : - + val make_empty_context : ?root:string -> unit -> t end -# 134 "v15.in.ml" +# 136 "v15.in.ml" - - + + module Wasm_2_0_0 : sig @@ -12224,7 +12266,7 @@ module Make val get_info : Tree.tree -> info Lwt.t @@ -215,8 +215,8 @@ index f412c985e9..313466717b 100644 end -# 136 "v15.in.ml" +# 138 "v15.in.ml" - - + + module Plonk : sig @@ -12343,7 +12385,7 @@ val scalar_array_encoding : scalar array Data_encoding.t on the given [inputs] according to the [public_parameters]. *) @@ -224,8 +224,8 @@ index f412c985e9..313466717b 100644 end -# 138 "v15.in.ml" +# 140 "v15.in.ml" - - + + module Dal : sig @@ -12498,7 +12540,7 @@ val share_is_trap : traps_fraction:Q.t -> @@ -233,8 +233,8 @@ index f412c985e9..313466717b 100644 end -# 140 "v15.in.ml" +# 142 "v15.in.ml" - - + + module Skip_list : sig @@ -12730,7 +12772,7 @@ module Make (_ : sig val basis : int @@ -242,8 +242,8 @@ index f412c985e9..313466717b 100644 end -# 142 "v15.in.ml" +# 144 "v15.in.ml" - - + + module Smart_rollup : sig @@ -12787,7 +12829,7 @@ module Inbox_hash : S.HASH (** Smart rollup merkelized payload hashes' hash *) @@ -251,11 +251,11 @@ index f412c985e9..313466717b 100644 end -# 144 "v15.in.ml" +# 146 "v15.in.ml" - - + + module Riscv : sig diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml -index f1224801d2..0bbf37a35f 100644 +index 97965b0f7af..ad18f8ccf98 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -2538,7 +2538,11 @@ let apply_manager_operations ctxt ~payload_producer chain_id ~mempool_mode @@ -286,36 +286,36 @@ index f1224801d2..0bbf37a35f 100644 + let+ ctxt = Bootstrap.cycle_end ctxt last_cycle in + (ctxt, balance_updates, deactivated)) + [@profiler.record_s {verbosity = Notice} "delegate end cycle"] - + let apply_liquidity_baking_subsidy ctxt ~per_block_vote = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/baking.ml b/src/proto_alpha/lib_protocol/baking.ml -index fd49c03e5b..ac6bb84e32 100644 +index 3c3bd980bc3..2c48b44392c 100644 --- a/src/proto_alpha/lib_protocol/baking.ml +++ b/src/proto_alpha/lib_protocol/baking.ml -@@ -87,7 +87,7 @@ type ordered_slots = { +@@ -109,7 +109,7 @@ type ordered_slots = { + (* Slots returned by this function are assumed by consumers to be in increasing + order, hence the use of [Slot.Range.rev_fold_es]. *) let attesting_rights (ctxt : t) level = - let consensus_committee_size = Constants.consensus_committee_size ctxt in - let open Lwt_result_syntax in -- let*? slots = Slot.Range.create ~min:0 ~count:consensus_committee_size in -+ (let*? slots = Slot.Range.create ~min:0 ~count:consensus_committee_size in - Slot.Range.rev_fold_es - (fun (ctxt, map) slot -> - let* ctxt, consensus_pk = Stake_distribution.slot_owner ctxt level slot in -@@ -108,7 +108,7 @@ let attesting_rights (ctxt : t) level = - in - return (ctxt, map)) - (ctxt, Signature.Public_key_hash.Map.empty) -- slots -+ slots) [@profiler.record_s {verbosity = Notice} "attesting_rights_by_first_slot"] - - let attesting_rights_by_first_slot ctxt level : - (t * Consensus_key.power Slot.Map.t) tzresult Lwt.t = +- let consensus_committee_size = Constants.consensus_committee_size ctxt in ++ (let consensus_committee_size = Constants.consensus_committee_size ctxt in + let all_bakers_attest_enabled = + Attesting_power.check_all_bakers_attest_at_level ctxt level + in +@@ -165,7 +165,7 @@ let attesting_rights (ctxt : t) level = + else {t with attesting_power = List.length slots |> Int64.of_int}) + map + in +- return (ctxt, map) ++ return (ctxt, map)) [@profiler.record_s {verbosity = Notice} "attesting_rights"] + + let incr_slot att_rights = + let one = Attesting_power.make ~slots:1 ~stake:0L in diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml -index 38b0e96c9c..3de66a1efc 100644 +index 9f3949710a9..5f1a6242a80 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml -@@ -218,42 +218,92 @@ let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = +@@ -227,42 +227,92 @@ let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = let cycle_end ctxt last_cycle = let open Lwt_result_syntax in (* attributing attesting rewards *) @@ -423,7 +423,7 @@ index 38b0e96c9c..3de66a1efc 100644 let balance_updates = slashing_balance_updates @ attesting_balance_updates in return (ctxt, balance_updates, deactivated_delegates) diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune -index 9d8c157e2f..6348104b4d 100644 +index fa81fbafe08..4b46d91a7e5 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -23,6 +23,8 @@ @@ -436,7 +436,7 @@ index 9d8c157e2f..6348104b4d 100644 (flags (:standard) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml -index 209f77c75f..209c8d6006 100644 +index 209f77c75fb..209c8d6006f 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -247,22 +247,38 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract @@ -504,7 +504,7 @@ index 209f77c75f..209c8d6006 100644 in return ctxt diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml -index c3eb705da0..97096a6d44 100644 +index 910c9d5dad7..ea684a8f115 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1753,12 +1753,13 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = @@ -526,9 +526,9 @@ index c3eb705da0..97096a6d44 100644 + [@profiler.record_s {verbosity = Notice} "Prepare"]) in (previous_proto, previous_proto_constants, ctxt) - + diff --git a/src/proto_alpha/lib_protocol/script_cache.ml b/src/proto_alpha/lib_protocol/script_cache.ml -index 70a79eb8f4..9724bc4246 100644 +index 70a79eb8f44..9724bc4246b 100644 --- a/src/proto_alpha/lib_protocol/script_cache.ml +++ b/src/proto_alpha/lib_protocol/script_cache.ml @@ -98,15 +98,16 @@ let find ctxt addr = @@ -554,14 +554,14 @@ index 70a79eb8f4..9724bc4246 100644 + in + return (ctxt, identifier, Some (unparsed_script, script_ir))) + [@profiler.record_s {verbosity = Notice} "cache_miss"]) - + let update ctxt identifier updated_script approx_size = Cache.update ctxt identifier (Some (updated_script, approx_size)) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml -index 5d3723d900..1b9a2e2e0a 100644 +index 3527a81698c..efd4ffebbe8 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml -@@ -1827,7 +1827,7 @@ type execution_result = { +@@ -1826,7 +1826,7 @@ type execution_result = { let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal unparsed_script cached_script arg = let open Lwt_result_syntax in @@ -570,7 +570,7 @@ index 5d3723d900..1b9a2e2e0a 100644 Script_ir_translator_config.make ~legacy:true ~keep_extra_types_for_interpreter_logging:(Option.is_some logger) -@@ -1880,9 +1880,10 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal +@@ -1879,9 +1879,10 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal Script_ir_translator.collect_lazy_storage ctxt storage_type old_storage in let* (ops, new_storage), ctxt = @@ -584,20 +584,20 @@ index 5d3723d900..1b9a2e2e0a 100644 in let* storage, lazy_storage_diff, ctxt = Script_ir_translator.extract_lazy_storage_diff -@@ -1950,7 +1951,7 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal +@@ -1949,7 +1950,7 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal ticket_receipt; address_registry_diff; }, - ctxt ) + ctxt )) [@profiler.record_s {verbosity = Notice} "execute"] - + let execute_with_typed_parameter ?logger ctxt ~cached_script mode step_constants ~script ~entrypoint ~parameter_ty ~location ~parameter ~internal = diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml -index 6ca28c7b22..d50aa670af 100644 +index 8356e1e2ba1..9d6b1929f55 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml -@@ -5238,17 +5238,21 @@ let parse_script : +@@ -5244,17 +5244,21 @@ let parse_script : (Code {code; arg_type; storage_type; views; entrypoints; code_size}), ctxt ) = @@ -628,8 +628,8 @@ index 6ca28c7b22..d50aa670af 100644 in ( Ex_script (Script -@@ -5948,15 +5952,15 @@ let list_of_big_map_ids ids = - +@@ -5954,15 +5958,15 @@ let list_of_big_map_ids ids = + let parse_data ~elab_conf ctxt ~allow_forged_tickets ~allow_forged_lazy_storage_id ty t = - parse_data @@ -650,9 +650,8 @@ index 6ca28c7b22..d50aa670af 100644 + ctxt + ty + t [@profiler.record_s {verbosity = Notice} "parse_data"]) - + let parse_view ~elab_conf ctxt ty view = parse_view ~unparse_code_rec ~elab_conf ctxt ty view --- -2.50.1 - +-- +2.43.0 diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index eed18dc1d07bfd7092be691ff855e9e8d56ee267..2c9043f52837949294bdfd01e8b9f5a468a57595 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -1002,7 +1002,7 @@ let pp_contents_and_result : "(%a, %a)" Consensus_key.pp delegate - Attestation_power.pp + Attesting_power.pp voting_power in fun ppf -> function @@ -1055,7 +1055,7 @@ let pp_contents_and_result : balance_updates Consensus_key.pp {delegate; consensus_pkh = consensus_key} - Attestation_power.pp + Attesting_power.pp consensus_power | ( Attestation {consensus_content = {level; _}; dal_content = _}, Attestation_result @@ -1073,7 +1073,7 @@ let pp_contents_and_result : balance_updates Consensus_key.pp {delegate; consensus_pkh = consensus_key} - Attestation_power.pp + Attesting_power.pp consensus_power | ( Preattestations_aggregate {consensus_content = {level; _}; _}, Preattestations_aggregate_result @@ -1091,7 +1091,7 @@ let pp_contents_and_result : balance_updates (Format.pp_print_list pp_committee) committee - Attestation_power.pp + Attesting_power.pp total_consensus_power | ( Attestations_aggregate {consensus_content = {level; _}; _}, Attestations_aggregate_result @@ -1109,7 +1109,7 @@ let pp_contents_and_result : balance_updates (Format.pp_print_list pp_committee) committee - Attestation_power.pp + Attesting_power.pp total_consensus_power | ( Double_consensus_operation_evidence {slot; op1; op2}, Double_consensus_operation_evidence_result double_signing_result ) -> diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index 3da1c7a87876ceb667d1ea907ecee97eaaa556e7..079f9457a12ca020406285f992145153f70d65a4 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -1016,7 +1016,6 @@ let inject_block ?(force_injection = false) ?(asynchronous = true) state return new_state let prepare_waiting_for_quorum state = - (* TODO ABAAB *) let consensus_threshold = Delegate_slots.consensus_threshold state.level_state.delegate_slots in diff --git a/src/proto_alpha/lib_delegate/baking_lib.ml b/src/proto_alpha/lib_delegate/baking_lib.ml index 324b944f7f494273530407be126b1ba5c76dffad..6ec89e5070e98828e21eccc7eb25a285bded7dc8 100644 --- a/src/proto_alpha/lib_delegate/baking_lib.ml +++ b/src/proto_alpha/lib_delegate/baking_lib.ml @@ -237,14 +237,14 @@ let attestations_attesting_power state attestations = match Delegate_slots.voting_power state.level_state.delegate_slots ~slot with - | None -> 0 (* cannot happen *) + | None -> 0L (* cannot happen *) | Some attesting_power -> attesting_power in List.sort_uniq compare attestations |> List.fold_left (fun power attestation -> - power + get_attestation_voting_power attestation) - 0 + Int64.add power (get_attestation_voting_power attestation)) + 0L let generic_attesting_power (filter : packed_operation list -> 'a list) (extract : 'a -> consensus_content) state = @@ -348,11 +348,10 @@ let propose_at_next_level ~minimal_timestamp state = let attestation_quorum state = let power, attestations = state_attesting_power state in - (* TODO ABAAB *) let consensus_threshold = Delegate_slots.consensus_threshold state.level_state.delegate_slots in - if Compare.Int.(power >= consensus_threshold) then Some (power, attestations) + if Compare.Int64.(power >= consensus_threshold) then Some (power, attestations) else None (* Here's the sketch of the algorithm: @@ -709,15 +708,14 @@ let rec baking_minimal_timestamp ~count state own_attestations.unsigned_consensus_votes |> attestations_attesting_power state in - (* TODO ABAAB *) let consensus_threshold = Delegate_slots.consensus_threshold state.level_state.delegate_slots in let* () = - if Compare.Int.(total_voting_power < consensus_threshold) then + if Compare.Int64.(total_voting_power < consensus_threshold) then cctxt#error - "Delegates do not have enough voting power. Only %d is available while \ - %d is required." + "Delegates do not have enough voting power. Only %Ld is available \ + while %Ld is required." total_voting_power consensus_threshold else return_unit diff --git a/src/proto_alpha/lib_delegate/baking_scheduling.ml b/src/proto_alpha/lib_delegate/baking_scheduling.ml index cafa36369e519a4bedd529516877e5a6a9a9db02..c4dbd2ccb539b4b0f24251e1e8f75e7de19fdcd8 100644 --- a/src/proto_alpha/lib_delegate/baking_scheduling.ml +++ b/src/proto_alpha/lib_delegate/baking_scheduling.ml @@ -945,6 +945,7 @@ let try_resolve_consensus_keys cctxt key = consensus_key = _; companion_key = _; slots = _; + attesting_power = _; } :: _; _; diff --git a/src/proto_alpha/lib_delegate/baking_state.ml b/src/proto_alpha/lib_delegate/baking_state.ml index 7c7cb80960b0b4f01d6ee8435d98876a202e2def..b7c5e39a6a45e102db5a7d64d7cd5997297c355c 100644 --- a/src/proto_alpha/lib_delegate/baking_state.ml +++ b/src/proto_alpha/lib_delegate/baking_state.ml @@ -127,7 +127,7 @@ module SlotMap : Map.S with type key = Slot.t = Map.Make (Slot) type delegate_slot = { delegate : Delegate.t; first_slot : Slot.t; - attesting_power : int; + attesting_power : int64; } module Delegate_slots = struct @@ -138,7 +138,7 @@ module Delegate_slots = struct (* This map cannot have as keys just the first slot of delegates, because it is used in [round_proposer] for which we need all slots, as the round can be arbitrary. *) - all_delegate_voting_power : int SlotMap.t; + all_delegate_voting_power : int64 SlotMap.t; (* This is a map having as keys the first slot of all delegates, and as values their attesting power. This map contains just the first slot for a delegate, because it is @@ -149,8 +149,8 @@ module Delegate_slots = struct non-first-slot operations from the mempool because this check is skipped in the mempool to increase its speed; the baker can and should ignore such operations. *) - consensus_threshold : int; - consensus_committee : int; + consensus_threshold : int64; + consensus_committee : int64; } let own_delegates slots = slots.own_delegates @@ -956,9 +956,9 @@ let delegate_slots attesting_rights delegates = all_delegate_voting_power ) = Lwt_list.fold_left_s (fun (own_list, own_map, all_map) validator -> - let {Plugin.RPC.Validators.slots; _} = validator in + let {Plugin.RPC.Validators.slots; attesting_power; _} = validator in let first_slot = Stdlib.List.hd slots in - let attesting_power = List.length slots in + let attesting_power = attesting_power in let all_map = SlotMap.add first_slot attesting_power all_map in let* own_list, own_map = let* delegate_opt = Delegate.of_validator ~known_keys validator in @@ -1172,7 +1172,7 @@ let pp_elected_block fmt {proposal; attestation_qc} = let pp_delegate_slot fmt {delegate; first_slot; attesting_power} = Format.fprintf fmt - "slots: @[first_slot: %a@],@ delegate: %a,@ attesting_power: %d" + "slots: @[first_slot: %a@],@ delegate: %a,@ attesting_power: %Ld" Slot.pp first_slot Delegate.pp @@ -1195,20 +1195,21 @@ let delegate_slots_for_pp delegate_slot_map = |> SlotMap.map (fun {attester; all_slots} -> {attester; all_slots = List.rev all_slots}) -let pp_delegate_slots fmt Delegate_slots.{own_delegate_slots; _} = +let pp_delegate_slots fmt (Delegate_slots.{own_delegate_slots; _} as t) = Format.fprintf fmt "@[%a@]" Format.( pp_print_list ~pp_sep:pp_print_cut - (fun fmt (_first_slot, {attester; all_slots}) -> + (fun fmt (first_slot, {attester; all_slots}) -> Format.fprintf fmt - "attester: %a, power: %d, first 10 slots: %a" + "attester: %a, power: %Ld, first 10 slots: %a" Delegate.pp attester - (List.length all_slots) + (Option.value ~default:0L + @@ Delegate_slots.voting_power t ~slot:first_slot) (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.pp_print_string fmt ",") Slot.pp) diff --git a/src/proto_alpha/lib_delegate/baking_state.mli b/src/proto_alpha/lib_delegate/baking_state.mli index bd17340328542d056dfa1b5226b2ec021666e37c..6d0cad992c4e13cd1c1b9bbf420eb9b38fb62854 100644 --- a/src/proto_alpha/lib_delegate/baking_state.mli +++ b/src/proto_alpha/lib_delegate/baking_state.mli @@ -32,7 +32,7 @@ open Baking_state_types type delegate_slot = { delegate : Delegate.t; first_slot : Slot.t; - attesting_power : int; + attesting_power : int64; } val pp_delegate_slot : Format.formatter -> delegate_slot -> unit @@ -57,7 +57,7 @@ module Delegate_slots : sig (** Returns the voting power of the delegate whose first slot is the given slot. Returns [None] if the slot is not the first slot of any delegate. *) - val voting_power : t -> slot:Slot.t -> int option + val voting_power : t -> slot:Slot.t -> int64 option (** Finds the first slot greater than or equal to [slot]. Returns the corresponding (slot, delegate) pair if found, or [None] if no such slot @@ -69,10 +69,10 @@ module Delegate_slots : sig val min_slot : t -> (Slot.t * delegate_slot) option (** Returns the consensus threshold at the level the slots were computed *) - val consensus_threshold : t -> int + val consensus_threshold : t -> int64 (** Returns the consensus committee at the level the slots were computed *) - val consensus_committee : t -> int + val consensus_committee : t -> int64 end type delegate_slots = Delegate_slots.t diff --git a/src/proto_alpha/lib_delegate/baking_state_types.ml b/src/proto_alpha/lib_delegate/baking_state_types.ml index 2904339ddddd870ff886e2cab8dcd15513040086..e52b533842cb2e905cb43f1c31f47144d2322a32 100644 --- a/src/proto_alpha/lib_delegate/baking_state_types.ml +++ b/src/proto_alpha/lib_delegate/baking_state_types.ml @@ -183,6 +183,7 @@ module Delegate = struct companion_key = companion_bls_pkh_opt; delegate = manager_pkh; slots = _; + attesting_power = _; } = let open Lwt_syntax in match Key.Set.find_pkh consensus_pkh known_keys with diff --git a/src/proto_alpha/lib_delegate/operation_worker.ml b/src/proto_alpha/lib_delegate/operation_worker.ml index 000fe7a216aa09e573324027583372866a79e3d1..de2d0e9f3038fc6bade948632f2050e966a9a8f0 100644 --- a/src/proto_alpha/lib_delegate/operation_worker.ml +++ b/src/proto_alpha/lib_delegate/operation_worker.ml @@ -36,6 +36,8 @@ module Events = struct let pp_int = Format.pp_print_int + let pp_int_64 fmt = Format.fprintf fmt "%Ld" + let loop_failed = declare_1 ~section @@ -61,8 +63,8 @@ module Events = struct ~msg: "prequorum reached (voting power: {voting_power}, {preattestations} \ preattestations)" - ~pp1:pp_int - ("voting_power", Data_encoding.int31) + ~pp1:pp_int_64 + ("voting_power", Data_encoding.int64) ~pp2:pp_int ("preattestations", Data_encoding.int31) @@ -84,10 +86,10 @@ module Events = struct power: {voting_power}, {preattestations} preattestations)" ~pp1:pp_int ("count", Data_encoding.int31) - ~pp2:pp_int - ("delta_power", Data_encoding.int31) - ~pp3:pp_int - ("voting_power", Data_encoding.int31) + ~pp2:pp_int_64 + ("delta_power", Data_encoding.int64) + ~pp3:pp_int_64 + ("voting_power", Data_encoding.int64) ~pp4:pp_int ("preattestations", Data_encoding.int31) @@ -112,8 +114,8 @@ module Events = struct ~msg: "quorum reached (voting power: {voting_power}, {attestations} \ attestations)" - ~pp1:pp_int - ("voting_power", Data_encoding.int31) + ~pp1:pp_int_64 + ("voting_power", Data_encoding.int64) ~pp2:pp_int ("attestations", Data_encoding.int31) @@ -127,10 +129,10 @@ module Events = struct power: {voting_power}, {attestations} attestations)" ~pp1:pp_int ("count", Data_encoding.int31) - ~pp2:pp_int - ("delta_power", Data_encoding.int31) - ~pp3:pp_int - ("voting_power", Data_encoding.int31) + ~pp2:pp_int_64 + ("delta_power", Data_encoding.int64) + ~pp3:pp_int_64 + ("voting_power", Data_encoding.int64) ~pp4:pp_int ("attestations", Data_encoding.int31) @@ -268,10 +270,10 @@ end) type pqc_watched = { candidate_watched : candidate; - get_slot_voting_power : slot:Slot.t -> int option; - consensus_threshold : int; - consensus_committee : int; - mutable current_voting_power : int; + get_slot_voting_power : slot:Slot.t -> int64 option; + consensus_threshold : int64; + consensus_committee : int64; + mutable current_voting_power : int64; mutable preattestations_received : Preattestation_set.t; mutable preattestations_count : int; mutable previous_prequorum_progression : int; @@ -279,10 +281,10 @@ type pqc_watched = { type qc_watched = { candidate_watched : candidate; - get_slot_voting_power : slot:Slot.t -> int option; - consensus_threshold : int; - consensus_committee : int; - mutable current_voting_power : int; + get_slot_voting_power : slot:Slot.t -> int64 option; + consensus_threshold : int64; + consensus_committee : int64; + mutable current_voting_power : int64; mutable attestations_received : Attestation_set.t; mutable attestations_count : int; mutable previous_quorum_progression : int; @@ -386,13 +388,13 @@ let reset_monitoring state = match state.proposal_watched with | None -> return_unit | Some (Pqc_watch pqc_watched) -> - pqc_watched.current_voting_power <- 0 ; + pqc_watched.current_voting_power <- 0L ; pqc_watched.preattestations_count <- 0 ; pqc_watched.preattestations_received <- Preattestation_set.empty ; pqc_watched.previous_prequorum_progression <- 0 ; return_unit | Some (Qc_watch qc_watched) -> - qc_watched.current_voting_power <- 0 ; + qc_watched.current_voting_power <- 0L ; qc_watched.attestations_count <- 0 ; qc_watched.attestations_received <- Attestation_set.empty ; qc_watched.previous_quorum_progression <- 0 ; @@ -438,14 +440,14 @@ let update_pqc_monitoring ~pqc_watched ops = pqc_watched.preattestations_count <- succ pqc_watched.preattestations_count ; pqc_watched.current_voting_power <- - pqc_watched.current_voting_power + op_power + Int64.add pqc_watched.current_voting_power op_power | None -> (* preattestations that do not use the first slot of a delegate are not added to the quorum *) ())) fresh_preattestations ; let additional_voting_power = - pqc_watched.current_voting_power - current_voting_power + Int64.sub pqc_watched.current_voting_power current_voting_power in let additional_preattestations_count = pqc_watched.preattestations_count - preattestations_count @@ -492,14 +494,14 @@ let update_qc_monitoring ~qc_watched ops = qc_watched.attestations_count <- succ qc_watched.attestations_count ; qc_watched.current_voting_power <- - qc_watched.current_voting_power + op_power + Int64.add qc_watched.current_voting_power op_power | None -> (* attestations that do not use the first slot of a delegate are not added to the quorum *) ())) fresh_attestations ; let additional_voting_power = - qc_watched.current_voting_power - current_voting_power + Int64.sub qc_watched.current_voting_power current_voting_power in let additional_attestations_count = qc_watched.attestations_count - attestations_count @@ -544,8 +546,11 @@ let update_monitoring ?(should_lock = true) state ops = else let* () = let current_ratio = - pqc_watched.current_voting_power * 100 - / pqc_watched.consensus_committee + Int64.( + div + (mul pqc_watched.current_voting_power 100L) + pqc_watched.consensus_committee + |> to_int) in (* We only want to output an event if the quorum progression has progressed of at least [quorum_progression_increment] *) @@ -593,8 +598,11 @@ let update_monitoring ?(should_lock = true) state ops = else let* () = let current_ratio = - qc_watched.current_voting_power * 100 - / qc_watched.consensus_committee + Int64.( + div + (mul qc_watched.current_voting_power 100L) + qc_watched.consensus_committee + |> to_int) in (* We only want to output an event if the quorum progression has progressed of at least [quorum_progression_increment] *) @@ -640,7 +648,7 @@ let monitor_preattestation_quorum state ~consensus_threshold get_slot_voting_power; consensus_threshold; consensus_committee; - current_voting_power = 0; + current_voting_power = 0L; preattestations_received = Preattestation_set.empty; preattestations_count = 0; previous_prequorum_progression = 0; @@ -658,7 +666,7 @@ let monitor_attestation_quorum state ~consensus_threshold ~consensus_committee get_slot_voting_power; consensus_threshold; consensus_committee; - current_voting_power = 0; + current_voting_power = 0L; attestations_received = Attestation_set.empty; attestations_count = 0; previous_quorum_progression = 0; diff --git a/src/proto_alpha/lib_delegate/operation_worker.mli b/src/proto_alpha/lib_delegate/operation_worker.mli index 96d54f887c90591195c88001f54a356c7c9af63f..a76a818fb910812716f3036714862725e838a8e3 100644 --- a/src/proto_alpha/lib_delegate/operation_worker.mli +++ b/src/proto_alpha/lib_delegate/operation_worker.mli @@ -83,9 +83,9 @@ val get_quorum_event_stream : t -> event Lwt_stream.t *) val monitor_preattestation_quorum : t -> - consensus_threshold:int -> - consensus_committee:int -> - get_slot_voting_power:(slot:Slot.t -> int option) -> + consensus_threshold:int64 -> + consensus_committee:int64 -> + get_slot_voting_power:(slot:Slot.t -> int64 option) -> candidate -> unit Lwt.t @@ -96,9 +96,9 @@ val monitor_preattestation_quorum : *) val monitor_attestation_quorum : t -> - consensus_threshold:int -> - consensus_committee:int -> - get_slot_voting_power:(slot:Slot.t -> int option) -> + consensus_threshold:int64 -> + consensus_committee:int64 -> + get_slot_voting_power:(slot:Slot.t -> int64 option) -> candidate -> unit Lwt.t diff --git a/src/proto_alpha/lib_delegate/state_transitions.ml b/src/proto_alpha/lib_delegate/state_transitions.ml index 22b8c697110ec8b19ab856c43d0836956ce3d855..53bb4d06942108637fc4e1b2a891fc2588a2ff72 100644 --- a/src/proto_alpha/lib_delegate/state_transitions.ml +++ b/src/proto_alpha/lib_delegate/state_transitions.ml @@ -204,29 +204,30 @@ let extract_pqc state (new_proposal : proposal) = Delegate_slots.voting_power state.level_state.delegate_slots ~slot with | Some attesting_power -> attesting_power - | None -> 0 + | None -> 0L in List.fold_left (fun voting_power op -> let (Operation_data operation_data) = op.protocol_data in match operation_data.contents with | Single (Preattestation {slot; _}) -> - voting_power_of_slot slot + voting_power + Int64.add (voting_power_of_slot slot) voting_power | Single (Preattestations_aggregate {committee; _}) -> List.fold_left (fun aggregated_voting_power slot -> - voting_power_of_slot slot + aggregated_voting_power) - 0 + Int64.add + (voting_power_of_slot slot) + aggregated_voting_power) + 0L committee | _ -> voting_power) - 0 + 0L prequorum.preattestations in - (* TODO ABAAB *) let consensus_threshold = Delegate_slots.consensus_threshold state.level_state.delegate_slots in - if Compare.Int.(voting_power >= consensus_threshold) then + if Compare.Int64.(voting_power >= consensus_threshold) then Some (prequorum.preattestations, prequorum.round) else None diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 622a7948769799024922ee6646cc2e3377f54e7b..30123575cc5d2ea57009cf6717daac065635d3b8 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -3803,7 +3803,7 @@ module Attestation_rights = struct delegate : Signature.Public_key_hash.t; consensus_key : Signature.Public_key_hash.t; first_slot : Slot.t; - attestation_power : int; + attesting_power : int; } type t = { @@ -3815,14 +3815,14 @@ module Attestation_rights = struct let delegate_rights_encoding = let open Data_encoding in conv - (fun {delegate; consensus_key; first_slot; attestation_power} -> - (delegate, first_slot, attestation_power, consensus_key)) - (fun (delegate, first_slot, attestation_power, consensus_key) -> - {delegate; first_slot; attestation_power; consensus_key}) + (fun {delegate; consensus_key; first_slot; attesting_power} -> + (delegate, first_slot, attesting_power, consensus_key)) + (fun (delegate, first_slot, attesting_power, consensus_key) -> + {delegate; first_slot; attesting_power; consensus_key}) (obj4 (req "delegate" Signature.Public_key_hash.encoding) (req "first_slot" Slot.encoding) - (req "attestation_power" uint16) + (req "attesting_power" uint16) (req "consensus_key" Signature.Public_key_hash.encoding)) let encoding = @@ -3912,7 +3912,7 @@ module Attestation_rights = struct companion_pk = _; companion_pkh = _; }; - attestation_power; + attesting_power; dal_power = _; } : Consensus_key.power) @@ -3922,7 +3922,7 @@ module Attestation_rights = struct consensus_key; first_slot; (* TODO ABAAB (this RPC is only used for tests) *) - attestation_power = Attestation_power.get_slots attestation_power; + attesting_power = Attesting_power.get_slots attesting_power; } :: acc) rights @@ -3984,27 +3984,29 @@ module Validators = struct consensus_key : Signature.public_key_hash; companion_key : Bls.Public_key_hash.t option; slots : Slot.t list; + attesting_power : int64; } type t = { level : Raw_level.t; - consensus_threshold : int; - consensus_committee : int; + consensus_threshold : int64; + consensus_committee : int64; delegates : delegate list; } let delegate_encoding = let open Data_encoding in conv - (fun {delegate; consensus_key; companion_key; slots} -> - (delegate, slots, consensus_key, companion_key)) - (fun (delegate, slots, consensus_key, companion_key) -> - {delegate; consensus_key; companion_key; slots}) - (obj4 + (fun {delegate; consensus_key; companion_key; slots; attesting_power} -> + (delegate, slots, consensus_key, companion_key, attesting_power)) + (fun (delegate, slots, consensus_key, companion_key, attesting_power) -> + {delegate; consensus_key; companion_key; slots; attesting_power}) + (obj5 (req "delegate" Signature.Public_key_hash.encoding) (req "slots" (list Slot.encoding)) (req "consensus_key" Signature.Public_key_hash.encoding) - (opt "companion_key" Bls.Public_key_hash.encoding)) + (opt "companion_key" Bls.Public_key_hash.encoding) + (req "attesting_power" int64)) let encoding = let open Data_encoding in @@ -4015,8 +4017,8 @@ module Validators = struct {level; consensus_threshold; consensus_committee; delegates}) (obj4 (req "level" Raw_level.encoding) - (req "consensus_threshold" int31) - (req "consensus_committee" int31) + (req "consensus_threshold" int64) + (req "consensus_committee" int64) (req "delegates" (list delegate_encoding))) module S = struct @@ -4061,19 +4063,29 @@ module Validators = struct let attestation_slots_at_level ctxt level = let open Lwt_result_syntax in - let+ ctxt, rights = Baking.attesting_rights ctxt level in + let* ctxt, rights = Baking.attesting_rights ctxt level in let aggregate_attestation = Constants.aggregate_attestation ctxt in - ( ctxt, - Signature.Public_key_hash.Map.fold - (fun _pkh {Baking.delegate; consensus_key; companion_key; slots} acc -> - let companion_key = - match consensus_key with - | Bls _ when aggregate_attestation -> companion_key - | _ -> None - in - {delegate; consensus_key; companion_key; slots} :: acc) - rights - [] ) + return + ( ctxt, + Signature.Public_key_hash.Map.fold + (fun _pkh + { + Baking.delegate; + consensus_key; + companion_key; + slots; + attesting_power; + } + acc -> + let companion_key = + match consensus_key with + | Bls _ when aggregate_attestation -> companion_key + | _ -> None + in + {delegate; consensus_key; companion_key; slots; attesting_power} + :: acc) + rights + [] ) let register () = let open Lwt_result_syntax in @@ -4084,11 +4096,11 @@ module Validators = struct let+ _ctxt, rights = List.fold_left_es (fun (ctxt, acc) level -> - let consensus_threshold = - Attestation_power.consensus_threshold ctxt level + let* ctxt, consensus_threshold = + Attesting_power.consensus_threshold ctxt level in - let consensus_committee = - Attestation_power.consensus_committee ctxt level + let* ctxt, consensus_committee = + Attesting_power.consensus_committee ctxt level in let* ctxt, delegates = attestation_slots_at_level ctxt level in return diff --git a/src/proto_alpha/lib_plugin/adaptive_issuance_services.ml b/src/proto_alpha/lib_plugin/adaptive_issuance_services.ml index 9f9ae5092a418ef528319f475dc81fd1e68b3219..bb07e0e09572e38e31eb88302d304a92956cdbab 100644 --- a/src/proto_alpha/lib_plugin/adaptive_issuance_services.ml +++ b/src/proto_alpha/lib_plugin/adaptive_issuance_services.ml @@ -31,8 +31,8 @@ open Alpha_context type expected_rewards = { cycle : Cycle.t; baking_reward_fixed_portion : Tez.t; - baking_reward_bonus_per_slot : Tez.t; - attesting_reward_per_slot : Tez.t; + baking_reward_bonus_per_block : Tez.t; + attesting_reward_per_block : Tez.t; dal_attesting_reward_per_shard : Tez.t; seed_nonce_revelation_tip : Tez.t; vdf_revelation_tip : Tez.t; @@ -44,31 +44,31 @@ let expected_rewards_encoding : expected_rewards Data_encoding.t = (fun { cycle; baking_reward_fixed_portion; - baking_reward_bonus_per_slot; - attesting_reward_per_slot; + baking_reward_bonus_per_block; + attesting_reward_per_block; dal_attesting_reward_per_shard; seed_nonce_revelation_tip; vdf_revelation_tip; } -> ( cycle, baking_reward_fixed_portion, - baking_reward_bonus_per_slot, - attesting_reward_per_slot, + baking_reward_bonus_per_block, + attesting_reward_per_block, seed_nonce_revelation_tip, vdf_revelation_tip, dal_attesting_reward_per_shard )) (fun ( cycle, baking_reward_fixed_portion, - baking_reward_bonus_per_slot, - attesting_reward_per_slot, + baking_reward_bonus_per_block, + attesting_reward_per_block, seed_nonce_revelation_tip, vdf_revelation_tip, dal_attesting_reward_per_shard ) -> { cycle; baking_reward_fixed_portion; - baking_reward_bonus_per_slot; - attesting_reward_per_slot; + baking_reward_bonus_per_block; + attesting_reward_per_block; dal_attesting_reward_per_shard; seed_nonce_revelation_tip; vdf_revelation_tip; @@ -76,8 +76,8 @@ let expected_rewards_encoding : expected_rewards Data_encoding.t = (obj7 (req "cycle" Cycle.encoding) (req "baking_reward_fixed_portion" Tez.encoding) - (req "baking_reward_bonus_per_slot" Tez.encoding) - (req "attesting_reward_per_slot" Tez.encoding) + (req "baking_reward_bonus_per_block" Tez.encoding) + (req "attesting_reward_per_block" Tez.encoding) (req "seed_nonce_revelation_tip" Tez.encoding) (req "vdf_revelation_tip" Tez.encoding) (req "dal_attesting_reward_per_shard" Tez.encoding)) @@ -212,8 +212,10 @@ let collect_expected_rewards ~ctxt = let reward_of_cycle cycle = if Cycle.(cycle = ctxt_cycle) then let*? baking_reward_fixed_portion = baking_reward_fixed_portion ctxt in - let*? baking_reward_bonus_per_slot = baking_reward_bonus_per_slot ctxt in - let*? attesting_reward_per_slot = attesting_reward_per_slot ctxt in + let*? baking_reward_bonus_per_block = + baking_reward_bonus_per_block ctxt + in + let*? attesting_reward_per_block = attesting_reward_per_block ctxt in let*? dal_attesting_reward_per_shard = if csts.dal.incentives_enable then dal_attesting_reward_per_shard ctxt else ok Tez.zero @@ -224,8 +226,8 @@ let collect_expected_rewards ~ctxt = { cycle; baking_reward_fixed_portion; - baking_reward_bonus_per_slot; - attesting_reward_per_slot; + baking_reward_bonus_per_block; + attesting_reward_per_block; dal_attesting_reward_per_shard; seed_nonce_revelation_tip; vdf_revelation_tip; @@ -243,14 +245,17 @@ let collect_expected_rewards ~ctxt = csts ~reward_kind:Baking_reward_fixed_portion in - let*? baking_reward_bonus_per_slot = + let*? baking_reward_bonus_per_block = reward_from_constants ~coeff csts - ~reward_kind:Baking_reward_bonus_per_slot + ~reward_kind:Baking_reward_bonus_per_block in - let*? attesting_reward_per_slot = - reward_from_constants ~coeff csts ~reward_kind:Attesting_reward_per_slot + let*? attesting_reward_per_block = + reward_from_constants + ~coeff + csts + ~reward_kind:Attesting_reward_per_block in let*? dal_attesting_reward_per_shard = reward_from_constants @@ -268,8 +273,8 @@ let collect_expected_rewards ~ctxt = { cycle; baking_reward_fixed_portion; - baking_reward_bonus_per_slot; - attesting_reward_per_slot; + baking_reward_bonus_per_block; + attesting_reward_per_block; dal_attesting_reward_per_shard; seed_nonce_revelation_tip; vdf_revelation_tip; diff --git a/src/proto_alpha/lib_plugin/adaptive_issuance_services.mli b/src/proto_alpha/lib_plugin/adaptive_issuance_services.mli index 14c3465d47bd2b21e7a3621e44ee60fe6e02d1e1..4d7adbec6822b0d51bc08d09665b67291b2a465f 100644 --- a/src/proto_alpha/lib_plugin/adaptive_issuance_services.mli +++ b/src/proto_alpha/lib_plugin/adaptive_issuance_services.mli @@ -31,8 +31,8 @@ open Alpha_context type expected_rewards = { cycle : Cycle.t; baking_reward_fixed_portion : Tez.t; - baking_reward_bonus_per_slot : Tez.t; - attesting_reward_per_slot : Tez.t; + baking_reward_bonus_per_block : Tez.t; + attesting_reward_per_block : Tez.t; dal_attesting_reward_per_shard : Tez.t; seed_nonce_revelation_tip : Tez.t; vdf_revelation_tip : Tez.t; diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 8dfea6c7ed20c9862f76c97b73eacfb9a488614a..a79880431053e36f9381cb00d073091cc4ed4979 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -26,7 +26,7 @@ "Cycle_repr", "Tez_repr", "Deposits_repr", - "Attestation_power_repr", + "Attesting_power_repr", "Unstaked_frozen_deposits_repr", "Staking_pseudotoken_repr", "Period_repr", @@ -144,7 +144,6 @@ "Global_constants_costs", "Ticket_hash_builder", "Constants_storage", - "Consensus_parameters_storage", "Level_storage", "Cycle_storage", "Nonce_storage", @@ -182,6 +181,7 @@ "Delegate_storage", "Delegate_sampler", "Delegate_rewards", + "Consensus_parameters_storage", "Already_denounced_storage", "Dal_already_denounced_storage", "Delegate_missed_attestations_storage", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 2d5e35ff35614b654595af2fa6315150694b57b0..764a072ce6662b66a9099b2ed12e598007340367 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -650,6 +650,8 @@ module Stake_distribution = struct let slot_owner = Delegate_sampler.slot_owner + let stake_info_for_cycle = Delegate_sampler.stake_info_for_cycle + let stake_info = Delegate_sampler.stake_info let load_sampler_for_cycle = Delegate_sampler.load_sampler_for_cycle @@ -691,8 +693,8 @@ end module Migration = Migration_repr -module Attestation_power = struct - include Attestation_power_repr +module Attesting_power = struct + include Attesting_power_repr include Consensus_parameters_storage let get ctxt level {slots; stake} = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 78db318b79d07d343b06089adc4a639f56968c95..91bc6413e6a98d2a6d0913c0ee3a9fb81c48cdd9 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -153,6 +153,10 @@ module Tez : sig val div_exn : t -> int -> t + (** See {!Tez_repr.mul_ratio}. *) + val mul_ratio : + rounding:[`Down | `Up] -> t -> num:int64 -> den:int64 -> t tzresult + (** See {!Tez_repr.mul_percentage}. *) val mul_percentage : rounding:[`Down | `Up] -> t -> Percentage.t -> t end @@ -1053,7 +1057,7 @@ module Constants : sig val round_durations : context -> Round.round_durations (** To be used for rounds and DAL. For attestations, - see {!Attestation_power.consensus_committee}. *) + see {!Attesting_power.consensus_committee}. *) val consensus_committee_size : context -> int val minimal_participation_ratio : context -> Ratio.t @@ -2243,9 +2247,9 @@ module Receipt : sig val balance_updates_encoding : balance_updates Data_encoding.t end -(** This module re-exports definitions from {!Attestation_power_repr} and +(** This module re-exports definitions from {!Attesting_power_repr} and {!Consensus_parameters_storage}. *) -module Attestation_power : sig +module Attesting_power : sig type t val encoding : t Data_encoding.t @@ -2262,9 +2266,13 @@ module Attestation_power : sig val get_slots : t -> int - val consensus_threshold : context -> Level.t -> int + val check_all_bakers_attest_at_level : context -> Level.t -> bool + + val consensus_threshold : + context -> Level.t -> (context * int64) tzresult Lwt.t - val consensus_committee : context -> Level.t -> int + val consensus_committee : + context -> Level.t -> (context * int64) tzresult Lwt.t end (** This module re-exports definitions from {!Delegate_consensus_key}. *) @@ -2284,7 +2292,7 @@ module Consensus_key : sig type power = { consensus_key : pk; - attestation_power : Attestation_power.t; + attesting_power : Attesting_power.t; dal_power : int; } @@ -2449,9 +2457,9 @@ module Delegate : sig module Rewards : sig val baking_reward_fixed_portion : t -> Tez.t tzresult - val baking_reward_bonus_per_slot : t -> Tez.t tzresult + val baking_reward_bonus_per_block : t -> Tez.t tzresult - val attesting_reward_per_slot : t -> Tez.t tzresult + val attesting_reward_per_block : t -> Tez.t tzresult val dal_attesting_reward_per_shard : t -> Tez.t tzresult @@ -2464,8 +2472,8 @@ module Delegate : sig module For_RPC : sig type reward_kind = | Baking_reward_fixed_portion - | Baking_reward_bonus_per_slot - | Attesting_reward_per_slot + | Baking_reward_bonus_per_block + | Attesting_reward_per_block | Dal_attesting_reward_per_shard | Seed_nonce_revelation_tip | Vdf_revelation_tip @@ -5276,6 +5284,11 @@ module Stake_distribution : sig val slot_owner : context -> Level.t -> Slot.t -> (context * Consensus_key.pk) tzresult Lwt.t + val stake_info_for_cycle : + context -> + Cycle.t -> + (context * Int64.t * (Consensus_key.pk * Int64.t) list) tzresult Lwt.t + val stake_info : context -> Level.t -> @@ -5563,7 +5576,7 @@ module Consensus : sig and type 'a level_map := 'a Level.Map.t and type slot_set := Slot.Set.t and type round := Round.t - and type attestation_power := Attestation_power.t + and type attesting_power := Attesting_power.t and type consensus_power := Consensus_key.power (** [store_attestation_branch context branch] sets the "attestation branch" diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index d01d46a2c5c4846dbdbb94fc17a6664c3600ed90..97965b0f7afbc68041837bb3fe496e3ea174575f 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -2328,17 +2328,17 @@ let record_preattestation ctxt (mode : mode) (content : consensus_content) : in match mode with | Application _ | Full_construction _ -> - let*? {consensus_key; attestation_power; dal_power = _} = + let*? {consensus_key; attesting_power; dal_power = _} = find_in_slot_map content.slot (Consensus.allowed_preattestations ctxt) in let*? ctxt = Consensus.record_preattestation ctxt ~initial_slot:content.slot - ~power:attestation_power + ~power:attesting_power content.round in - return (ctxt, mk_preattestation_result consensus_key attestation_power) + return (ctxt, mk_preattestation_result consensus_key attesting_power) | Partial_construction _ -> (* In mempool mode, preattestations are allowed for various levels and rounds. We do not record preattestations because we could get @@ -2355,7 +2355,7 @@ let record_preattestation ctxt (mode : mode) (content : consensus_content) : ( ctxt, mk_preattestation_result consensus_key - Attestation_power.zero (* Fake power. *) ) + Attesting_power.zero (* Fake power. *) ) let record_dal_content ctxt slot ~dal_power = function | None -> Result.return ctxt @@ -2383,17 +2383,17 @@ let record_attestation ctxt (mode : mode) (consensus : consensus_content) in match mode with | Application _ | Full_construction _ -> - let*? {consensus_key; attestation_power; dal_power} = + let*? {consensus_key; attesting_power; dal_power} = find_in_slot_map consensus.slot (Consensus.allowed_attestations ctxt) in let*? ctxt = Consensus.record_attestation ctxt ~initial_slot:consensus.slot - ~power:attestation_power + ~power:attesting_power in let*? ctxt = record_dal_content ctxt consensus.slot ~dal_power dal in - return (ctxt, mk_attestation_result consensus_key attestation_power) + return (ctxt, mk_attestation_result consensus_key attesting_power) | Partial_construction _ -> (* In mempool mode, attestations are allowed for various levels and rounds. We do not record attestations because we could get @@ -2410,7 +2410,7 @@ let record_attestation ctxt (mode : mode) (consensus : consensus_content) ( ctxt, mk_attestation_result consensus_key - Attestation_power.zero (* Fake power. *) ) + Attesting_power.zero (* Fake power. *) ) let record_attestations_aggregate ctxt (mode : mode) committee : (context * Kind.attestations_aggregate contents_result_list) tzresult Lwt.t @@ -2425,7 +2425,7 @@ let record_attestations_aggregate ctxt (mode : mode) committee : (fun (ctxt, consensus_keys, consensus_power) (slot, dal) -> let* { consensus_key = {delegate; consensus_pkh; _}; - attestation_power; + attesting_power; dal_power; } = find_in_slot_map slot slot_map @@ -2434,15 +2434,15 @@ let record_attestations_aggregate ctxt (mode : mode) committee : Consensus.record_attestation ctxt ~initial_slot:slot - ~power:attestation_power + ~power:attesting_power in let* ctxt = record_dal_content ctxt slot ~dal_power dal in let key = ({delegate; consensus_pkh} : Consensus_key.t) in return ( ctxt, - (key, attestation_power) :: consensus_keys, - Attestation_power.add attestation_power consensus_power )) - (ctxt, [], Attestation_power.zero) + (key, attesting_power) :: consensus_keys, + Attesting_power.add attesting_power consensus_power )) + (ctxt, [], Attesting_power.zero) committee in let result = @@ -2483,7 +2483,7 @@ let record_preattestations_aggregate ctxt (mode : mode) (fun (ctxt, consensus_keys, consensus_power) slot -> let* { consensus_key = {delegate; consensus_pkh; _}; - attestation_power; + attesting_power; dal_power = _; } = find_in_slot_map slot slot_map @@ -2492,15 +2492,15 @@ let record_preattestations_aggregate ctxt (mode : mode) Consensus.record_preattestation ctxt ~initial_slot:slot - ~power:attestation_power + ~power:attesting_power round in let key = ({delegate; consensus_pkh} : Consensus_key.t) in return ( ctxt, - (key, attestation_power) :: consensus_keys, - Attestation_power.add attestation_power consensus_power )) - (ctxt, [], Attestation_power.zero) + (key, attesting_power) :: consensus_keys, + Attesting_power.add attesting_power consensus_power )) + (ctxt, [], Attesting_power.zero) committee in let result = @@ -3010,8 +3010,7 @@ let record_attesting_participation ctxt dal_attestation = | Some validators -> Slot.Map.fold_es (fun initial_slot - ({consensus_key; attestation_power; dal_power} : - Consensus_key.power) + ({consensus_key; attesting_power; dal_power} : Consensus_key.power) ctxt -> let participation = if Slot.Set.mem initial_slot (Consensus.attestations_seen ctxt) then @@ -3023,7 +3022,7 @@ let record_attesting_participation ctxt dal_attestation = ctxt ~delegate:consensus_key.delegate ~participation - ~attesting_slots:(Attestation_power.get_slots attestation_power) + ~attesting_slots:(Attesting_power.get_slots attesting_power) in Dal_apply.record_participation ctxt @@ -3220,7 +3219,7 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash (Gas.block_level ctxt) in let level = Level.current ctxt in - let attestation_power = Consensus.current_attestation_power ctxt in + let attesting_power = Consensus.current_attesting_power ctxt in let* required_attestations = are_attestations_required ctxt ~level:level.level in @@ -3246,7 +3245,7 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash if Round.(round = zero) then Consecutive_round_zero.incr ctxt else Consecutive_round_zero.reset ctxt in - (* end of level *) + (* end of level *) let* ctxt = match block_data_contents.Block_header.seed_nonce_hash with | None -> return ctxt @@ -3257,9 +3256,8 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash let* ctxt, reward_bonus = if required_attestations then let* ctxt = record_attesting_participation ctxt dal_attestation in - let*? rewards_bonus = - (* TODO ABAAB : only works if flag is false *) - Baking.bonus_baking_reward ctxt level ~attestation_power + let* ctxt, rewards_bonus = + Baking.bonus_baking_reward ctxt level ~attesting_power in return (ctxt, Some rewards_bonus) else return (ctxt, None) diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index bb8d28f19a76e44ffcb8a35d7cf60d44b4613f5c..71b05ac70f6de3f13f6056304cb00e9530458b7d 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -893,26 +893,26 @@ type 'kind contents_result = balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - consensus_power : Attestation_power.t; + consensus_power : Attesting_power.t; } -> Kind.preattestation contents_result | Attestation_result : { balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - consensus_power : Attestation_power.t; + consensus_power : Attesting_power.t; } -> Kind.attestation contents_result | Preattestations_aggregate_result : { balance_updates : Receipt.balance_updates; - committee : (Consensus_key.t * Attestation_power.t) list; - total_consensus_power : Attestation_power.t; + committee : (Consensus_key.t * Attesting_power.t) list; + total_consensus_power : Attesting_power.t; } -> Kind.preattestations_aggregate contents_result | Attestations_aggregate_result : { balance_updates : Receipt.balance_updates; - committee : (Consensus_key.t * Attestation_power.t) list; - total_consensus_power : Attestation_power.t; + committee : (Consensus_key.t * Attesting_power.t) list; + total_consensus_power : Attesting_power.t; } -> Kind.attestations_aggregate contents_result | Seed_nonce_revelation_result : @@ -1040,7 +1040,7 @@ module Encoding = struct obj4 (dft "balance_updates" Receipt.balance_updates_encoding []) (req "delegate" Signature.Public_key_hash.encoding) - (req "consensus_power" Attestation_power.encoding) + (req "consensus_power" Attesting_power.encoding) (req "consensus_key" Signature.Public_key_hash.encoding) let consensus_aggregate_result_encoding = @@ -1052,8 +1052,8 @@ module Encoding = struct (list (merge_objs Consensus_key.encoding - (obj1 (req "consensus_power" Attestation_power.encoding))))) - (req "total_consensus_power" Attestation_power.encoding) + (obj1 (req "consensus_power" Attesting_power.encoding))))) + (req "total_consensus_power" Attesting_power.encoding) type case = | Case : { diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 4bdfaa4012db72a1f75968dfd35104e7f817d77a..77842812276672a93ec79c518d31939610a2161e 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -69,26 +69,26 @@ and 'kind contents_result = balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - consensus_power : Attestation_power.t; + consensus_power : Attesting_power.t; } -> Kind.preattestation contents_result | Attestation_result : { balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - consensus_power : Attestation_power.t; + consensus_power : Attesting_power.t; } -> Kind.attestation contents_result | Preattestations_aggregate_result : { balance_updates : Receipt.balance_updates; - committee : (Consensus_key.t * Attestation_power.t) list; - total_consensus_power : Attestation_power.t; + committee : (Consensus_key.t * Attesting_power.t) list; + total_consensus_power : Attesting_power.t; } -> Kind.preattestations_aggregate contents_result | Attestations_aggregate_result : { balance_updates : Receipt.balance_updates; - committee : (Consensus_key.t * Attestation_power.t) list; - total_consensus_power : Attestation_power.t; + committee : (Consensus_key.t * Attesting_power.t) list; + total_consensus_power : Attesting_power.t; } -> Kind.attestations_aggregate contents_result | Seed_nonce_revelation_result : diff --git a/src/proto_alpha/lib_protocol/attestation_power_repr.ml b/src/proto_alpha/lib_protocol/attesting_power_repr.ml similarity index 100% rename from src/proto_alpha/lib_protocol/attestation_power_repr.ml rename to src/proto_alpha/lib_protocol/attesting_power_repr.ml diff --git a/src/proto_alpha/lib_protocol/attestation_power_repr.mli b/src/proto_alpha/lib_protocol/attesting_power_repr.mli similarity index 100% rename from src/proto_alpha/lib_protocol/attestation_power_repr.mli rename to src/proto_alpha/lib_protocol/attesting_power_repr.mli diff --git a/src/proto_alpha/lib_protocol/baking.ml b/src/proto_alpha/lib_protocol/baking.ml index 41be5dc8b4195f066cb11d4e4d5ad87ae0fde9bf..7a57ac6e8dd99556224b6d9c734e75aa00a58201 100644 --- a/src/proto_alpha/lib_protocol/baking.ml +++ b/src/proto_alpha/lib_protocol/baking.ml @@ -28,95 +28,148 @@ open Alpha_context type error += | (* `Permanent *) - Insufficient_attestation_power of { - attestation_power : int64; + Insufficient_attesting_power of { + attesting_power : int64; consensus_threshold : int64; } let () = register_error_kind `Permanent - ~id:"baking.insufficient_attestation_power" + ~id:"baking.insufficient_attesting_power" ~title:"Insufficient attestation power" ~description: - "The attestation power is insufficient to satisfy the consensus \ - threshold." - ~pp:(fun ppf (attestation_power, consensus_threshold) -> + "The attesting power is insufficient to satisfy the consensus threshold." + ~pp:(fun ppf (attesting_power, consensus_threshold) -> Format.fprintf ppf - "The attestation power (%Ld) is insufficient to satisfy the consensus \ + "The attesting power (%Ld) is insufficient to satisfy the consensus \ threshold (%Ld)." - attestation_power + attesting_power consensus_threshold) Data_encoding.( - obj2 (req "attestation_power" int64) (req "consensus_threshold" int64)) + obj2 (req "attesting_power" int64) (req "consensus_threshold" int64)) (function - | Insufficient_attestation_power {attestation_power; consensus_threshold} - -> - Some (attestation_power, consensus_threshold) + | Insufficient_attesting_power {attesting_power; consensus_threshold} -> + Some (attesting_power, consensus_threshold) | _ -> None) - (fun (attestation_power, consensus_threshold) -> - Insufficient_attestation_power {attestation_power; consensus_threshold}) + (fun (attesting_power, consensus_threshold) -> + Insufficient_attesting_power {attesting_power; consensus_threshold}) -let bonus_baking_reward ctxt level ~attestation_power = - let open Result_syntax in - (* TODO ABAAB : only works if flag is false *) - let attestation_power = Attestation_power.get ctxt level attestation_power in - let consensus_threshold_size = - Attestation_power.consensus_threshold ctxt level |> Int64.of_int +let bonus_baking_reward ctxt level ~attesting_power = + let open Lwt_result_syntax in + let attesting_power = Attesting_power.get ctxt level attesting_power in + let* ctxt, consensus_threshold = + Attesting_power.consensus_threshold ctxt level in - let* baking_reward_bonus_per_slot = - Delegate.Rewards.baking_reward_bonus_per_slot ctxt + let* ctxt, consensus_committee = + Attesting_power.consensus_committee ctxt level in - let extra_attestation_power = - Int64.sub attestation_power consensus_threshold_size + let*? baking_reward_bonus_per_block = + Delegate.Rewards.baking_reward_bonus_per_block ctxt in - let* () = + let extra_attesting_power = Int64.sub attesting_power consensus_threshold in + let*? () = error_when - Compare.Int64.(extra_attestation_power < 0L) - (Insufficient_attestation_power - {attestation_power; consensus_threshold = consensus_threshold_size}) + Compare.Int64.(extra_attesting_power < 0L) + (Insufficient_attesting_power {attesting_power; consensus_threshold}) + in + let max_extra_attesting_power = + Int64.sub consensus_committee consensus_threshold + in + (* Reward computation depends on the flag. If not activated, we keep the same + rewards as before: division then multiplication. It activated, we have to change + the order of operations (because the division will always result in 0 otherwise). *) + let* reward = + if Compare.Int64.(max_extra_attesting_power <= 0L) then return (Ok Tez.zero) + else if Attesting_power.check_all_bakers_attest_at_level ctxt level then + return + @@ Tez.mul_ratio + ~rounding:`Up + ~num:extra_attesting_power + ~den:max_extra_attesting_power + baking_reward_bonus_per_block + else + let*? part = + Tez.(baking_reward_bonus_per_block /? max_extra_attesting_power) + in + return Tez.(part *? extra_attesting_power) in - Tez.(baking_reward_bonus_per_slot *? extra_attestation_power) + let*? reward in + return (ctxt, reward) type ordered_slots = { delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; companion_key : Bls.Public_key_hash.t option; slots : Slot.t list; + attesting_power : int64; } (* Slots returned by this function are assumed by consumers to be in increasing order, hence the use of [Slot.Range.rev_fold_es]. *) let attesting_rights (ctxt : t) level = let consensus_committee_size = Constants.consensus_committee_size ctxt in + let all_bakers_attest_enabled = + Attesting_power.check_all_bakers_attest_at_level ctxt level + in let open Lwt_result_syntax in + let* ctxt, _, delegates = Stake_distribution.stake_info ctxt level in + let* attesting_power_map = + List.fold_left_es + (fun acc_map ((consensus_pk : Consensus_key.pk), power) -> + let acc_map = + Signature.Public_key_hash.Map.add consensus_pk.delegate power acc_map + in + return acc_map) + Signature.Public_key_hash.Map.empty + delegates + in let*? slots = Slot.Range.create ~min:0 ~count:consensus_committee_size in - Slot.Range.rev_fold_es - (fun (ctxt, map) slot -> - let* ctxt, consensus_pk = Stake_distribution.slot_owner ctxt level slot in - let map = - Signature.Public_key_hash.Map.update - consensus_pk.delegate - (function - | None -> - Some - { - delegate = consensus_pk.delegate; - consensus_key = consensus_pk.consensus_pkh; - companion_key = consensus_pk.companion_pkh; - slots = [slot]; - } - | Some slots -> Some {slots with slots = slot :: slots.slots}) - map - in - return (ctxt, map)) - (ctxt, Signature.Public_key_hash.Map.empty) - slots + let* ctxt, map = + Slot.Range.rev_fold_es + (fun (ctxt, map) slot -> + let* ctxt, consensus_pk = + Stake_distribution.slot_owner ctxt level slot + in + let map = + Signature.Public_key_hash.Map.update + consensus_pk.delegate + (function + | None -> + Some + { + delegate = consensus_pk.delegate; + consensus_key = consensus_pk.consensus_pkh; + companion_key = consensus_pk.companion_pkh; + slots = [slot]; + attesting_power = 0L; + (* Updated after, once all the slots are attributed *) + } + | Some slots -> Some {slots with slots = slot :: slots.slots}) + map + in + return (ctxt, map)) + (ctxt, Signature.Public_key_hash.Map.empty) + slots + in + let map = + Signature.Public_key_hash.Map.map + (fun ({slots; delegate; _} as t) -> + if all_bakers_attest_enabled then + let attesting_power = + Option.value ~default:0L + @@ Signature.Public_key_hash.Map.find delegate attesting_power_map + in + {t with attesting_power} + else {t with attesting_power = List.length slots |> Int64.of_int}) + map + in + return (ctxt, map) let incr_slot att_rights = - let one = Attestation_power.make ~slots:1 ~stake:0L in - Attestation_power.add one att_rights + let one = Attesting_power.make ~slots:1 ~stake:0L in + Attesting_power.add one att_rights let attesting_rights_by_first_slot ctxt level : (t * Consensus_key.power Slot.Map.t) tzresult Lwt.t = @@ -158,18 +211,18 @@ let attesting_rights_by_first_slot ctxt level : Some { consensus_key; - attestation_power = - incr_slot Attestation_power.zero + attesting_power = + incr_slot Attesting_power.zero (* stake added in the next step *); dal_power = in_dal_committee; } | Some - ({consensus_key; attestation_power; dal_power} : + ({consensus_key; attesting_power; dal_power} : Consensus_key.power) -> Some { consensus_key; - attestation_power = incr_slot attestation_power; + attesting_power = incr_slot attesting_power; dal_power = dal_power + in_dal_committee; }) slots_map @@ -194,9 +247,9 @@ let attesting_rights_by_first_slot ctxt level : slot { v with - attestation_power = - Attestation_power.( - add (make ~slots:0 ~stake:weight) v.attestation_power); + attesting_power = + Attesting_power.( + add (make ~slots:0 ~stake:weight) v.attesting_power); } acc)) Slot.Map.empty diff --git a/src/proto_alpha/lib_protocol/baking.mli b/src/proto_alpha/lib_protocol/baking.mli index 9ccc224fbae81dbc6b3d530a4648d0f1d2c51389..b1f113c8eaeb1c09e07d055cc6eb4b5c1b2e2619 100644 --- a/src/proto_alpha/lib_protocol/baking.mli +++ b/src/proto_alpha/lib_protocol/baking.mli @@ -28,8 +28,8 @@ open Alpha_context type error += | (* `Permanent *) - Insufficient_attestation_power of { - attestation_power : int64; + Insufficient_attesting_power of { + attesting_power : int64; consensus_threshold : int64; } @@ -38,6 +38,7 @@ type ordered_slots = private { consensus_key : Signature.public_key_hash; companion_key : Bls.Public_key_hash.t option; slots : Slot.t list; + attesting_power : int64; } (** For a given level computes who has the right to include an attestation in @@ -63,4 +64,7 @@ val attesting_rights_by_first_slot : (** Computes the bonus baking reward depending on the attestation power. *) val bonus_baking_reward : - context -> Level.t -> attestation_power:Attestation_power.t -> Tez.t tzresult + context -> + Level.t -> + attesting_power:Attesting_power.t -> + (context * Tez.t) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/consensus_parameters_storage.ml b/src/proto_alpha/lib_protocol/consensus_parameters_storage.ml index 22361c7490ec75ebd0614400ad8c397c2d42ffa4..37918512721b06bd0cb13836ace8c791032361f6 100644 --- a/src/proto_alpha/lib_protocol/consensus_parameters_storage.ml +++ b/src/proto_alpha/lib_protocol/consensus_parameters_storage.ml @@ -10,8 +10,31 @@ let check_all_bakers_attest_at_level ctxt level = | None -> false | Some act_level -> Raw_level_repr.(level.Level_repr.level >= act_level) -let consensus_threshold ctxt _level = - Constants_storage.consensus_threshold_size ctxt +let consensus_committee ctxt level = + let open Lwt_result_syntax in + if check_all_bakers_attest_at_level ctxt level then + let* ctxt, total_staking_weight, _ = + Delegate_sampler.stake_info ctxt level + in + return (ctxt, total_staking_weight) + else + return + (ctxt, Int64.of_int @@ Constants_storage.consensus_committee_size ctxt) -let consensus_committee ctxt _level = - Constants_storage.consensus_committee_size ctxt +let consensus_threshold ctxt level = + let open Lwt_result_syntax in + if check_all_bakers_attest_at_level ctxt level then + let* ctxt, committee = consensus_committee ctxt level in + let const_committee = + Int64.of_int @@ Constants_storage.consensus_committee_size ctxt + in + let const_threshold = + Int64.of_int @@ Constants_storage.consensus_threshold_size ctxt + in + let threshold = + Int64.(mul const_threshold (div committee const_committee)) + in + return (ctxt, threshold) + else + return + (ctxt, Int64.of_int @@ Constants_storage.consensus_threshold_size ctxt) diff --git a/src/proto_alpha/lib_protocol/consensus_parameters_storage.mli b/src/proto_alpha/lib_protocol/consensus_parameters_storage.mli index b5c1094c95a9207a5f519e4642fb7cbc58136af8..4c058951709070247fc1ceb21868f61aa369258b 100644 --- a/src/proto_alpha/lib_protocol/consensus_parameters_storage.mli +++ b/src/proto_alpha/lib_protocol/consensus_parameters_storage.mli @@ -9,6 +9,8 @@ level, all bakers were allowed (and expected) to attest. *) val check_all_bakers_attest_at_level : Raw_context.t -> Level_repr.t -> bool -val consensus_threshold : Raw_context.t -> Level_repr.t -> int +val consensus_threshold : + Raw_context.t -> Level_repr.t -> (Raw_context.t * int64) tzresult Lwt.t -val consensus_committee : Raw_context.t -> Level_repr.t -> int +val consensus_committee : + Raw_context.t -> Level_repr.t -> (Raw_context.t * int64) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml index 66deb6f268e651bf18754a04cb9f63275175b4ef..a4393e4e91f656f9095036319ef066abcf3f1d21 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml @@ -128,7 +128,7 @@ type pk = Raw_context.consensus_pk = { type power = Raw_context.consensus_power = { consensus_key : pk; - attestation_power : Attestation_power_repr.t; + attesting_power : Attesting_power_repr.t; dal_power : int; } diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.mli b/src/proto_alpha/lib_protocol/delegate_consensus_key.mli index 7be5382d70e392b2b4e31d3eab97eb6f6c0c2fba..919dde3023cf1e40c374c92b53f41d7696926936 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.mli +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.mli @@ -53,7 +53,7 @@ type pk = Raw_context.consensus_pk = { (** The attesting and dal power related to the associated consensus key *) type power = Raw_context.consensus_power = { consensus_key : pk; - attestation_power : Attestation_power_repr.t; + attesting_power : Attesting_power_repr.t; dal_power : int; } diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index 38b0e96c9c64741a35534577990502bede553e6d..9f3949710a972ce5da020b2fcfbdd6e8c701453b 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -132,8 +132,21 @@ let maybe_distribute_dal_attesting_rewards ctxt delegate ~gets_consensus_rewards (* This includes DAL rewards. *) let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = let open Lwt_result_syntax in - let*? attesting_reward_per_slot = - Delegate_rewards.attesting_reward_per_slot ctxt + let cycle_eras = Raw_context.cycle_eras ctxt in + let first_level = + Level_repr.first_level_in_cycle_from_eras ~cycle_eras last_cycle + in + let all_bakers_attest_enabled = + Consensus_parameters_storage.check_all_bakers_attest_at_level + ctxt + first_level + in + let*? attesting_reward_per_block = + Delegate_rewards.attesting_reward_per_block ctxt + in + (* Attesting power is staking power *) + let* ctxt, total_active_stake_weight, _ = + Delegate_sampler.stake_info_for_cycle ctxt last_cycle in let unrevealed_nonces_set = List.fold_left @@ -142,12 +155,6 @@ let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = Signature.Public_key_hash.Set.empty unrevealed_nonces in - let* total_active_stake = - Stake_storage.get_total_active_stake ctxt last_cycle - in - let total_active_stake_weight = - Stake_repr.staking_weight total_active_stake - in let* dal_attesting_reward_per_shard = Raw_context.Dal.only_if_incentives_enabled ctxt @@ -158,6 +165,8 @@ let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = in return @@ Some dal_attesting_reward_per_shard) in + (* We cannot use the cached stake info: the detailed stake is needed for reward + distribution, but it is not cached. *) let* delegates = Stake_storage.get_selected_distribution ctxt last_cycle in List.fold_left_es (fun (ctxt, balance_updates) (delegate, active_stake) -> @@ -171,14 +180,14 @@ let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = delegate_has_revealed_nonces delegate unrevealed_nonces_set in let active_stake_weight = Stake_repr.staking_weight active_stake in - let expected_slots = - Delegate_missed_attestations_storage - .expected_slots_for_given_active_stake + let*? rewards = + Delegate_missed_attestations_storage.attestation_rewards_per_cycle ctxt + ~all_bakers_attest_enabled ~total_active_stake_weight ~active_stake_weight + ~rewards_per_block:attesting_reward_per_block in - let rewards = Tez_repr.mul_exn attesting_reward_per_slot expected_slots in let gets_consensus_rewards = sufficient_participation && has_revealed_nonces in diff --git a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml index c22c88e7ab5579ccf3979d0b5bee0cedd63ea81d..a21307a7a8a6dcb8f90e0e65a198864e31b7f5d1 100644 --- a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml @@ -43,6 +43,38 @@ let expected_slots_for_given_active_stake ctxt ~total_active_stake_weight (Z.of_int number_of_attestations_per_cycle)) (Z.of_int64 total_active_stake_weight)) +(* The rewards depend on the flag status. In essence, the rewards should be about + the same, but a bit more accurate since we don't quantize with slots. + We also round up to ensure all attesters get rewarded, even if their stake + is incredibly low. *) +let attestation_rewards_per_cycle ctxt ~all_bakers_attest_enabled + ~total_active_stake_weight ~active_stake_weight ~rewards_per_block = + let open Result_syntax in + let* rewards = + if all_bakers_attest_enabled then + let blocks_per_cycle = + Z.of_int32 (Constants_storage.blocks_per_cycle ctxt) + in + let num = Z.(mul (of_int64 active_stake_weight) blocks_per_cycle) in + let den = Z.of_int64 total_active_stake_weight in + Tez_repr.mul_ratio_z ~rounding:`Up ~num ~den rewards_per_block + else + let consensus_committee_size = + Constants_storage.consensus_committee_size ctxt + in + let rewards_per_slot = + Tez_repr.div_exn rewards_per_block consensus_committee_size + in + let expected_slots = + expected_slots_for_given_active_stake + ctxt + ~total_active_stake_weight + ~active_stake_weight + in + return Tez_repr.(mul_exn rewards_per_slot expected_slots) + in + return rewards + let expected_dal_shards_per_slot_for_given_active_stake ctxt ~total_active_stake_weight ~active_stake_weight = let blocks_per_cycle = @@ -289,14 +321,11 @@ module For_RPC = struct expected_attesting_rewards = Tez_repr.zero; } | Some active_stake -> - let* total_active_stake = - Stake_storage.get_total_active_stake ctxt level.cycle + let* ctxt, total_active_stake_weight, _ = + Delegate_sampler.stake_info ctxt level in + let active_stake_weight = Stake_repr.staking_weight active_stake in let expected_cycle_activity = - let active_stake_weight = Stake_repr.staking_weight active_stake in - let total_active_stake_weight = - Stake_repr.staking_weight total_active_stake - in expected_slots_for_given_active_stake ctxt ~total_active_stake_weight @@ -305,8 +334,13 @@ module For_RPC = struct let Ratio_repr.{numerator; denominator} = Constants_storage.minimal_participation_ratio ctxt in - let*? attesting_reward_per_slot = - Delegate_rewards.attesting_reward_per_slot ctxt + let*? rewards_per_block = + Delegate_rewards.attesting_reward_per_block ctxt + in + let all_bakers_attest_enabled = + Consensus_parameters_storage.check_all_bakers_attest_at_level + ctxt + level in let minimal_cycle_activity = expected_cycle_activity * numerator / denominator @@ -314,8 +348,13 @@ module For_RPC = struct let maximal_cycle_inactivity = expected_cycle_activity - minimal_cycle_activity in - let expected_attesting_rewards = - Tez_repr.mul_exn attesting_reward_per_slot expected_cycle_activity + let*? expected_attesting_rewards = + attestation_rewards_per_cycle + ctxt + ~all_bakers_attest_enabled + ~total_active_stake_weight + ~active_stake_weight + ~rewards_per_block in let contract = Contract_repr.Implicit delegate in let* missed_attestations = diff --git a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli index fa4d610f9e7d62c0fb8e822f5b94049bca154353..2939e00e7271ee9b4465f1e2169e20bd8daef4b2 100644 --- a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli +++ b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli @@ -30,14 +30,14 @@ This module is responsible for maintaining the {!Storage.Contract.Missed_attestations} table. *) -(** Computes the number of validator slots that a delegate is expected to be - allocated during a cycle. This number is proportional to its active stake - wrt total active stake. *) -val expected_slots_for_given_active_stake : +(** Computes the total rewards over a cycle for a given portion of the stake *) +val attestation_rewards_per_cycle : Raw_context.t -> + all_bakers_attest_enabled:bool -> total_active_stake_weight:int64 -> active_stake_weight:int64 -> - int + rewards_per_block:Tez_repr.t -> + Tez_repr.t tzresult (** Computes the number of DAL shards that a delegate is expected to be allocated during a cycle per DAL slot. This number is proportional to its diff --git a/src/proto_alpha/lib_protocol/delegate_rewards.ml b/src/proto_alpha/lib_protocol/delegate_rewards.ml index 510ad06937d10b4c3fbf7b580c50083f5b74dfa5..fa6b065055fabd5350732565a04a8c345b66c6ec 100644 --- a/src/proto_alpha/lib_protocol/delegate_rewards.ml +++ b/src/proto_alpha/lib_protocol/delegate_rewards.ml @@ -74,8 +74,8 @@ let tez_from_weights module M = struct type reward_kind = | Baking_reward_fixed_portion - | Baking_reward_bonus_per_slot - | Attesting_reward_per_slot + | Baking_reward_bonus_per_block + | Attesting_reward_per_block | Dal_attesting_reward_per_shard | Seed_nonce_revelation_tip | Vdf_revelation_tip @@ -89,9 +89,9 @@ module M = struct match reward_kind with | Baking_reward_fixed_portion -> issuance_weights.baking_reward_fixed_portion_weight - | Baking_reward_bonus_per_slot -> + | Baking_reward_bonus_per_block -> issuance_weights.baking_reward_bonus_weight - | Attesting_reward_per_slot -> issuance_weights.attesting_reward_weight + | Attesting_reward_per_block -> issuance_weights.attesting_reward_weight | Dal_attesting_reward_per_shard -> if dal_incentives_enabled then issuance_weights.dal_rewards_weight else 0 @@ -115,22 +115,14 @@ module M = struct in let base_rewards = match reward_kind with - (* Since these the "_per_slot" rewards are given per slot, they do not depend on whether - all bakers attest or not. We can use the constants directly. *) - (* TODO ABAAB: baking bonus and attesting rewards without slots *) - | Baking_reward_bonus_per_slot -> - let bonus_committee_size = - csts.consensus_committee_size - csts.consensus_threshold_size - in - if Compare.Int.(bonus_committee_size <= 0) then Tez_repr.zero - else Tez_repr.div_exn rewards bonus_committee_size - | Attesting_reward_per_slot -> - Tez_repr.div_exn rewards csts.consensus_committee_size | Dal_attesting_reward_per_shard -> Tez_repr.div_exn rewards csts.dal.cryptobox_parameters.number_of_shards - | _ -> rewards + | Baking_reward_fixed_portion | Baking_reward_bonus_per_block + | Attesting_reward_per_block | Seed_nonce_revelation_tip + | Vdf_revelation_tip -> + rewards in Tez_repr.mul_q ~rounding:`Down base_rewards coeff @@ -156,11 +148,11 @@ let reward_from_context ~ctxt ~reward_kind = let baking_reward_fixed_portion ctxt = reward_from_context ~ctxt ~reward_kind:Baking_reward_fixed_portion -let baking_reward_bonus_per_slot ctxt = - reward_from_context ~ctxt ~reward_kind:Baking_reward_bonus_per_slot +let baking_reward_bonus_per_block ctxt = + reward_from_context ~ctxt ~reward_kind:Baking_reward_bonus_per_block -let attesting_reward_per_slot ctxt = - reward_from_context ~ctxt ~reward_kind:Attesting_reward_per_slot +let attesting_reward_per_block ctxt = + reward_from_context ~ctxt ~reward_kind:Attesting_reward_per_block let dal_attesting_reward_per_shard ctxt = reward_from_context ~ctxt ~reward_kind:Dal_attesting_reward_per_shard diff --git a/src/proto_alpha/lib_protocol/delegate_rewards.mli b/src/proto_alpha/lib_protocol/delegate_rewards.mli index 0aa8300da78167212e0424cae1ecec71a4e85f3a..7cfa1090a092eca6aedecbee890d50496b406a9d 100644 --- a/src/proto_alpha/lib_protocol/delegate_rewards.mli +++ b/src/proto_alpha/lib_protocol/delegate_rewards.mli @@ -27,9 +27,9 @@ val baking_reward_fixed_portion : Raw_context.t -> Tez_repr.t tzresult -val baking_reward_bonus_per_slot : Raw_context.t -> Tez_repr.t tzresult +val baking_reward_bonus_per_block : Raw_context.t -> Tez_repr.t tzresult -val attesting_reward_per_slot : Raw_context.t -> Tez_repr.t tzresult +val attesting_reward_per_block : Raw_context.t -> Tez_repr.t tzresult val dal_attesting_reward_per_shard : Raw_context.t -> Tez_repr.t tzresult @@ -42,8 +42,8 @@ val vdf_revelation_tip : Raw_context.t -> Tez_repr.t tzresult module For_RPC : sig type reward_kind = | Baking_reward_fixed_portion - | Baking_reward_bonus_per_slot - | Attesting_reward_per_slot + | Baking_reward_bonus_per_block + | Attesting_reward_per_block | Dal_attesting_reward_per_shard | Seed_nonce_revelation_tip | Vdf_revelation_tip diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.ml b/src/proto_alpha/lib_protocol/delegate_sampler.ml index af73de9fc7db22747576b6e06342b25dcf9487cb..e006aaa9869625f4061282162febd2bc49810ac0 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.ml +++ b/src/proto_alpha/lib_protocol/delegate_sampler.ml @@ -287,28 +287,41 @@ let clear_outdated_sampling_data ctxt ~new_cycle = let* ctxt = Delegate_sampler_state.remove_existing ctxt outdated_cycle in Seed_storage.remove_for_cycle ctxt outdated_cycle -(* This function is relevant only when all bakers don't attest *) -let attesting_rights_count ctxt level = - assert ( - not - (Consensus_parameters_storage.check_all_bakers_attest_at_level ctxt level)) ; - let consensus_committee_size = - Constants_storage.consensus_committee_size ctxt - in +let attesting_power ~all_bakers_attest_enabled ctxt level = let open Lwt_result_syntax in - let*? slots = Slot_repr.Range.create ~min:0 ~count:consensus_committee_size in - Slot_repr.Range.fold_es - (fun (ctxt, map) slot -> - let* ctxt, consensus_pk = slot_owner ctxt level slot in - let map = - Signature.Public_key_hash.Map.update - consensus_pk.delegate - (function None -> Some 1 | Some slots_n -> Some (slots_n + 1)) - map - in - return (ctxt, map)) - (ctxt, Signature.Public_key_hash.Map.empty) - slots + if all_bakers_attest_enabled then + let* ctxt, _, delegates = stake_info ctxt level in + let map = + List.fold_left + (fun map_acc ((consensus_pk : Raw_context.consensus_pk), staking_power) -> + Signature.Public_key_hash.Map.add + consensus_pk.delegate + staking_power + map_acc) + Signature.Public_key_hash.Map.empty + delegates + in + return (ctxt, map) + else + let consensus_committee_size = + Constants_storage.consensus_committee_size ctxt + in + let*? slots = + Slot_repr.Range.create ~min:0 ~count:consensus_committee_size + in + Slot_repr.Range.fold_es + (fun (ctxt, map) slot -> + let* ctxt, consensus_pk = slot_owner ctxt level slot in + let map = + Signature.Public_key_hash.Map.update + consensus_pk.delegate + (function + | None -> Some 1L | Some slots_n -> Some (Int64.succ slots_n)) + map + in + return (ctxt, map)) + (ctxt, Signature.Public_key_hash.Map.empty) + slots let cleanup_values_for_protocol_t ctxt ~previous_consensus_rights_delay ~consensus_rights_delay ~new_cycle = diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.mli b/src/proto_alpha/lib_protocol/delegate_sampler.mli index 13a507807a265e2539ecbec904e4257a549f23ff..c0458d975d2c1e0dffd75e0d9a6bdbb7f5b4d5cf 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.mli +++ b/src/proto_alpha/lib_protocol/delegate_sampler.mli @@ -61,6 +61,20 @@ val baking_rights_owner : val load_sampler_for_cycle : Raw_context.t -> Cycle_repr.t -> Raw_context.t tzresult Lwt.t +(** [stake_info_for_cycle ctxt cycle] reads the stake info for [cycle] from + [ctxt] if it has been previously initialized. Otherwise it initializes + the sampler and caches it in [ctxt] with + [Raw_context.set_stake_info_for_cycle]. + Returns the updated context, the total staking power active for the cycle, + and the list of all delegates with their respective active staking power. *) +val stake_info_for_cycle : + Raw_context.t -> + Cycle_repr.t -> + (Raw_context.t * Int64.t * (Delegate_consensus_key.pk * Int64.t) list) + tzresult + Lwt.t + +(** Same as [stake_info_for_cycle], but for the given level (uses the level's cycle) *) val stake_info : Raw_context.t -> Level_repr.t -> @@ -85,13 +99,14 @@ val clear_outdated_sampling_data : val select_distribution_for_cycle : Raw_context.t -> Cycle_repr.t -> Raw_context.t tzresult Lwt.t -(** [attesting_rights_count ctxt level] returns a map of the delegates to - their number of attestation slots for the given level. Fails if the +(** [attesting_power ctxt level] returns a map of the delegates to + their attesting power for the given level. Fails if the given level is in a cycle for which the seed is not in the storage *) -val attesting_rights_count : +val attesting_power : + all_bakers_attest_enabled:bool -> Raw_context.t -> Level_repr.t -> - (Raw_context.t * int Signature.Public_key_hash.Map.t) tzresult Lwt.t + (Raw_context.t * int64 Signature.Public_key_hash.Map.t) tzresult Lwt.t val cleanup_values_for_protocol_t : Raw_context.t -> diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index bc02145ac528a14581064f032baf0fa34399ad8b..fa81fbafe08b8a307dcdc6e01e568a5ae7017456 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -54,7 +54,7 @@ Cycle_repr Tez_repr Deposits_repr - Attestation_power_repr + Attesting_power_repr Unstaked_frozen_deposits_repr Staking_pseudotoken_repr Period_repr @@ -163,7 +163,6 @@ Global_constants_costs Ticket_hash_builder Constants_storage - Consensus_parameters_storage Level_storage Cycle_storage Nonce_storage @@ -198,6 +197,7 @@ Delegate_storage Delegate_sampler Delegate_rewards + Consensus_parameters_storage Already_denounced_storage Dal_already_denounced_storage Delegate_missed_attestations_storage @@ -346,7 +346,7 @@ cycle_repr.ml cycle_repr.mli tez_repr.ml tez_repr.mli deposits_repr.ml deposits_repr.mli - attestation_power_repr.ml attestation_power_repr.mli + attesting_power_repr.ml attesting_power_repr.mli unstaked_frozen_deposits_repr.ml unstaked_frozen_deposits_repr.mli staking_pseudotoken_repr.ml staking_pseudotoken_repr.mli period_repr.ml period_repr.mli @@ -458,7 +458,6 @@ global_constants_costs.ml global_constants_costs.mli ticket_hash_builder.ml ticket_hash_builder.mli constants_storage.ml constants_storage.mli - consensus_parameters_storage.ml consensus_parameters_storage.mli level_storage.ml level_storage.mli cycle_storage.ml cycle_storage.mli nonce_storage.ml nonce_storage.mli @@ -493,6 +492,7 @@ delegate_storage.ml delegate_storage.mli delegate_sampler.ml delegate_sampler.mli delegate_rewards.ml delegate_rewards.mli + consensus_parameters_storage.ml consensus_parameters_storage.mli already_denounced_storage.ml already_denounced_storage.mli dal_already_denounced_storage.ml dal_already_denounced_storage.mli delegate_missed_attestations_storage.ml @@ -643,7 +643,7 @@ cycle_repr.ml cycle_repr.mli tez_repr.ml tez_repr.mli deposits_repr.ml deposits_repr.mli - attestation_power_repr.ml attestation_power_repr.mli + attesting_power_repr.ml attesting_power_repr.mli unstaked_frozen_deposits_repr.ml unstaked_frozen_deposits_repr.mli staking_pseudotoken_repr.ml staking_pseudotoken_repr.mli period_repr.ml period_repr.mli @@ -755,7 +755,6 @@ global_constants_costs.ml global_constants_costs.mli ticket_hash_builder.ml ticket_hash_builder.mli constants_storage.ml constants_storage.mli - consensus_parameters_storage.ml consensus_parameters_storage.mli level_storage.ml level_storage.mli cycle_storage.ml cycle_storage.mli nonce_storage.ml nonce_storage.mli @@ -790,6 +789,7 @@ delegate_storage.ml delegate_storage.mli delegate_sampler.ml delegate_sampler.mli delegate_rewards.ml delegate_rewards.mli + consensus_parameters_storage.ml consensus_parameters_storage.mli already_denounced_storage.ml already_denounced_storage.mli dal_already_denounced_storage.ml dal_already_denounced_storage.mli delegate_missed_attestations_storage.ml @@ -924,7 +924,7 @@ cycle_repr.ml cycle_repr.mli tez_repr.ml tez_repr.mli deposits_repr.ml deposits_repr.mli - attestation_power_repr.ml attestation_power_repr.mli + attesting_power_repr.ml attesting_power_repr.mli unstaked_frozen_deposits_repr.ml unstaked_frozen_deposits_repr.mli staking_pseudotoken_repr.ml staking_pseudotoken_repr.mli period_repr.ml period_repr.mli @@ -1036,7 +1036,6 @@ global_constants_costs.ml global_constants_costs.mli ticket_hash_builder.ml ticket_hash_builder.mli constants_storage.ml constants_storage.mli - consensus_parameters_storage.ml consensus_parameters_storage.mli level_storage.ml level_storage.mli cycle_storage.ml cycle_storage.mli nonce_storage.ml nonce_storage.mli @@ -1071,6 +1070,7 @@ delegate_storage.ml delegate_storage.mli delegate_sampler.ml delegate_sampler.mli delegate_rewards.ml delegate_rewards.mli + consensus_parameters_storage.ml consensus_parameters_storage.mli already_denounced_storage.ml already_denounced_storage.mli dal_already_denounced_storage.ml dal_already_denounced_storage.mli delegate_missed_attestations_storage.ml diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 30edf104fe49706d7a8a96a264916b7143518eeb..910c9d5dad79a0c5bf4c4b5d43fec05b56f540ab 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -93,7 +93,7 @@ let consensus_pk_encoding = type consensus_power = { consensus_key : consensus_pk; - attestation_power : Attestation_power_repr.t; + attesting_power : Attesting_power_repr.t; dal_power : int; } @@ -103,7 +103,7 @@ module Raw_consensus = struct this delegate. *) type t = { - current_attestation_power : Attestation_power_repr.t; + current_attesting_power : Attesting_power_repr.t; (** Number of attestation slots and their related staking power recorded for the current block. *) allowed_attestations : consensus_power Slot_repr.Map.t option; @@ -131,7 +131,7 @@ module Raw_consensus = struct preattestations_seen : Slot_repr.Set.t; (** Record the preattestations already seen. Only initial slots are indexed. *) - locked_round_evidence : (Round_repr.t * Attestation_power_repr.t) option; + locked_round_evidence : (Round_repr.t * Attesting_power_repr.t) option; (** Record the preattestation power and staking power for a locked round. *) preattestations_quorum_round : Round_repr.t option; (** in block construction mode, record the round of preattestations @@ -151,7 +151,7 @@ module Raw_consensus = struct let empty : t = { - current_attestation_power = Attestation_power_repr.zero; + current_attesting_power = Attesting_power_repr.zero; allowed_attestations = Some Slot_repr.Map.empty; allowed_preattestations = Some Slot_repr.Map.empty; allowed_consensus = None; @@ -185,13 +185,13 @@ module Raw_consensus = struct (Slot_repr.Set.mem initial_slot t.attestations_seen) Double_inclusion_of_consensus_operation in - let current_attestation_power = - Attestation_power_repr.add power t.current_attestation_power + let current_attesting_power = + Attesting_power_repr.add power t.current_attesting_power in return { t with - current_attestation_power; + current_attesting_power; attestations_seen = Slot_repr.Set.add initial_slot t.attestations_seen; } @@ -210,7 +210,7 @@ module Raw_consensus = struct It doesn't matter in that case since quorum certificates are not used in mempool. For other cases [Apply.check_round] verifies it. *) - let power = Attestation_power_repr.add power evidences in + let power = Attesting_power_repr.add power evidences in Some (round, power) in return @@ -2162,7 +2162,7 @@ module type CONSENSUS = sig type round - type attestation_power + type attesting_power type consensus_power @@ -2176,7 +2176,7 @@ module type CONSENSUS = sig type error += Slot_map_not_found of {loc : string} - val current_attestation_power : t -> attestation_power + val current_attesting_power : t -> attesting_power val initialize_consensus_operation : t -> @@ -2186,10 +2186,10 @@ module type CONSENSUS = sig t val record_attestation : - t -> initial_slot:slot -> power:attestation_power -> t tzresult + t -> initial_slot:slot -> power:attesting_power -> t tzresult val record_preattestation : - t -> initial_slot:slot -> power:attestation_power -> round -> t tzresult + t -> initial_slot:slot -> power:attesting_power -> round -> t tzresult val forbid_delegate : t -> Signature.Public_key_hash.t -> t @@ -2201,7 +2201,7 @@ module type CONSENSUS = sig val set_preattestations_quorum_round : t -> round -> t - val locked_round_evidence : t -> (round * attestation_power) option + val locked_round_evidence : t -> (round * attesting_power) option val set_attestation_branch : t -> Block_hash.t * Block_payload_hash.t -> t @@ -2216,7 +2216,7 @@ module Consensus : and type 'a level_map := 'a Level_repr.Map.t and type slot_set := Slot_repr.Set.t and type round := Round_repr.t - and type attestation_power := Attestation_power_repr.t + and type attesting_power := Attesting_power_repr.t and type consensus_power := consensus_power = struct let[@inline] update_consensus_with ctxt f = {ctxt with back = {ctxt.back with consensus = f ctxt.back.consensus}} @@ -2240,8 +2240,8 @@ module Consensus : let[@inline] set_forbidden_delegates ctxt delegates = update_consensus_with ctxt (Raw_consensus.set_forbidden_delegates delegates) - let[@inline] current_attestation_power ctxt = - ctxt.back.consensus.current_attestation_power + let[@inline] current_attesting_power ctxt = + ctxt.back.consensus.current_attesting_power let[@inline] get_preattestations_quorum_round ctxt = ctxt.back.consensus.preattestations_quorum_round diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index 209383de852a2e0b9ca4c564018b8e1af80fb282..d4947cfe444da3b76d10df8361c5005d3a1b516c 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -357,7 +357,7 @@ end type consensus_power = { consensus_key : consensus_pk; - attestation_power : Attestation_power_repr.t; + attesting_power : Attesting_power_repr.t; dal_power : int; } @@ -374,7 +374,7 @@ module type CONSENSUS = sig type round - type attestation_power + type attesting_power (** Info on the power of a given member of the consensus committee. Contains a consensus_pk, its attesting power and its DAL power. *) @@ -403,7 +403,7 @@ module type CONSENSUS = sig (** [attestation power ctx] returns the attestation power and stake of the current block. *) - val current_attestation_power : t -> attestation_power + val current_attesting_power : t -> attesting_power (** Initializes the map of allowed attestations and preattestations, this function must be called only once and before applying any consensus @@ -422,7 +422,7 @@ module type CONSENSUS = sig [Int_map.find_opt initial_slot allowed_attestation ctx = Some (pkh, power)]. *) val record_attestation : - t -> initial_slot:slot -> power:attestation_power -> t tzresult + t -> initial_slot:slot -> power:attesting_power -> t tzresult (** [record_preattestation ctx ~initial_slot ~power round payload_hash power] records a preattestation for a proposal at @@ -432,7 +432,7 @@ module type CONSENSUS = sig [Int_map.find_opt initial_slot allowed_preattestation ctx = Some (pkh, power)]. *) val record_preattestation : - t -> initial_slot:slot -> power:attestation_power -> round -> t tzresult + t -> initial_slot:slot -> power:attesting_power -> round -> t tzresult (** [forbid_delegate ctx delegate] adds [delegate] to the set of forbidden delegates, which prevents this delegate from baking or @@ -460,7 +460,7 @@ module type CONSENSUS = sig (** [locked_round_evidence ctx] returns the round of the recorded preattestations as well as their power. *) - val locked_round_evidence : t -> (round * attestation_power) option + val locked_round_evidence : t -> (round * attesting_power) option val set_attestation_branch : t -> Block_hash.t * Block_payload_hash.t -> t @@ -475,7 +475,7 @@ module Consensus : and type 'a level_map := 'a Level_repr.Map.t and type slot_set := Slot_repr.Set.t and type round := Round_repr.t - and type attestation_power := Attestation_power_repr.t + and type attesting_power := Attesting_power_repr.t and type consensus_power := consensus_power module Sc_rollup_in_memory_inbox : sig diff --git a/src/proto_alpha/lib_protocol/slash_percentage.ml b/src/proto_alpha/lib_protocol/slash_percentage.ml index 42e410234b0db5c8b46af74313821374919c9564..ac95598476250aab7021337b7d66e53876479b7c 100644 --- a/src/proto_alpha/lib_protocol/slash_percentage.ml +++ b/src/proto_alpha/lib_protocol/slash_percentage.ml @@ -8,31 +8,35 @@ let for_double_baking ctxt = Constants_storage.percentage_of_frozen_deposits_slashed_per_double_baking ctxt -let for_double_attestation ctxt rights level denounced = +let for_double_attestation ctxt ~committee_size rights denounced = let total_rights_denounced = List.fold_left (fun total delegate -> Option.value (Signature.Public_key_hash.Map.find delegate rights) - ~default:0 - |> ( + ) total) - 0 + ~default:0L + |> Int64.add total) + 0L denounced in - (* TODO ABAAB. Note that the [rights] amount would also depend on the flag status. *) - let committee_size = - Consensus_parameters_storage.consensus_committee ctxt level - in let Ratio_repr.{numerator; denominator} = Constants_storage.max_slashing_threshold ctxt in - (* Set the threshold to ⌈committee_size * threshold_ratio⌉ *) - let threshold_max = 1 + (((committee_size * numerator) - 1) / denominator) in + (* Temporary Z cast to avoid overflow *) + let committee_size = Z.of_int64 committee_size in + let numerator, denominator = Z.(of_int numerator, of_int denominator) in + (* Set the threshold to ⌈committee_size * threshold_ratio⌉ + = 1 + (((committee_size * numerator) - 1) / denominator) *) + let threshold_max = + Z.( + succ (div (sub (mul committee_size numerator) one) denominator) + |> to_int64) + in let max_slashing = Constants_storage.max_slashing_per_block ctxt in - if Compare.Int.(total_rights_denounced >= threshold_max) then max_slashing + if Compare.Int64.(total_rights_denounced >= threshold_max) then max_slashing else - let num_z = Z.(pow (of_int total_rights_denounced) 2) in - let den_z = Z.(pow (of_int threshold_max) 2) in + let num_z = Z.(pow (of_int64 total_rights_denounced) 2) in + let den_z = Z.(pow (of_int64 threshold_max) 2) in Percentage.mul_q_bounded ~round:`Up max_slashing Q.(num_z /// den_z) let get ctxt ~(kind : Misbehaviour_repr.kind) ~(level : Level_repr.t) @@ -41,8 +45,16 @@ let get ctxt ~(kind : Misbehaviour_repr.kind) ~(level : Level_repr.t) match kind with | Double_baking -> return (ctxt, for_double_baking ctxt) | Double_attesting | Double_preattesting -> - let* ctxt, rights = Delegate_sampler.attesting_rights_count ctxt level in - return (ctxt, for_double_attestation ctxt rights level denounced) + let all_bakers_attest_enabled = + Consensus_parameters_storage.check_all_bakers_attest_at_level ctxt level + in + let* ctxt, rights = + Delegate_sampler.attesting_power ~all_bakers_attest_enabled ctxt level + in + let* ctxt, committee_size = + Consensus_parameters_storage.consensus_committee ctxt level + in + return (ctxt, for_double_attestation ctxt ~committee_size rights denounced) module Internal_for_tests = struct let for_double_attestation = for_double_attestation diff --git a/src/proto_alpha/lib_protocol/slash_percentage.mli b/src/proto_alpha/lib_protocol/slash_percentage.mli index 6eb06bc18a0921be87d8afd30139e4d8807cb8fc..e450c13b762156591032c6b064f22f72f47c3ea0 100644 --- a/src/proto_alpha/lib_protocol/slash_percentage.mli +++ b/src/proto_alpha/lib_protocol/slash_percentage.mli @@ -24,8 +24,8 @@ val get : module Internal_for_tests : sig val for_double_attestation : Raw_context.t -> - int Signature.Public_key_hash.Map.t -> - Level_repr.t -> + committee_size:int64 -> + int64 Signature.Public_key_hash.Map.t -> Signature.Public_key_hash.t list -> Percentage.t end diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 09b7d940790dc822c397d04c4e6d33fa5db5e34c..1f9754fea3858d0efe1c8b7ebfec20ff8f1f9740 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -140,6 +140,7 @@ type attester = Plugin.RPC.Validators.delegate = { consensus_key : Signature.public_key_hash; companion_key : Signature.Bls.Public_key_hash.t option; slots : Slot.t list; + attesting_power : int64; } let get_attesters ctxt = @@ -288,29 +289,41 @@ let get_baking_reward_fixed_portion ctxt = let get_bonus_reward ctxt ~attesting_power = let open Lwt_result_wrap_syntax in - let* {Constants.parametric = {consensus_threshold_size; _} as csts; _} = + let* { + Constants.parametric = + {consensus_threshold_size; consensus_committee_size; _} as csts; + _; + } = get_constants ctxt in (* TODO ABAAB: will depend on level/feature flag *) - let*?@ baking_reward_bonus_per_slot = + let*?@ baking_reward_bonus_per_block = Delegate.Rewards.For_RPC.reward_from_constants csts - ~reward_kind:Baking_reward_bonus_per_slot + ~reward_kind:Baking_reward_bonus_per_block in - let multiplier = max 0 (attesting_power - consensus_threshold_size) in - return Tez_helpers.(baking_reward_bonus_per_slot *! Int64.of_int multiplier) + let multiplier = + max 0 (attesting_power - consensus_threshold_size) |> Int64.of_int + in + let den = + consensus_committee_size - consensus_threshold_size |> Int64.of_int + in + return Tez_helpers.(baking_reward_bonus_per_block /! den *! multiplier) let get_attesting_reward ctxt ~expected_attesting_power = + (* TODO ABAAB: will depend on level/feature flag *) let open Lwt_result_wrap_syntax in let* {Constants.parametric = csts; _} = get_constants ctxt in - let*?@ attesting_reward_per_slot = + let*?@ attesting_reward_per_block = Delegate.Rewards.For_RPC.reward_from_constants csts - ~reward_kind:Attesting_reward_per_slot + ~reward_kind:Attesting_reward_per_block in let*?@ t = - Tez.(attesting_reward_per_slot *? Int64.of_int expected_attesting_power) + Tez.( + attesting_reward_per_block /? Int64.of_int csts.consensus_committee_size) in + let*?@ t = Tez.(t *? Int64.of_int expected_attesting_power) in return t let get_liquidity_baking_subsidy ctxt = diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index c5f56a26465a1f935b9b4564d195514bdcac11ea..cfa96066b9cfcf460ad83f0cb02be98213bb5c67 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -44,6 +44,7 @@ type attester = Plugin.RPC.Validators.delegate = { consensus_key : Signature.public_key_hash; companion_key : Signature.Bls.Public_key_hash.t option; slots : Slot.t list; + attesting_power : int64; } (** Retrieves the attesting rights at the level of the given context diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_attestation.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_attestation.ml index 31cb50100bc8cd59f2cb5dac8526996c87e2bc7b..eafda43b791488c9651538200f92b0afcae0bc53 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_attestation.ml @@ -367,10 +367,10 @@ let attest_with_all_ : t -> t tzresult Lwt.t = RPC.Attestation_rights.delegate; consensus_key = _; first_slot = _; - attestation_power; + attesting_power; } -> Tezt.Check.( - (attestation_power > 0) + (attesting_power > 0) int ~__LOC__ ~error_msg:"Attestation power should be greater than 0, got %L") ; @@ -387,7 +387,7 @@ let attest_with_all_ : t -> t tzresult Lwt.t = RPC.Attestation_rights.delegate = manager_pkh; consensus_key = consensus_pkh; first_slot = slot; - attestation_power = _; + attesting_power = _; } as delegate_rights) -> (* Update delegate activity in any case. *) let delegate_name, _ = @@ -591,10 +591,10 @@ let preattest_with_all_ ?payload_round : t_incr -> t_incr tzresult Lwt.t = Plugin.RPC.Attestation_rights.delegate; consensus_key = _; first_slot = _; - attestation_power; + attesting_power; } -> Tezt.Check.( - (attestation_power > 0) + (attesting_power > 0) int ~__LOC__ ~error_msg:"Attestation power should be greater than 0, got %L") ; @@ -609,7 +609,7 @@ let preattest_with_all_ ?payload_round : t_incr -> t_incr tzresult Lwt.t = Plugin.RPC.Attestation_rights.delegate = manager_pkh; consensus_key = consensus_pkh; first_slot = slot; - attestation_power = _; + attesting_power = _; } as delegate_rights) -> (* Update delegate activity in any case. *) let delegate_name, _ = diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml index 0fdaf14461f0e3790072d0fd8252bd64d04b3745..cfd0afd96874d0c2e63b7193accff664c046ab8c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_aggregate.ml @@ -109,7 +109,7 @@ let check_aggregate_result (type kind) (kind : kind aggregate) ~attesters attesters in let total_consensus_power = - Alpha_context.Attestation_power.get_slots total_consensus_power + Alpha_context.Attesting_power.get_slots total_consensus_power in if voting_power = total_consensus_power then return_unit else @@ -128,7 +128,7 @@ let check_aggregate_result (type kind) (kind : kind aggregate) ~attesters in let resulting_committee = List.map - (fun (a, b) -> (a, Alpha_context.Attestation_power.get_slots b)) + (fun (a, b) -> (a, Alpha_context.Attesting_power.get_slots b)) resulting_committee in if diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml index 5d60622bfa3c9026c22fd401269faa4105f5258d..4af8cdbba735949138a66caec44a7e152270ed2a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml @@ -203,10 +203,15 @@ let test_participation_rpc () = expected_cycle_activity * numerator / denominator in let allowed_missed_slots = expected_cycle_activity - minimal_cycle_activity in - let*?@ attesting_reward_per_slot = + let*?@ attesting_reward_per_block = Alpha_context.Delegate.Rewards.For_RPC.reward_from_constants csts.parametric - ~reward_kind:Attesting_reward_per_slot + ~reward_kind:Attesting_reward_per_block + in + let attesting_reward_per_slot = + Tez_helpers.( + attesting_reward_per_block + /! Int64.of_int csts.parametric.consensus_committee_size) in let expected_attesting_rewards = Tez_helpers.( diff --git a/src/proto_alpha/lib_protocol/test/integration/test_constants.ml b/src/proto_alpha/lib_protocol/test/integration/test_constants.ml index d959160a10b84bc6d058dd7b9f32acf419571218..a669ad844855c45cdf50cca0ef5c1c886c952215 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_constants.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_constants.ml @@ -428,22 +428,15 @@ let () = Protocol.Alpha_context.Delegate.Rewards.For_RPC.reward_from_constants constants in - let*?@ baking_reward_bonus_per_slot = - get_reward ~reward_kind:Baking_reward_bonus_per_slot - in - let*? baking_reward_bonus = - baking_reward_bonus_per_slot - *? Int64.of_int (constants.consensus_committee_size / 3) + let*?@ baking_reward_bonus = + get_reward ~reward_kind:Baking_reward_bonus_per_block in let*?@ baking_reward_fixed_portion = get_reward ~reward_kind:Baking_reward_fixed_portion in let*? baking_rewards = baking_reward_fixed_portion +? baking_reward_bonus in - let*?@ attesting_reward_per_slot = - get_reward ~reward_kind:Attesting_reward_per_slot - in - let*? validators_rewards = - attesting_reward_per_slot *? Int64.of_int constants.consensus_committee_size + let*?@ validators_rewards = + get_reward ~reward_kind:Attesting_reward_per_block in let*?@ dal_attesting_reward_per_shard = get_reward ~reward_kind:Dal_attesting_reward_per_shard diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml index 18ebb91e9bb270316e2b97127dcf7a24c1bd48d5..2af5e4f05e54ba55c8bb41fc2ad83b7486149f37 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml @@ -145,8 +145,7 @@ let check_has_no_slots ~loc baker_name = | [] -> return input | [{level = _; delegates_rights; estimated_time = _}] -> ( match delegates_rights with - | [{delegate; consensus_key = _; first_slot = _; attestation_power}] - -> + | [{delegate; consensus_key = _; first_slot = _; attesting_power}] -> Test.fail ~__LOC__ "%s: delegate '%s'(%a) expected to have no attestation power, \ @@ -155,7 +154,7 @@ let check_has_no_slots ~loc baker_name = baker_name Signature.Public_key_hash.pp delegate - attestation_power + attesting_power | _ -> (* Cannot happen: RPC called for only one delegate *) assert false ) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml index 3e94e340d11d6f2db3587cd39594de4f7003d2c9..7ece05694ddb5d683451c5a241b2a370ab9c289e 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml @@ -55,7 +55,10 @@ let make_fake_culprits_with_rights_from_int_list il = let map = List.fold_left (fun map (pkh, rights) -> - Environment.Signature.Public_key_hash.Map.add pkh rights map) + Environment.Signature.Public_key_hash.Map.add + pkh + (Int64.of_int rights) + map) Environment.Signature.Public_key_hash.Map.empty pkh_rights_list in @@ -69,8 +72,10 @@ let get_pct ~max_slashing_threshold ~max_slashing_per_block int_list = return @@ Protocol.Slash_percentage.Internal_for_tests.for_double_attestation ctxt + ~committee_size: + (Int64.of_int + Default_parameters.constants_mainnet.consensus_committee_size) map - Protocol.Level_repr.level_zero_use_with_care pkh_list (** Tests that the slashing amount for several delegates is the same as long diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 2856cbbab89ca1e2d2500b5404f5b225528ed8e8..67a0d67e5ef172739ee020002ac5018928255b4c 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -431,8 +431,8 @@ type block_state = { remaining_block_gas : Gas.Arith.fp; recorded_operations_rev : Operation_hash.t list; last_op_validation_pass : int option; - locked_round_evidence : (Round.t * Attestation_power.t) option; - attestation_power : Attestation_power.t; + locked_round_evidence : (Round.t * Attesting_power.t) option; + attesting_power : Attesting_power.t; } type validation_state = { @@ -480,7 +480,7 @@ let init_block_state vi = recorded_operations_rev = []; last_op_validation_pass = None; locked_round_evidence = None; - attestation_power = Attestation_power.zero; + attesting_power = Attesting_power.zero; } let get_initial_ctxt {info; _} = info.ctxt @@ -638,7 +638,7 @@ module Consensus = struct let (Single (Preattestation consensus_content)) = operation.protocol_data.contents in - let* {consensus_key; attestation_power; dal_power = _} = + let* {consensus_key; attesting_power; dal_power = _} = match vi.mode with | Application block_info | Partial_validation block_info -> let* () = @@ -699,7 +699,7 @@ module Consensus = struct ] else [] in - return (attestation_power, check_signature) + return (attesting_power, check_signature) let check_preattestation_conflict vs oph (op : Kind.preattestation operation) = @@ -751,7 +751,7 @@ module Consensus = struct construction mode. *) Some ( consensus_content.round, - Attestation_power.add total_attesting_power attesting_power )) + Attesting_power.add total_attesting_power attesting_power )) in {block_state with locked_round_evidence} @@ -869,7 +869,7 @@ module Consensus = struct let (Single (Attestation {consensus_content; dal_content})) = operation.protocol_data.contents in - let* {consensus_key; attestation_power; dal_power = _} = + let* {consensus_key; attesting_power; dal_power = _} = match vi.mode with | Application _ | Partial_validation _ | Construction _ -> ( let* () = @@ -912,7 +912,7 @@ module Consensus = struct [(fun () -> check_attestation_signature vi consensus_key operation)] else [] in - return (attestation_power, check_signature) + return (attesting_power, check_signature) let check_attestation_conflict vs oph (operation : Kind.attestation operation) = @@ -951,19 +951,19 @@ module Consensus = struct in {vs with consensus_state = {vs.consensus_state with attestations_seen}} - let may_update_attestation_power vi block_state attesting_power = + let may_update_attesting_power vi block_state attesting_power = match vi.mode with | Mempool -> (* The block_state is not relevant. *) block_state | Application _ | Partial_validation _ | Construction _ -> { block_state with - attestation_power = - Attestation_power.add block_state.attestation_power attesting_power; + attesting_power = + Attesting_power.add block_state.attesting_power attesting_power; } (* Hypothesis: this function will only be called in mempool mode *) let remove_attestation vs (operation : Kind.attestation operation) = - (* We do not remove the attestation power because it is not + (* We do not remove the attesting power because it is not relevant for the mempool mode. *) let (Single (Attestation @@ -1044,7 +1044,7 @@ module Consensus = struct check_attestation_conflict operation_state oph operation |> wrap_attestation_conflict in - let block_state = may_update_attestation_power info block_state power in + let block_state = may_update_attesting_power info block_state power in let operation_state = add_attestation operation_state oph operation in return {info; operation_state; block_state} @@ -1313,12 +1313,12 @@ module Consensus = struct return_unit | Mempool -> return_unit in - (* Retrieve public keys and compute total attestation power *) - let* public_keys, total_attestation_power = + (* Retrieve public keys and compute total attesting power *) + let* public_keys, total_attesting_power = List.fold_left_es - (fun (public_keys, total_attestation_power) slot -> + (fun (public_keys, total_attesting_power) slot -> (* Lookup the slot owner *) - let*? {consensus_key; attestation_power; dal_power = _} = + let*? {consensus_key; attesting_power; dal_power = _} = get_delegate_details consensus_info.preattestation_slot_map Preattestation @@ -1331,11 +1331,10 @@ module Consensus = struct | Bls pk -> return ( pk :: public_keys, - Attestation_power.add - attestation_power - total_attestation_power ) + Attesting_power.add attesting_power total_attesting_power + ) | _ -> tzfail Validate_errors.Consensus.Non_bls_key_in_aggregate) - ([], Attestation_power.zero) + ([], Attesting_power.zero) committee in (* Fail on empty committee *) @@ -1364,7 +1363,7 @@ module Consensus = struct block_state info.mode {level; round; block_payload_hash; slot = Slot.zero} - total_attestation_power + total_attesting_power in return {validation_state with block_state} @@ -1426,7 +1425,7 @@ module Consensus = struct List.fold_left_es (fun (pks, weighted_pks, total_power) (slot, dal) -> (* Lookup the slot owner *) - let*? {consensus_key; attestation_power; dal_power = _} = + let*? {consensus_key; attesting_power; dal_power = _} = get_delegate_details consensus_info.attestation_slot_map Attestation @@ -1437,7 +1436,7 @@ module Consensus = struct in let* () = check_dal_content info level slot consensus_key dal in let total_power = - Attestation_power.add attestation_power total_power + Attesting_power.add attesting_power total_power in match consensus_key.consensus_pk with | Bls consensus_pk -> ( @@ -1464,7 +1463,7 @@ module Consensus = struct (Missing_companion_key_for_bls_dal (Consensus_key.pkh consensus_key))) | _ -> tzfail Validate_errors.Consensus.Non_bls_key_in_aggregate) - ([], [], Attestation_power.zero) + ([], [], Attesting_power.zero) committee in (* Fail on empty committee *) @@ -1490,7 +1489,7 @@ module Consensus = struct in (* Increase block attesting power *) let block_state = - may_update_attestation_power info block_state total_attesting_power + may_update_attesting_power info block_state total_attesting_power in return {validation_state with block_state} end @@ -4009,7 +4008,7 @@ let validate_operation ?(check_signature = true) open Validate_errors.Block -let check_attestation_power vi bs = +let check_attesting_power vi bs = let open Lwt_result_syntax in let* are_attestations_required = (* The migration block (whose level is [first_level_of_protocol]) @@ -4024,13 +4023,14 @@ let check_attestation_power vi bs = return Compare.Int32.(level_position_in_protocol > 1l) in if are_attestations_required then - let required = - Attestation_power.consensus_threshold vi.ctxt vi.current_level - |> Int64.of_int + (* We can safely drop the context: it is only updated for the cache of + the stake info for a given level, which should already be cached + at this time anyways. *) + let* _ctxt, required = + Attesting_power.consensus_threshold vi.ctxt vi.current_level in - (* TODO ABAAB : required should depend on the flag *) let provided = - Attestation_power.get vi.ctxt vi.current_level bs.attestation_power + Attesting_power.get vi.ctxt vi.current_level bs.attesting_power in fail_unless Compare.Int64.(provided >= required) @@ -4063,11 +4063,11 @@ let check_fitness_locked_round bs fitness_locked_round = contains preattestations when they are mandatory. This is checked by {!check_fitness_locked_round} instead. *) let check_preattestation_round_and_power vi vs round = - let open Result_syntax in + let open Lwt_result_syntax in match vs.locked_round_evidence with - | None -> ok_unit + | None -> return_unit | Some (preattestation_round, total_attesting_power) -> - let* () = + let*? () = (* Actually, this check should never fail, because we have already called {!Consensus.check_round_before_block} for all preattestations in a block. Nevertheless, it does not @@ -4077,18 +4077,22 @@ let check_preattestation_round_and_power vi vs round = (Locked_round_after_block_round {locked_round = preattestation_round; round}) in - (* TODO ABAAB : threshold should depend on abaab flag *) - let consensus_threshold = - Attestation_power.consensus_threshold vi.ctxt vi.current_level - |> Int64.of_int + (* We can safely drop the context: it is only updated for the cache of + the stake info for a given level, which should already be cached + at this time anyways. *) + let* _ctxt, consensus_threshold = + Attesting_power.consensus_threshold vi.ctxt vi.current_level in let total_attesting_power = - Attestation_power.get vi.ctxt vi.current_level total_attesting_power + Attesting_power.get vi.ctxt vi.current_level total_attesting_power in - error_when - Compare.Int64.(total_attesting_power < consensus_threshold) - (Insufficient_locked_round_evidence - {total_attesting_power; consensus_threshold}) + let*? () = + error_when + Compare.Int64.(total_attesting_power < consensus_threshold) + (Insufficient_locked_round_evidence + {total_attesting_power; consensus_threshold}) + in + return_unit let check_payload_hash block_state ~predecessor_hash (block_header_contents : Block_header.contents) = @@ -4107,21 +4111,21 @@ let finalize_block {info; block_state; _} = let open Lwt_result_syntax in match info.mode with | Application {round; locked_round; predecessor_hash; header_contents} -> - let* () = check_attestation_power info block_state in + let* () = check_attesting_power info block_state in let*? () = check_fitness_locked_round block_state locked_round in - let*? () = check_preattestation_round_and_power info block_state round in + let* () = check_preattestation_round_and_power info block_state round in let*? () = check_payload_hash block_state ~predecessor_hash header_contents in return_unit | Partial_validation {round; locked_round; _} -> - let* () = check_attestation_power info block_state in + let* () = check_attesting_power info block_state in let*? () = check_fitness_locked_round block_state locked_round in - let*? () = check_preattestation_round_and_power info block_state round in + let* () = check_preattestation_round_and_power info block_state round in return_unit | Construction {round; predecessor_hash; header_contents} -> - let* () = check_attestation_power info block_state in - let*? () = check_preattestation_round_and_power info block_state round in + let* () = check_attesting_power info block_state in + let* () = check_preattestation_round_and_power info block_state round in let*? () = match block_state.locked_round_evidence with | Some _ -> diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out index 9fb0b2d56b7375f1dc5a1f63d4a1860f9e21d917..d86658b1a35c4044b47b3223f37627bf82bd8845 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- adaptive_issuance.out @@ -39,13 +39,15 @@ ./octez-client rpc get /chains/main/blocks/head/context/issuance/expected_issuance [ { "cycle": 0, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, + "baking_reward_bonus_per_block": "300010", + "attesting_reward_per_block": "600020", + "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", + "dal_attesting_reward_per_shard": "520" }, { "cycle": 1, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" } ] + "baking_reward_bonus_per_block": "300010", + "attesting_reward_per_block": "600020", + "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", + "dal_attesting_reward_per_shard": "520" } ] ./octez-client rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/stakers' [ { "staker": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index 9904784dacc87ea0564f0fcaec7517ccf83b5add..7c00020c20f84f4563c1c34b705fd793a98a9684 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -118,26 +118,26 @@ [ { "level": 1, "delegates": [ { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 11, "attestation_power": 50, + "first_slot": 11, "attesting_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 4, "attestation_power": 47, + "first_slot": 4, "attesting_power": 47, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 2, "attestation_power": 46, + "first_slot": 2, "attesting_power": 46, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 1, "attestation_power": 55, + "first_slot": 1, "attesting_power": 55, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 0, "attestation_power": 58, + "first_slot": 0, "attesting_power": 58, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] ./octez-client rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' [ { "level": 1, "delegates": [ { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 11, "attestation_power": 50, + "first_slot": 11, "attesting_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] ./octez-client rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out index 3415cd6047a48aace9cf134ee6d8cb6d2af46ed3..fce27bb9fc3405eef24a114351313be30329d0b0 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- adaptive_issuance.out @@ -39,13 +39,15 @@ ./octez-client --mode light rpc get /chains/main/blocks/head/context/issuance/expected_issuance [ { "cycle": 0, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, + "baking_reward_bonus_per_block": "300010", + "attesting_reward_per_block": "600020", + "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", + "dal_attesting_reward_per_shard": "520" }, { "cycle": 1, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" } ] + "baking_reward_bonus_per_block": "300010", + "attesting_reward_per_block": "600020", + "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", + "dal_attesting_reward_per_shard": "520" } ] ./octez-client --mode light rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/stakers' [ { "staker": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index a2347b6aa68c0788682803bed1565eb12d27b114..f6b3c03403f98004bd577acf656b91273ddac145 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -118,26 +118,26 @@ [ { "level": 1, "delegates": [ { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 11, "attestation_power": 50, + "first_slot": 11, "attesting_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 4, "attestation_power": 47, + "first_slot": 4, "attesting_power": 47, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 2, "attestation_power": 46, + "first_slot": 2, "attesting_power": 46, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 1, "attestation_power": 55, + "first_slot": 1, "attesting_power": 55, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 0, "attestation_power": 58, + "first_slot": 0, "attesting_power": 58, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] ./octez-client --mode light rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' [ { "level": 1, "delegates": [ { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 11, "attestation_power": 50, + "first_slot": 11, "attesting_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] ./octez-client --mode light rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out index 72d5fdab114a267521734b8d6e5a7046d2259425..7d83521beae4bb0fd99f1fee10c886a3651ebc1b 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- adaptive_issuance.out @@ -39,13 +39,15 @@ ./octez-client --mode proxy rpc get /chains/main/blocks/head/context/issuance/expected_issuance [ { "cycle": 0, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" }, + "baking_reward_bonus_per_block": "300010", + "attesting_reward_per_block": "600020", + "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", + "dal_attesting_reward_per_shard": "520" }, { "cycle": 1, "baking_reward_fixed_portion": "300010", - "baking_reward_bonus_per_slot": "1171", - "attesting_reward_per_slot": "2343", "seed_nonce_revelation_tip": "234", - "vdf_revelation_tip": "234", "dal_attesting_reward_per_shard": "520" } ] + "baking_reward_bonus_per_block": "300010", + "attesting_reward_per_block": "600020", + "seed_nonce_revelation_tip": "234", "vdf_revelation_tip": "234", + "dal_attesting_reward_per_shard": "520" } ] ./octez-client --mode proxy rpc get '/chains/main/blocks/head/context/delegates/[PUBLIC_KEY_HASH]/stakers' [ { "staker": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index f476c821cab05e9335a6e13f01290fba33260574..de80fb77e8b95078e10035063255e8bf8ba2afee 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -118,26 +118,26 @@ [ { "level": 1, "delegates": [ { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 11, "attestation_power": 50, + "first_slot": 11, "attesting_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 4, "attestation_power": 47, + "first_slot": 4, "attesting_power": 47, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 2, "attestation_power": 46, + "first_slot": 2, "attesting_power": 46, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 1, "attestation_power": 55, + "first_slot": 1, "attesting_power": 55, "consensus_key": "[PUBLIC_KEY_HASH]" }, { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 0, "attestation_power": 58, + "first_slot": 0, "attesting_power": 58, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] ./octez-client --mode proxy rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' [ { "level": 1, "delegates": [ { "delegate": "[PUBLIC_KEY_HASH]", - "first_slot": 11, "attestation_power": 50, + "first_slot": 11, "attesting_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] ./octez-client --mode proxy rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle diff --git a/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out b/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out index f9981c3c1459ef49dca48694fa9f99124a2cbd2a..48388a8225c45bbfad2bf8b8a3726877b7c71076 100644 --- a/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out +++ b/tezt/tests/expected/dal.ml/Alpha- Testing DAL node (attesters receive DAL rewards).out @@ -75,7 +75,7 @@ } GET http://[HOST]:[PORT]/chains/main/blocks/head/context/issuance/expected_issuance 200 OK -[{"cycle":0,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"}] +[{"cycle":0,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_block":"300010","attesting_reward_per_block":"600020","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_block":"300010","attesting_reward_per_block":"600020","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"}] GET http://[HOST]:[PORT]/chains/main/blocks/head~1/context/delegates/[PUBLIC_KEY_HASH]/dal_participation 200 OK @@ -134,7 +134,7 @@ GET http://[HOST]:[PORT]/chains/main/blocks/head~1/context/delegates/[PUBLIC_KEY } GET http://[HOST]:[PORT]/chains/main/blocks/head/context/issuance/expected_issuance 200 OK -[{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_slot":"1171","attesting_reward_per_slot":"2343","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":2,"baking_reward_fixed_portion":"7847","baking_reward_bonus_per_slot":"30","attesting_reward_per_slot":"61","seed_nonce_revelation_tip":"6","vdf_revelation_tip":"6","dal_attesting_reward_per_shard":"13"}] +[{"cycle":1,"baking_reward_fixed_portion":"300010","baking_reward_bonus_per_block":"300010","attesting_reward_per_block":"600020","seed_nonce_revelation_tip":"234","vdf_revelation_tip":"234","dal_attesting_reward_per_shard":"520"},{"cycle":2,"baking_reward_fixed_portion":"7847","baking_reward_bonus_per_block":"7847","attesting_reward_per_block":"15695","seed_nonce_revelation_tip":"6","vdf_revelation_tip":"6","dal_attesting_reward_per_shard":"13"}] GET http://[HOST]:[PORT]/chains/main/blocks/head~1/context/delegates/[PUBLIC_KEY_HASH]/dal_participation 200 OK diff --git a/teztale/bin_teztale_archiver/alpha_machine.real.ml b/teztale/bin_teztale_archiver/alpha_machine.real.ml index f76e4e42bee82d531dd2098b3c7cc04f6dd43d43..5082f3f00f5b7c61689f164ddc016a85ad3a5f59 100644 --- a/teztale/bin_teztale_archiver/alpha_machine.real.ml +++ b/teztale/bin_teztale_archiver/alpha_machine.real.ml @@ -42,13 +42,13 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct return (List.map (fun Plugin.RPC.Attestation_rights. - {delegate; first_slot; attestation_power; _} -> + {delegate; first_slot; attesting_power; _} -> Consensus_ops. { address = Tezos_crypto.Signature.Of_V2.public_key_hash delegate; first_slot = slot_to_int first_slot; - power = attestation_power; + power = attesting_power; }) answer.Plugin.RPC.Attestation_rights.delegates_rights) | [] -> return_nil @@ -240,7 +240,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct kind; }; delegate = Tezos_crypto.Signature.Of_V2.public_key_hash ck.delegate; - power = Protocol.Alpha_context.Attestation_power.get_slots power; + power = Protocol.Alpha_context.Attesting_power.get_slots power; } :: acc) acc @@ -277,7 +277,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct delegate = Tezos_crypto.Signature.Of_V2.public_key_hash delegate; power = - Protocol.Alpha_context.Attestation_power.get_slots + Protocol.Alpha_context.Attesting_power.get_slots consensus_power; } :: acc @@ -301,7 +301,7 @@ module Services : Protocol_machinery.PROTOCOL_SERVICES = struct delegate = Tezos_crypto.Signature.Of_V2.public_key_hash delegate; power = - Protocol.Alpha_context.Attestation_power.get_slots + Protocol.Alpha_context.Attesting_power.get_slots consensus_power; } :: acc