diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 4014e166d12a0e2a54e325dd60560c2195b03573..b2d0b93dd18396ab5adee7f22210910357983932 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 43808c870d38456a04328ad1088be2de153976d3..0b9b46f2865892f2e74f0bfd5b25a538ebaa80af 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 = @@ -200,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 -> @@ -225,6 +226,76 @@ let test_update_companion_key_without_consensus_key = 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:None + client + in + unit + +let test_update_companion_key_for_tz4_delegate = + Protocol.register_regression_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 + ~hooks + ~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 @@ -249,4 +320,5 @@ let test_update_companion_key_without_consensus_key = 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 0000000000000000000000000000000000000000..a066d8363849737d2c5ef16db6b44f08d2722945 --- /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 +