From 36508138c992c3a7857b2571f6bccad20144f548 Mon Sep 17 00:00:00 2001 From: Mathias Bourgoin Date: Wed, 14 Feb 2024 17:17:57 +0100 Subject: [PATCH 1/8] proto/NS_feature flag: enable ns --- src/proto_alpha/lib_parameters/default_parameters.ml | 2 +- src/proto_alpha/lib_protocol/raw_context.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 1012559309b4..6c10e7ec75c5 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -308,7 +308,7 @@ let constants_mainnet : Constants.Parametric.t = activation_vote_enable = true; autostaking_enable = true; force_activation = false; - ns_enable = false; + ns_enable = true; }; (* TODO: https://gitlab.com/tezos/tezos/-/issues/6668 Enable once at least the following is done: diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index e280159687af..2b3c234b16ac 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1177,7 +1177,7 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = activation_vote_enable = true; autostaking_enable = c.adaptive_issuance.autostaking_enable; force_activation = false; - ns_enable = false; + ns_enable = true; } in let liquidity_baking_subsidy = Tez_repr.(mul_exn one 5) in -- GitLab From 5b92cf530ba822bb28f38c526f556ad4879e718e Mon Sep 17 00:00:00 2001 From: Mathias Bourgoin Date: Wed, 14 Feb 2024 17:18:21 +0100 Subject: [PATCH 2/8] tezt/RPC: reset regression trace --- ...Alpha- (mode client) RPC regression tests- misc_protocol.out | 2 +- .../Alpha- (mode light) RPC regression tests- misc_protocol.out | 2 +- .../Alpha- (mode proxy) RPC regression tests- misc_protocol.out | 2 +- ...oxy_server_data_dir) RPC regression tests- misc_protocol.out | 2 +- ...de proxy_server_rpc) RPC regression tests- misc_protocol.out | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index 0f3ba89ec871..1d9060d2c4c8 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -76,7 +76,7 @@ "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, "autostaking_enable": true, "adaptive_issuance_force_activation": false, - "ns_enable": false, "direct_ticket_spending_enable": false } + "ns_enable": true, "direct_ticket_spending_enable": false } ./octez-client rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index aac8177c008a..e0ab02cc8c52 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -76,7 +76,7 @@ "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, "autostaking_enable": true, "adaptive_issuance_force_activation": false, - "ns_enable": false, "direct_ticket_spending_enable": false } + "ns_enable": true, "direct_ticket_spending_enable": false } ./octez-client --mode light rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index 2149eb2092eb..e0016303b2aa 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -76,7 +76,7 @@ "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, "autostaking_enable": true, "adaptive_issuance_force_activation": false, - "ns_enable": false, "direct_ticket_spending_enable": false } + "ns_enable": true, "direct_ticket_spending_enable": false } ./octez-client --mode proxy rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out index 3b39db3348d5..4b95bc68d5c4 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out @@ -76,7 +76,7 @@ "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, "autostaking_enable": true, "adaptive_issuance_force_activation": false, - "ns_enable": false, "direct_ticket_spending_enable": false } + "ns_enable": true, "direct_ticket_spending_enable": false } ./octez-client rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 3, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out index 3b39db3348d5..4b95bc68d5c4 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out @@ -76,7 +76,7 @@ "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, "autostaking_enable": true, "adaptive_issuance_force_activation": false, - "ns_enable": false, "direct_ticket_spending_enable": false } + "ns_enable": true, "direct_ticket_spending_enable": false } ./octez-client rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 3, "delegate": "[PUBLIC_KEY_HASH]", -- GitLab From 08600ede32936d9dfe821873cfa7802a8e25b9d8 Mon Sep 17 00:00:00 2001 From: Mathias Bourgoin Date: Wed, 14 Feb 2024 17:21:57 +0100 Subject: [PATCH 3/8] docs/proto: update alpha changelog --- docs/protocols/alpha.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 83fdde472ec6..51527678d642 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -98,7 +98,7 @@ Adaptive Issuance (ongoing) a strong incentive against potential consensus attacks. (MR :gl:`!11854`) -- Activating adaptive issuance per-block vote (MR !11935) +- Activating adaptive issuance per-block vote (MR :gl:`!11935`) - Adjust total supply tracked for AI (estimated in O) so that it matches the actual total supply. (MR :gl:`!11996`) @@ -107,6 +107,7 @@ Adaptive Issuance (ongoing) - Add RPC to get min_delegated_in_current_cycle for a delegate using ``GET '/chains/main/blocks/[BLOCK_ID]]/context/delegates/[PUBLIC_KEY_HASH]/min_delegated_in_current_cycle'`` (MR :gl:`!12018`) +- Activating new slashing flag (MR :gl:`!12013`) Gas improvements ---------------- -- GitLab From cd47082abe96175242fb5ed3621a56c8614dfd77 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Fri, 16 Feb 2024 17:56:44 +0100 Subject: [PATCH 4/8] proto/tests: fix mini_slash with ns_enable = true --- .../test_adaptive_issuance_roundtrip.ml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml index 3390af28a1d4..753ea063970d 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml @@ -2884,12 +2884,14 @@ module Slashing = struct ["delegate"; "baker"]) --> unstake "delegate" (Amount Tez.one_mutez) --> set_baker "baker" --> next_cycle - --> ((Tag "7% slash" --> double_bake "delegate" --> make_denunciations () - |+ Tag "99% slash" --> next_cycle --> double_attest "delegate" - --> loop 7 (double_bake "delegate") - --> make_denunciations ()) - --> next_cycle - --> check_balance_field "delegate" `Unstaked_frozen_total Tez.zero) + --> (Tag "5% slash" --> double_bake "delegate" --> make_denunciations () + |+ Tag "95% slash" --> next_cycle --> double_attest "delegate" + --> loop 9 (double_bake "delegate") + --> make_denunciations ()) + (* Wait two cycles because of ns_enable *) + --> next_cycle + --> next_cycle + --> check_balance_field "delegate" `Unstaked_frozen_total Tez.zero --> wait_n_cycles (constants.consensus_rights_delay + 1) let test_slash_rounding = -- GitLab From 0c7af42493d9f12b487e60729c1c051793ea849c Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Mon, 19 Feb 2024 11:24:38 +0100 Subject: [PATCH 5/8] Proto/tests: update test to have the slash --- .../test/integration/test_adaptive_issuance_roundtrip.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml index 753ea063970d..5d638863fab2 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml @@ -2561,7 +2561,7 @@ module Slashing = struct else return_unit) --> check_snapshot_balances "before slash") --> exec_unit check_pending_slashings - --> next_block + --> next_cycle |+ Tag "denounce too late" --> next_cycle --> next_cycle --> assert_failure ~expected_error:(fun (_block, state) -> -- GitLab From 402826b0f89e3c6b6de27d396ee368ff0a793997 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Mon, 19 Feb 2024 16:11:32 +0100 Subject: [PATCH 6/8] Proto/tests: update block helper --- .../lib_protocol/test/helpers/block.ml | 17 ++++++++++++----- .../lib_protocol/test/helpers/block.mli | 13 ++++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index 28d784014b69..4bffbbbaf29e 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -1273,9 +1273,17 @@ let bake_until_cycle_end_with_metadata ?baking_mode ?policy b = in return (blk, eoc_metadata, nxt_metadata) -let bake_until_n_cycle_end ?policy n b = +let bake_until_n_cycle_end ?baking_mode ?policy n b = let cycle = current_cycle b in - bake_until_cycle ?policy (Cycle.add cycle n) b + bake_until_cycle ?baking_mode ?policy (Cycle.add cycle n) b + +let bake_until_n_cycle_end_with_metadata ?baking_mode ?policy n b = + let open Lwt_result_syntax in + let cycle = current_cycle b in + let* blk, (eoc_metadata, nxt_metadata) = + bake_until_cycle_with_metadata ?baking_mode ?policy (Cycle.add cycle n) b + in + return (blk, eoc_metadata, nxt_metadata) let debited_of_balance_update_item (it : Receipt.balance_update_item) : Tez.t option = @@ -1309,6 +1317,5 @@ let autostaked_opt baker (metadata : block_header_metadata) = autostaked_bal_up_opt let autostaked ?(loc = __LOC__) baker metadata = - match autostaked_opt baker metadata with - | None -> raise (Failure (loc ^ ":No autostake found")) - | Some tez -> tez + ignore loc ; + match autostaked_opt baker metadata with None -> Tez.zero | Some tez -> tez diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index 0256dfe6c7a4..1dfc38eb2f14 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -370,7 +370,18 @@ val bake_until_cycle_end_with_metadata : (** Bakes enough blocks to end [n] cycles. *) val bake_until_n_cycle_end : - ?policy:baker_policy -> int -> t -> t tzresult Lwt.t + ?baking_mode:baking_mode -> + ?policy:baker_policy -> + int -> + t -> + t tzresult Lwt.t + +val bake_until_n_cycle_end_with_metadata : + ?baking_mode:baking_mode -> + ?policy:baker_policy -> + int -> + block -> + (block * block_header_metadata option * block_header_metadata) tzresult Lwt.t (** Bakes enough blocks to reach the cycle. *) val bake_until_cycle : -- GitLab From 1bb893b9c8c1d414b88bcda6cc2d4bccacc1ef6b Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Mon, 19 Feb 2024 17:04:03 +0100 Subject: [PATCH 7/8] Proto/tests: fix tests --- .../consensus/test_double_attestation.ml | 10 ++++++---- .../integration/consensus/test_double_baking.ml | 16 ++++++++++------ .../consensus/test_double_preattestation.ml | 9 +++++---- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml index bbf5c482c51f..38148cdbf5b3 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml @@ -143,7 +143,7 @@ let test_valid_double_attestation_evidence () = let* frozen_deposits_right_after = Context.Delegate.current_frozen_deposits (B blk_final) delegate in - (* Check that the initial frozen deposits has not changed *) + (* Check that the initial frozen deposits have not changed *) let* () = Assert.equal_tez ~loc:__LOC__ initial_frozen_deposits frozen_deposits_before in @@ -156,8 +156,9 @@ let test_valid_double_attestation_evidence () = frozen_deposits_before in let* blk_eoc, metadata, _ = - Block.bake_until_cycle_end_with_metadata + Block.bake_until_n_cycle_end_with_metadata ~policy:(By_account baker) + 2 blk_final in let metadata = Option.value_f ~default:(fun () -> assert false) metadata in @@ -335,8 +336,9 @@ let test_two_double_attestation_evidences_leadsto_no_bake () = in (* Check that all frozen deposits have been slashed at the end of the cycle. *) let* b, metadata, _ = - Block.bake_until_cycle_end_with_metadata + Block.bake_until_n_cycle_end_with_metadata ~policy:(By_account baker) + 2 blk_with_evidence2 in let metadata = Option.value_f ~default:(fun () -> assert false) metadata in @@ -350,7 +352,7 @@ let test_two_double_attestation_evidences_leadsto_no_bake () = Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle ~policy:(By_account baker) (B b) - (Block.current_cycle blk_with_evidence2) + (Block.current_cycle b) delegate base_reward in diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml index 0f04bb884285..86255a92aecd 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml @@ -113,8 +113,9 @@ let test_valid_double_baking_evidence () = in (* Check that the frozen deposits have been slashed at the end of the cycle. *) let* blk_eoc, end_cycle_metadata, _next_cycle = - Block.bake_until_cycle_end_with_metadata + Block.bake_until_n_cycle_end_with_metadata ~policy:(By_account baker2) + 2 blk_final in let end_cycle_metadata = @@ -189,8 +190,9 @@ let test_valid_double_baking_followed_by_double_attesting () = frozen_deposits_right_after in let* blk_eoc, metadata, _ = - Block.bake_until_cycle_end_with_metadata + Block.bake_until_n_cycle_end_with_metadata ~policy:(By_account baker2) + 2 blk_final in let metadata = Option.value_f ~default:(fun () -> assert false) metadata in @@ -267,8 +269,9 @@ let test_valid_double_attesting_followed_by_double_baking () = frozen_deposits_right_after in let* blk_eoc, end_cycle_metadata, _ = - Block.bake_until_cycle_end_with_metadata + Block.bake_until_n_cycle_end_with_metadata ~policy:(By_account baker2) + 2 blk_with_db_evidence in let end_cycle_metadata = @@ -305,7 +308,9 @@ let test_valid_double_attesting_followed_by_double_baking () = the reward. *) let test_payload_producer_gets_evidence_rewards () = let open Lwt_result_syntax in - let* genesis, contracts = Context.init_n ~consensus_threshold:0 10 () in + let* genesis, contracts = + Context.init_n ~consensus_threshold:0 ~consensus_committee_size:64 10 () + in let* c = Context.get_constants (B genesis) in let p = c.parametric.percentage_of_frozen_deposits_slashed_per_double_baking @@ -375,13 +380,12 @@ let test_payload_producer_gets_evidence_rewards () = in (* Slashing and rewarding happen at the end of the cycle. *) let* b', end_cycle_metadata, _ = - Block.bake_until_cycle_end_with_metadata ~policy:(By_account baker2) b' + Block.bake_until_n_cycle_end_with_metadata ~policy:(By_account baker2) 2 b' in let end_cycle_metadata = Option.value_f ~default:(fun () -> assert false) end_cycle_metadata in let autostaked = Block.autostaked baker1 end_cycle_metadata in - let* frozen_deposits_after = Context.Delegate.current_frozen_deposits (B b') baker1 in diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml index 0ed039a49913..1d8343bec74e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml @@ -48,8 +48,8 @@ end = struct let bake_n = Block.bake_n ~baking_mode:Mode.baking_mode - let bake_until_cycle_end = - Block.bake_until_cycle_end ~baking_mode:Mode.baking_mode + let bake_until_n_cycle_end = + Block.bake_until_n_cycle_end ~baking_mode:Mode.baking_mode (****************************************************************) (* Utility functions *) @@ -143,8 +143,8 @@ end = struct let* bal_bad = Context.Delegate.full_balance (B bbad) d1 in let* () = Assert.equal_tez ~loc:__LOC__ bal_good bal_bad in (* Slashing happens at the end of the cycle. *) - let* bgood = bake_until_cycle_end ~policy:(By_account baker) bgood in - let* bbad = bake_until_cycle_end ~policy:(By_account baker) bbad in + let* bgood = bake_until_n_cycle_end ~policy:(By_account baker) 2 bgood in + let* bbad = bake_until_n_cycle_end ~policy:(By_account baker) 2 bbad in (* Checking what the attester lost *) let* frozen_deposit = Context.Delegate.current_frozen_deposits (B pred) d1 @@ -231,6 +231,7 @@ end = struct ~issuance_weights ~adaptive_issuance ~consensus_threshold:0 + ~consensus_committee_size:64 10 () in -- GitLab From 8a4bc8eeb78842075f5c0b00a21bc7b437624e9a Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Mon, 19 Feb 2024 14:23:15 +0100 Subject: [PATCH 8/8] Proto/tests/tezt: fix test --- tezt/tests/adaptive_issuance.ml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tezt/tests/adaptive_issuance.ml b/tezt/tests/adaptive_issuance.ml index 19d8d03cef7f..bfb5c5ab8d5f 100644 --- a/tezt/tests/adaptive_issuance.ml +++ b/tezt/tests/adaptive_issuance.ml @@ -1082,6 +1082,15 @@ let test_staking = else Test.fail "Double baking evidence was not found" in + (* Bake a cycle to wait for the slashing *) + let* () = + Helpers.bake_n_cycles + bake + ~keys:[Constant.bootstrap1.public_key_hash] + 1 + client_1 + in + let* bu = Operation_receipt.get_block_metadata client_1 in let* bu = Operation_receipt.Balance_updates.from_result [bu] in @@ -1323,7 +1332,7 @@ let test_staking = in assert (List.length finalizable == 0) ; - assert (List.length unfinalizable == 1) ; + assert (List.length unfinalizable == 0) ; let* balance2 = Client.get_balance_for ~account:staker0.alias client_1 in Log.info -- GitLab