From 91a15f6c7da2119252720a611e68644e21e8b332 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 7 May 2025 11:49:29 +0200 Subject: [PATCH 1/3] Proto: validators RPC returns companion key only when consensus key is bls key --- src/proto_alpha/lib_plugin/RPC.ml | 10 +++++++++- tezt/tests/companion_key.ml | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 4014e166d12a..b2d0b93dd183 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -4001,7 +4001,9 @@ module Validators = struct RPC_service.get_service ~description: "Retrieves the level, the attestation slots and the public key hash \ - of each delegate allowed to attest a block.\n\ + of each delegate allowed to attest a block. Also returns each \ + delegate's current consensus key, and current companion key when \ + needed for crafting and validating attestations at this level.\n\ By default, it provides this information for the next level.\n\ Parameter `level` can be used to specify the (valid) level(s) in \ the past or future at which the attestation rights have to be \ @@ -4016,9 +4018,15 @@ module Validators = struct let add_attestation_slots_at_level (ctxt, acc) level = let open Lwt_result_syntax 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 {level = level.level; delegate; consensus_key; companion_key; slots} :: acc) rights diff --git a/tezt/tests/companion_key.ml b/tezt/tests/companion_key.ml index 43808c870d38..7e0a41765b46 100644 --- a/tezt/tests/companion_key.ml +++ b/tezt/tests/companion_key.ml @@ -124,6 +124,7 @@ let init_node_and_client ~protocol = (["cache_sampler_state_cycles"], `Int (consensus_rights_delay + 3)); (["cache_stake_distribution_cycles"], `Int (consensus_rights_delay + 3)); (["allow_tz4_delegate_enable"], `Bool true); + (["aggregate_attestation"], `Bool true); ] in let* parameter_file = @@ -242,7 +243,7 @@ let test_update_companion_key_without_consensus_key = ~__LOC__ ~level:(current_level.level + 1) delegate - ~expected:(Some companion_key_bls.public_key_hash) + ~expected:None client in unit -- GitLab From 103622bcd33cafc15d73c75126d1a8ae63a9f178 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 14 May 2025 12:00:08 +0200 Subject: [PATCH 2/3] Tezt/Tests: update companion key for tz4 delegate --- tezt/tests/companion_key.ml | 72 ++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/tezt/tests/companion_key.ml b/tezt/tests/companion_key.ml index 7e0a41765b46..028d0348c471 100644 --- a/tezt/tests/companion_key.ml +++ b/tezt/tests/companion_key.ml @@ -248,6 +248,76 @@ let test_update_companion_key_without_consensus_key = in unit +let test_update_companion_key_for_tz4_delegate = + Protocol.register_test + ~__FILE__ + ~title:"update companion key for tz4 delegate" + ~tags:[team; "companion_key"] + ~supports:(Protocol.From_protocol 023) + @@ fun protocol -> + let* _node, client = init_node_and_client ~protocol in + (* gen keys delegate -s bls *) + (* transfer 1000000 from bootstrap2 to delegate *) + let* delegate = + Client.gen_and_show_keys ~alias:"delegate" ~sig_alg:"bls" client + in + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:(Tez.of_int 1_000_000) + ~giver:Constant.bootstrap2.alias + ~receiver:delegate.public_key_hash + client + in + let* () = Client.bake_for_and_wait client in + (* set delegate for delegate to delegate *) + let*! () = + Client.set_delegate ~src:delegate.alias ~delegate:delegate.alias client + in + let* () = Client.bake_for_and_wait client in + (* stake 800000 for delegate *) + let* () = Client.stake ~staker:delegate.alias (Tez.of_int 800_000) client in + let* () = Client.bake_for_and_wait client in + (* gen keys companion_key -s bls *) + (* set companion key for delegate to companion_key *) + let* companion_key_bls = + Client.gen_and_show_keys ~alias:"companion_key" ~sig_alg:"bls" client + in + Log.info "Updating companion key" ; + let* () = + Client.update_companion_key + ~src:delegate.alias + ~pk:companion_key_bls.alias + client + in + let* () = Client.bake_for_and_wait client in + + Log.info "Waiting for companion key activation" ; + let* () = bake_n_cycles (consensus_rights_delay + 1) client in + + Log.info "Checking key is activated" ; + let* () = + check_companion_key + ~__LOC__ + delegate + ~expected_active:companion_key_bls + client + in + let* () = + check_validators_companion_key ~__LOC__ delegate ~expected:None client + in + let* current_level = get_current_level client in + let* () = + check_validators_companion_key + ~__LOC__ + ~level:(current_level.level + 1) + delegate + ~expected:(Some companion_key_bls.public_key_hash) + client + in + unit + let register ~protocols = test_update_companion_key protocols ; - test_update_companion_key_without_consensus_key protocols + test_update_companion_key_without_consensus_key protocols ; + test_update_companion_key_for_tz4_delegate protocols -- GitLab From 273e3140103a33dcc5890016b6ae1bb8f7d736b5 Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Wed, 14 May 2025 12:09:52 +0200 Subject: [PATCH 3/3] Tezt/Test: reset regressions --- tezt/tests/companion_key.ml | 9 ++++--- ...te companion key for non tz4 delegate.out} | 0 ... update companion key for tz4 delegate.out | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) rename tezt/tests/expected/companion_key.ml/{Alpha- update companion key without updating consensus key.out => Alpha- update companion key for non tz4 delegate.out} (100%) create mode 100644 tezt/tests/expected/companion_key.ml/Alpha- update companion key for tz4 delegate.out diff --git a/tezt/tests/companion_key.ml b/tezt/tests/companion_key.ml index 028d0348c471..0b9b46f28658 100644 --- a/tezt/tests/companion_key.ml +++ b/tezt/tests/companion_key.ml @@ -201,10 +201,10 @@ let test_update_companion_key = in unit -let test_update_companion_key_without_consensus_key = +let test_update_companion_key_for_non_tz4_delegate = Protocol.register_regression_test ~__FILE__ - ~title:"update companion key without updating consensus key" + ~title:"update companion key for non tz4 delegate" ~tags:[team; "companion_key"] ~supports:(Protocol.From_protocol 023) @@ fun protocol -> @@ -249,7 +249,7 @@ let test_update_companion_key_without_consensus_key = unit let test_update_companion_key_for_tz4_delegate = - Protocol.register_test + Protocol.register_regression_test ~__FILE__ ~title:"update companion key for tz4 delegate" ~tags:[team; "companion_key"] @@ -286,6 +286,7 @@ let test_update_companion_key_for_tz4_delegate = Log.info "Updating companion key" ; let* () = Client.update_companion_key + ~hooks ~src:delegate.alias ~pk:companion_key_bls.alias client @@ -319,5 +320,5 @@ let test_update_companion_key_for_tz4_delegate = let register ~protocols = test_update_companion_key protocols ; - test_update_companion_key_without_consensus_key protocols ; + test_update_companion_key_for_non_tz4_delegate protocols ; test_update_companion_key_for_tz4_delegate protocols diff --git a/tezt/tests/expected/companion_key.ml/Alpha- update companion key without updating consensus key.out b/tezt/tests/expected/companion_key.ml/Alpha- update companion key for non tz4 delegate.out similarity index 100% rename from tezt/tests/expected/companion_key.ml/Alpha- update companion key without updating consensus key.out rename to tezt/tests/expected/companion_key.ml/Alpha- update companion key for non tz4 delegate.out diff --git a/tezt/tests/expected/companion_key.ml/Alpha- update companion key for tz4 delegate.out b/tezt/tests/expected/companion_key.ml/Alpha- update companion key for tz4 delegate.out new file mode 100644 index 000000000000..a066d8363849 --- /dev/null +++ b/tezt/tests/expected/companion_key.ml/Alpha- update companion key for tz4 delegate.out @@ -0,0 +1,27 @@ + +./octez-client --wait none set companion key for delegate to companion_key +Node is bootstrapped. +Estimated gas: 3249.100 units (will add 100 for safety) +Estimated storage: no bytes added +Operation successfully injected in the node. +Operation hash is '[OPERATION_HASH]' +NOT waiting for the operation to be included. +Use command + octez-client wait for [OPERATION_HASH] to be included --confirmations 1 --branch [BLOCK_HASH] +and/or an external block explorer to make sure that it has been included. +This sequence of operations was run: + Manager signed operations: + From: [PUBLIC_KEY_HASH] + Fee to the baker: ꜩ0.000743 + Expected counter: 5 + Gas limit: 3350 + Storage limit: 0 bytes + Balance updates: + [PUBLIC_KEY_HASH] ... -ꜩ0.000743 + payload fees(the block proposer) ....... +ꜩ0.000743 + Update_companion_key: + Public key hash: [PUBLIC_KEY_HASH] + Proof of possession: [BLS_SIGNATURE] + This companion key update was successfully applied + Consumed gas: 3249.030 + -- GitLab