diff --git a/src/proto_alpha/lib_delegate/block_forge.ml b/src/proto_alpha/lib_delegate/block_forge.ml index 102fd897253bb90d6020639e8064e6bd325d0c0b..ed71e94dcb9a0b64692fd406b214efa3eff0fa55 100644 --- a/src/proto_alpha/lib_delegate/block_forge.ml +++ b/src/proto_alpha/lib_delegate/block_forge.ml @@ -445,6 +445,7 @@ let aggregate_attestations eligible_attestations = with | Some signature -> let contents = + let committee = Operation.tmp_of_old_committee committee in Single (Attestations_aggregate {consensus_content; committee}) in let protocol_data = {contents; signature = Some (Bls signature)} in @@ -550,7 +551,9 @@ let aggregate_attestations_on_reproposal consensus_operations = (* The proposal already contains an aggregate. We must incorporate additional attestations *) (* Build the set of aggregated slots for a logarithmic presence lookup *) - let aggregated_slots = SlotSet.of_list committee in + let aggregated_slots = + SlotSet.of_list (Operation.committee_slots committee) + in (* Gather slots and signatures incorporating fresh attestations. *) let committee, signatures = List.fold_left @@ -561,7 +564,7 @@ let aggregate_attestations_on_reproposal consensus_operations = when not (SlotSet.mem consensus_content.slot aggregated_slots) -> (consensus_content.slot :: slots, signature :: signatures) | _ -> acc) - (committee, [signature]) + (Operation.tmp_to_old_committee committee, [signature]) eligible_attestations in (* We disable the subgroup check for better performance, as operations @@ -571,6 +574,7 @@ let aggregate_attestations_on_reproposal consensus_operations = with | Some signature -> let contents = + let committee = Operation.tmp_of_old_committee committee in Single (Attestations_aggregate {consensus_content; committee}) in let protocol_data = {contents; signature = Some (Bls signature)} in diff --git a/src/proto_alpha/lib_plugin/mempool.ml b/src/proto_alpha/lib_plugin/mempool.ml index a67d84292e08be12bb535ebffec08d52dd6c4bfb..84cf49212ef7dce80436b8d49dd0dab1a48d76a9 100644 --- a/src/proto_alpha/lib_plugin/mempool.ml +++ b/src/proto_alpha/lib_plugin/mempool.ml @@ -799,54 +799,50 @@ let get_context context ~(head : Tezos_base.Block_header.shell_header) = in return ctxt +let sources_from_level_and_slot ctxt level slot = + let open Lwt_syntax in + let* slot_owner = Stake_distribution.slot_owner ctxt level slot in + match slot_owner with + | Ok + ( _ctxt, + { + delegate; + consensus_pkh; + consensus_pk = _; + companion_pkh = _; + companion_pk = _; + } ) -> + return [delegate; consensus_pkh] + | Error _ -> return_nil + +let sources_from_aggregate ctxt + (consensus_content : consensus_aggregate_content) slots = + let open Lwt_syntax in + let level = Level.from_raw ctxt consensus_content.level in + Lwt_list.fold_left_s + (fun acc slot -> + let* sources = sources_from_level_and_slot ctxt level slot in + return (sources @ acc)) + [] + slots + let sources_from_operation ctxt ({shell = _; protocol_data = Operation_data {contents; _}} : Main.operation) = let open Lwt_syntax in - let map_pkh_env = List.map Tezos_crypto.Signature.Of_V2.public_key_hash in match contents with | Single (Failing_noop _) -> return_nil | Single (Preattestation consensus_content) - | Single (Attestation {consensus_content; dal_content = _}) -> ( + | Single (Attestation {consensus_content; dal_content = _}) -> let level = Level.from_raw ctxt consensus_content.level in - let* slot_owner = - Stake_distribution.slot_owner ctxt level consensus_content.slot - in - match slot_owner with - | Ok - ( _ctxt, - { - delegate; - consensus_pkh; - consensus_pk = _; - companion_pkh = _; - companion_pk = _; - } ) -> - return @@ map_pkh_env [delegate; consensus_pkh] - | Error _ -> return_nil) - | Single (Preattestations_aggregate {consensus_content; committee}) + sources_from_level_and_slot ctxt level consensus_content.slot + | Single (Preattestations_aggregate {consensus_content; committee}) -> + sources_from_aggregate ctxt consensus_content committee | Single (Attestations_aggregate {consensus_content; committee}) -> - let level = Level.from_raw ctxt consensus_content.level in - let* sources = - Lwt_list.fold_left_s - (fun acc slot -> - let* slot_owner = Stake_distribution.slot_owner ctxt level slot in - match slot_owner with - | Ok - ( _ctxt, - { - delegate; - consensus_pkh; - consensus_pk = _; - companion_pkh = _; - companion_pk = _; - } ) -> - return (delegate :: consensus_pkh :: acc) - | Error _ -> return acc) - [] - committee - in - return @@ map_pkh_env sources + sources_from_aggregate + ctxt + consensus_content + (Operation.committee_slots committee) | Single (Seed_nonce_revelation _) | Single (Double_preattestation_evidence _) | Single (Double_attestation_evidence _) @@ -856,10 +852,10 @@ let sources_from_operation ctxt | Single (Vdf_revelation _) -> return_nil | Single (Proposals {source; _}) | Single (Ballot {source; _}) -> - return @@ map_pkh_env [source] - | Single (Drain_delegate {delegate; _}) -> return @@ map_pkh_env [delegate] - | Single (Manager_operation {source; _}) -> return @@ map_pkh_env [source] - | Cons (Manager_operation {source; _}, _) -> return @@ map_pkh_env [source] + return [source] + | Single (Drain_delegate {delegate; _}) -> return [delegate] + | Single (Manager_operation {source; _}) -> return [source] + | Cons (Manager_operation {source; _}, _) -> return [source] module Internal_for_tests = struct let default_config_with_clock_drift clock_drift = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 4a43e54b22afd463467dd2e30ad6b25c4a1015f4..20dbcaf28d107fe4938d2b9a42f4b9f4bdb5a48a 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4722,7 +4722,7 @@ and _ contents = -> Kind.preattestations_aggregate contents | Attestations_aggregate : { consensus_content : consensus_aggregate_content; - committee : Slot.t list; + committee : (Slot.t * dal_content option) list; } -> Kind.attestations_aggregate contents | Seed_nonce_revelation : { @@ -5154,6 +5154,13 @@ module Operation : sig val of_list : packed_contents list -> packed_contents_list tzresult val to_list : packed_contents_list -> packed_contents list + + (** See {!Operation_repr.committee_slots}. *) + val committee_slots : (Slot.t * dal_content option) list -> Slot.t list + + val tmp_to_old_committee : (Slot.t * dal_content option) list -> Slot.t list + + val tmp_of_old_committee : Slot.t list -> (Slot.t * dal_content option) list end (** This module re-exports definitions from {!Stake_storage}, diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index f6f304c13a1b001b9cdf9c685a7e5a9d4d429a90..cee57d76ae1c77a0e3ad429ee0033bfe10787429 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -2558,7 +2558,10 @@ let apply_contents_list (type kind) ctxt chain_id (mode : mode) (Constants.aggregate_attestation ctxt) Validate_errors.Consensus.(Aggregate_disabled) in - record_attestations_aggregate ctxt mode committee + record_attestations_aggregate + ctxt + mode + (Operation.tmp_to_old_committee committee) | Single (Seed_nonce_revelation {level; nonce}) -> let level = Level.from_raw ctxt level in let* ctxt = Nonce.reveal ctxt level nonce in diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index bff7fd97cd65f2267a6afdf4e9eef2b3dba16ce2..ca9d76c3e8777bd7f92cc562522ca597b1859e8e 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -296,7 +296,7 @@ and _ contents = -> Kind.preattestations_aggregate contents | Attestations_aggregate : { consensus_content : consensus_aggregate_content; - committee : Slot_repr.t list; + committee : (Slot_repr.t * dal_content option) list; } -> Kind.attestations_aggregate contents | Seed_nonce_revelation : { @@ -551,6 +551,13 @@ let of_list l = | Ok contents -> Ok contents | Error s -> Result_syntax.tzfail @@ Contents_list_error s +let committee_slots committee = List.map fst committee + +let tmp_to_old_committee committee = List.map fst committee + +let tmp_of_old_committee committee = + List.map (fun slot -> (slot, None)) committee + let tx_rollup_operation_tag_offset = 150 let tx_rollup_operation_origination_tag = tx_rollup_operation_tag_offset + 0 @@ -1257,9 +1264,13 @@ module Encoding = struct | Contents (Attestations_aggregate _ as op) -> Some op | _ -> None); proj = (fun (Attestations_aggregate {consensus_content; committee}) -> + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7935 + Take dal_content into account. *) + let committee = tmp_to_old_committee committee in (consensus_content, committee)); inj = (fun (consensus_content, committee) -> + let committee = tmp_of_old_committee committee in Attestations_aggregate {consensus_content; committee}); } @@ -2518,7 +2529,9 @@ let weight_of : packed_operation -> operation_weight = W (Consensus, Weight_attestations_aggregate aggregate_infos) | Single (Attestations_aggregate {consensus_content; committee}) -> let aggregate_infos = - aggregate_infos_from_content consensus_content committee + aggregate_infos_from_content + consensus_content + (committee_slots committee) in W (Consensus, Weight_attestations_aggregate aggregate_infos) | Single (Proposals {period; source; _}) -> diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 5382636189598c55f5c83a269d6bed6a96d42c16..5dc6ccb29d1128898efb01008eb1b75474282587 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -289,10 +289,10 @@ and _ contents = committee : Slot_repr.t list; } -> Kind.preattestations_aggregate contents - (* Aggregate of attestations without dal_content. *) + (* Aggregate of attestations. *) | Attestations_aggregate : { consensus_content : consensus_aggregate_content; - committee : Slot_repr.t list; + committee : (Slot_repr.t * dal_content option) list; } -> Kind.attestations_aggregate contents (* Seed_nonce_revelation: Nonces are created by bakers and are @@ -584,6 +584,23 @@ val pack : 'kind operation -> packed_operation val manager_kind : 'kind manager_operation -> 'kind Kind.manager +(** Extracts the slots from a + {!constructor:contents.Attestations_aggregate} committee. *) +val committee_slots : + (Slot_repr.t * dal_content option) list -> Slot_repr.t list + +(* TODO: https://gitlab.com/tezos/tezos/-/issues/7935 + The following two functions are used so that despite the type + having been updated with DAL contents, attestations aggregate still + has the old logic without DAL. They should be removed once the new + logic has been implemented everywhere. *) + +val tmp_to_old_committee : + (Slot_repr.t * dal_content option) list -> Slot_repr.t list + +val tmp_of_old_committee : + Slot_repr.t list -> (Slot_repr.t * dal_content option) list + val encoding : packed_operation Data_encoding.t val contents_encoding : packed_contents Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index ae000bf57d4855766a1cb01e7d99ce72b12c49d3..b2e6b80fa167baad06c376a32abf3fdfe171e0e8 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -165,6 +165,7 @@ let aggregate attestations = Bls12_381_signature.MinPk.aggregate_signature_opt signatures in let contents = + let committee = Operation.tmp_of_old_committee committee in Single (Attestations_aggregate {consensus_content; committee}) in let protocol_data = 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 5f705c710c70d55c11fcaf1fc571a07c8f1365f4..dca10743eded83929f1db7da96395bdc5ec4cf91 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 @@ -306,8 +306,12 @@ let test_aggregate_attestation_non_bls_delegate () = let consensus_content : Alpha_context.consensus_aggregate_content = {level; round; block_payload_hash} in + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7935 + Add tests with dal_content = Some _. *) let contents : _ Alpha_context.contents_list = - Single (Attestations_aggregate {consensus_content; committee = [slot]}) + Single + (Attestations_aggregate + {consensus_content; committee = [(slot, None)]}) in let aggregate : operation = {shell; protocol_data = Operation_data {contents; signature}} diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 0c2f8be7e326d9069d90e83f064345df52a03003..5c983d4dc3d3aeea00b873ef0ab06b7f5eddee40 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -1061,7 +1061,7 @@ module Consensus = struct in return operation_state) operation_state - committee + (Operation.committee_slots committee) in return {info; operation_state; block_state} @@ -1117,7 +1117,7 @@ module Consensus = struct | Bls pk -> return (pk :: public_keys, power + total_voting_power) | _ -> tzfail Validate_errors.Consensus.Non_bls_key_in_aggregate) ([], 0) - committee + (Operation.tmp_to_old_committee committee) in (* Fail on empty committee *) let*? () =