From 240a6bee5d7c94c3258ea9dbcefd0a3b53ea81d1 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 28 Feb 2024 12:48:41 +0100 Subject: [PATCH 1/4] Paris/Tests: use small value for number_of_shards in slow AI tests Computing the DAL committee takes a bit of time, around 1ms for [number_of_shards] = 2048, and this adds up when baking for a long time. As this issue is orthogonal to this test, we simply pick a lower value. --- .../test_adaptive_issuance_launch.ml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml index bba07acba2e9..50f2cd2155a4 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml @@ -123,6 +123,24 @@ let test_launch threshold expected_vote_duration () = (* Initialize the state with a single delegate. *) let constants = let default_constants = Default_parameters.constants_test in + let default_constants = + { + default_constants with + dal = + { + default_constants.dal with + cryptobox_parameters = + { + default_constants.dal.cryptobox_parameters with + (* Computing the DAL committee takes a bit of time, around 1ms + for [number_of_shards] = 2048, and this adds up when baking + for a long time. As this issue is orthogonal to this test, we + simply pick a lower value. *) + number_of_shards = 32; + }; + }; + } + in let adaptive_issuance = { default_constants.adaptive_issuance with @@ -402,6 +420,21 @@ let test_does_not_launch_without_feature_flag threshold vote_duration () = (* Initialize the state with a single delegate. *) let constants = let default_constants = Default_parameters.constants_test in + let default_constants = + { + default_constants with + dal = + { + default_constants.dal with + cryptobox_parameters = + { + default_constants.dal.cryptobox_parameters with + (* same reasoning as for [test_launch] *) + number_of_shards = 32; + }; + }; + } + in let adaptive_issuance = { default_constants.adaptive_issuance with -- GitLab From ef36b7bc021235cde74a0bdfcc8172020939e85c Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 28 Feb 2024 13:06:05 +0100 Subject: [PATCH 2/4] Paris/DAL: remove the unused mapping from the DAL committee --- .../lib_protocol/alpha_context.mli | 1 - src/proto_alpha/lib_protocol/raw_context.ml | 17 +------------- src/proto_alpha/lib_protocol/raw_context.mli | 22 +++---------------- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 867a6b1da8d5..e11b723cb030 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2789,7 +2789,6 @@ module Dal : sig type committee = { pkh_to_shards : (shard_index * int) Signature.Public_key_hash.Map.t; - shard_to_pkh : Signature.Public_key_hash.t Shard_map.t; } val compute_committee : diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 2b3c234b16ac..35f610c314b9 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -225,14 +225,9 @@ end type dal_committee = { pkh_to_shards : (Dal_attestation_repr.shard_index * int) Signature.Public_key_hash.Map.t; - shard_to_pkh : Signature.Public_key_hash.t Dal_attestation_repr.Shard_map.t; } -let empty_dal_committee = - { - pkh_to_shards = Signature.Public_key_hash.Map.empty; - shard_to_pkh = Dal_attestation_repr.Shard_map.empty; - } +let empty_dal_committee = {pkh_to_shards = Signature.Public_key_hash.Map.empty} type back = { context : Context.t; @@ -1881,7 +1876,6 @@ module Dal = struct type committee = dal_committee = { pkh_to_shards : (Dal_attestation_repr.shard_index * int) Signature.Public_key_hash.Map.t; - shard_to_pkh : Signature.Public_key_hash.t Dal_attestation_repr.Shard_map.t; } (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3110 @@ -1924,12 +1918,6 @@ module Dal = struct | Some (initial_shard_index, old_power) -> Some (initial_shard_index, old_power + power)) committee.pkh_to_shards; - shard_to_pkh = - List.fold_left - (fun shard_to_pkh slot -> - Dal_attestation_repr.Shard_map.add slot pkh shard_to_pkh) - committee.shard_to_pkh - Misc.(slot_index --> (slot_index + (power - 1))); } in let rec compute_power index committee = @@ -1940,9 +1928,6 @@ module Dal = struct let* _ctxt, pkh = pkh_from_tenderbake_slot slot in (* The [Slot_repr] module is related to the Tenderbake committee. *) let slot_index = Slot_repr.to_int slot in - (* An optimisation could be to return only [pkh_to_shards] map - because the second one is not used. This can be done later - on, if it is a good optimisation. *) let committee = update_committee committee pkh ~slot_index ~power:1 in compute_power (index - 1) committee in diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index 76a39cc23438..d6494485dd96 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -465,32 +465,16 @@ module Dal : sig t -> attester:Signature.Public_key_hash.t -> int list option (** The DAL committee is a subset of the Tenderbake committee. A - shard from [0;number_of_shards] is associated to a public key - hash. For efficiency reasons, the committee is both: - a mapping from public key hashes to shards and - a mapping from shards to public key hashes. + shard from [0; number_of_shards - 1] is associated to a public key + hash. The committee is a mapping from public key hashes to shards and The DAL committee ensures the shards associated to the same public key hash are contiguous. The list of shards is represented as two natural numbers [(initial, power)] which encodes the list of shards: - [initial; initial + 1; ... ; initial + power - 1]. - - This data-type ensures the following invariants: - - - \forall pkh shard, find pkh_to_shards pkh = Some (start,n) -> - \forall i, i \in [start; start + n - 1] -> find shard_to_pkh i - = Some pkh - - - forall pkh shard, find shard_to_pkh shard = Some pkh -> - \exists (start,n), find pkh_to_shards pkh = Some (start,n) /\ - start <= shard <= start + n - 1 - - - Given an attester, all its shard assignments are contiguous - *) + [initial; initial + 1; ... ; initial + power - 1]. *) type committee = { pkh_to_shards : (Dal_attestation_repr.shard_index * int) Signature.Public_key_hash.Map.t; - shard_to_pkh : Signature.Public_key_hash.t Dal_attestation_repr.Shard_map.t; } (** [compute_committee ctxt pkh_from_tenderbake_slot] computes the -- GitLab From 59a638b6d56027ebcddbfbbb0e657fe87edbe3ba Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 28 Feb 2024 13:06:55 +0100 Subject: [PATCH 3/4] Paris/DAL: move comment The comment was placed in a function that did not do what the comment said. In particular [computed_committee] is also called by Dal_services, and there we don't cache the committee. --- src/proto_alpha/lib_protocol/dal_apply.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_apply.ml b/src/proto_alpha/lib_protocol/dal_apply.ml index de04ea637bc2..ee1a82bfb954 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.ml +++ b/src/proto_alpha/lib_protocol/dal_apply.ml @@ -153,8 +153,6 @@ let compute_committee ctxt level = let+ ctxt, consensus_key = Stake_distribution.slot_owner ctxt level slot in (ctxt, pkh_of_consensus_key consensus_key) in - (* This committee is cached because it is the one we will use - for the validation of the DAL attestations. *) Alpha_context.Dal.Attestation.compute_committee ctxt pkh_from_tenderbake_slot let initialisation ctxt ~level = @@ -164,4 +162,6 @@ let initialisation ctxt ~level = ~default:(fun ctxt -> return ctxt) (fun ctxt -> let+ committee = compute_committee ctxt level in + (* This committee is cached because it is the one we will use + for the validation of the DAL attestations. *) Alpha_context.Dal.Attestation.init_committee ctxt committee) -- GitLab From a651d9e05b8c5ca50af107fb4316231ad7bf4094 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 28 Feb 2024 13:12:39 +0100 Subject: [PATCH 4/4] Paris/DAL: replace bitset weight computation by library call --- src/proto_alpha/lib_protocol/dal_attestation_repr.ml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml index 2fc9e154e15b..43688eb26a6c 100644 --- a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml +++ b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml @@ -134,12 +134,7 @@ module Accountability = struct match List.nth shard_bitset_per_slot (Dal_slot_index_repr.to_int index) with | None -> false | Some bitset -> - let acc = ref 0 in - List.iter - (fun x -> - match Bitset.mem bitset x with - | Error _ | Ok false -> () - | Ok true -> incr acc) - Misc.(0 --> (number_of_shards - 1)) ; - Compare.Int.(!acc >= threshold * number_of_shards / 100) + let number_of_attested_shards = Bitset.hamming_weight bitset in + Compare.Int.( + number_of_attested_shards >= threshold * number_of_shards / 100) end -- GitLab