diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 867a6b1da8d500382072744819210e10ed1f1321..e11b723cb0305bac58a6e7ed08af5c5500bf19f0 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/dal_apply.ml b/src/proto_alpha/lib_protocol/dal_apply.ml index de04ea637bc2c475a68e1bd3643b7cce97c70d6d..ee1a82bfb95497cd7cb94c6717eca696126284cb 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) diff --git a/src/proto_alpha/lib_protocol/dal_attestation_repr.ml b/src/proto_alpha/lib_protocol/dal_attestation_repr.ml index 2fc9e154e15b5e03ad293c0b135372d2dead4e08..43688eb26a6ca9d8c1a1e403389a155552feb633 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 diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 2b3c234b16ac8c735f52c03ae095f6f9e9c84ef6..35f610c314b9a6d2c25d0c133363e0f9386eca90 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 76a39cc234385210af5d31ad82eea384a05591ac..d6494485dd963a99a2e7a28b3ee8acc7201c73c8 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 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 3c51de4d159b4ba74f0de72a2fef9098649860ca..6ec13dedade075b7a8670b65d04b9a8323554b07 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 @@ -124,6 +124,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 @@ -403,6 +421,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