diff --git a/tezt/lib_tezos/dal_node.ml b/tezt/lib_tezos/dal_node.ml index 402078e90506470dfc81885003e030df280ff819..844abe53dcadcb874419ec619d4625ec1ff273cd 100644 --- a/tezt/lib_tezos/dal_node.ml +++ b/tezt/lib_tezos/dal_node.ml @@ -633,7 +633,8 @@ module Mockup_for_baker = struct ] in let body = value_to_string mocked_json in - Lwt.return_some (`Response body))); + if List.mem attester attesters then Lwt.return_some (`Response body) + else Lwt.return_none)); (let path_pattern = "^/profiles/?$" in Mockup.route ~path_pattern ~callback:(fun ~path:_ -> let open Ezjsonm in diff --git a/tezt/tests/baker_test.ml b/tezt/tests/baker_test.ml index 698640f0cc5e2c261c915ab5f04b132fe73b0d0f..b0dce177c212efe82b0e1d31975967150b7b8d12 100644 --- a/tezt/tests/baker_test.ml +++ b/tezt/tests/baker_test.ml @@ -709,6 +709,136 @@ let simple_attestations_aggregation = in unit +let simple_attestations_aggregation_with_dal = + Protocol.register_test + ~__FILE__ + ~title:"Simple attestations aggregation with DAL content" + ~tags:[team; "baker"; "attestation"; "aggregation"; "dal"] + ~supports:Protocol.(From_protocol 023) + ~uses:(fun _protocol -> [Constant.octez_agnostic_baker]) + @@ fun protocol -> + log_step 1 "Initialize a node and a client with protocol" ; + let consensus_rights_delay = 1 in + let parameter_overrides = + [ + (["allow_tz4_delegate_enable"], `Bool true); + (["aggregate_attestation"], `Bool true); + (* Diminish some constants to activate consensus keys faster *) + (["blocks_per_cycle"], `Int 2); + (["nonce_revelation_threshold"], `Int 1); + (["consensus_rights_delay"], `Int consensus_rights_delay); + (["cache_sampler_state_cycles"], `Int (consensus_rights_delay + 3)); + (["cache_stake_distribution_cycles"], `Int (consensus_rights_delay + 3)); + ] + in + let* node, client, dal_parameters = + Dal.setup_node + ~node_arguments:[Synchronisation_threshold 0; Connections 0] + ~parameter_overrides + ~protocol + ~activation_timestamp:Now + () + in + log_step 2 "Wait for level 1" ; + let* _ = Node.wait_for_level node 1 in + log_step 3 "Generate fresh BLS consensus keys for bootstrap1 to bootstrap3" ; + let* b1 = Client.update_fresh_consensus_key ~algo:"bls" bootstrap1 client in + let* b2 = Client.update_fresh_consensus_key ~algo:"bls" bootstrap2 client in + let* b3 = Client.update_fresh_consensus_key ~algo:"bls" bootstrap3 client in + let delegates = + Account.Bootstrap.keys |> Array.to_list + |> List.append [b1; b2; b3] + |> List.map (fun (account : Account.key) -> account.Account.alias) + in + (* Expected committee that should be found in attestations aggregate *) + let expected_attestations_committee = [bootstrap1; bootstrap2; bootstrap3] in + let* () = Client.bake_for_and_wait ~keys:delegates client in + (* Expected attestations that should be found non-aggregated *) + let expected_attestations = [bootstrap4; bootstrap5] in + + log_step 4 "Generate companion bls keys" ; + let* ck1 = Client.gen_keys ~sig_alg:"bls" client in + let* ck2 = Client.gen_keys ~sig_alg:"bls" client in + let* ck3 = Client.gen_keys ~sig_alg:"bls" client in + log_step 5 "Use them as companion keys for bootstrap1 to bootstrap3" ; + let* () = Client.update_companion_key ~src:bootstrap1.alias ~pk:ck1 client in + let* () = Client.update_companion_key ~src:bootstrap2.alias ~pk:ck2 client in + let* () = Client.update_companion_key ~src:bootstrap3.alias ~pk:ck3 client in + let delegates = List.append delegates [ck1; ck2; ck3] in + + log_step 6 "Bake for until level 8" ; + (* Baking until level 8 ensures that the BLS consensus and companion + keys are activated *) + (* TODO: check for the error: Error: Expected a BLS companion key + for the consensus key ... *) + let* () = Client.bake_for_and_wait ~count:6 ~keys:delegates client in + + (* DAL attestation *) + log_step 7 "Start the mocked DAL node" ; + let dal_node_mockup = + let attestation_lag = dal_parameters.attestation_lag in + let number_of_slots = dal_parameters.number_of_slots in + let attesters = [bootstrap1.public_key_hash; bootstrap3.public_key_hash] in + let attestable_slots ~attester:_ ~attested_level:_ = + List.init number_of_slots (fun _0 -> true) + in + Dal_node.Mockup_for_baker.make + ~name:"mock-dal-node" + ~attestation_lag + ~attesters + ~attestable_slots + in + let port = Port.fresh () in + let () = Dal_node.Mockup_for_baker.run dal_node_mockup ~port in + let dal_node_rpc_endpoint = + Endpoint.make ~host:"localhost" ~scheme:"http" ~port () + in + let dal_node_endpoint = Endpoint.as_string dal_node_rpc_endpoint in + + log_step 8 "Bake with a dal node endpoint" ; + let* () = + Client.bake_for_and_wait ~dal_node_endpoint ~keys:delegates client + in + log_step 9 "Check consensus operations" ; + let* () = + check_consensus_operations + ~expected_attestations_committee + ~expected_attestations + client + in + (* Testing the "bake for" command with minimal timestamp *) + log_step 10 "Bake for with minimal timestamp until level 11" ; + let* () = + Client.bake_for_and_wait + ~dal_node_endpoint + ~minimal_timestamp:true + ~count:2 + ~keys:delegates + client + in + log_step 11 "Check consensus operations" ; + let* () = + check_consensus_operations + ~expected_attestations_committee + ~expected_attestations + client + in + + (* Testing the baker automaton *) + log_step 12 "Start a baker and bake until level 13" ; + let _baker = + Agnostic_baker.init ~delegates ~dal_node_rpc_endpoint node client + in + let* _ = Node.wait_for_level node 13 in + log_step 13 "Check consensus operations" ; + let* () = + check_consensus_operations + ~expected_attestations_committee + ~expected_attestations + client + in + unit + let prequorum_check_levels = Protocol.register_test ~__FILE__ @@ -1048,5 +1178,6 @@ let register ~protocols = baker_check_consensus_branch protocols ; force_apply_from_round protocols ; simple_attestations_aggregation protocols ; + simple_attestations_aggregation_with_dal protocols ; prequorum_check_levels protocols ; attestations_aggregation_on_reproposal protocols