diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 83fdde472ec622edd00d65ac6c562cc20ca75c7a..51527678d6429d7e30718ce575e91cc4ce63ac9b 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 ---------------- diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 1012559309b4d8a8427dbfddbb398f847661ff84..6c10e7ec75c5e140459d2546d7529ad9284f0c51 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 e280159687af3ca375426a689602dc71ff647d12..2b3c234b16ac8c735f52c03ae095f6f9e9c84ef6 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 diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index 28d784014b69318b385d98e664b0625ed966a700..4bffbbbaf29e7054fe82c8c7d6726f32fd535d68 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 0256dfe6c7a4f61ee9fef0cbeaf277b5541f34fd..1dfc38eb2f1446fcf42317ce96c9e3d15ee9f93e 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 : 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 bbf5c482c51f782ea47d50ba716eef1b274bad4f..38148cdbf5b3af1e941f9f55c8026f28df879a22 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 0f04bb8842850c8b965273ff88716b187c41de54..86255a92aecd044cd122d944637d302ca08a2308 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 0ed039a499138efac197de56f4a60c03b9f98907..1d8343bec74ebb3f29ffac65ba562b08c6d2bd39 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 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 3390af28a1d44cf4ddff638b6202b7f2c21e3111..5d638863fab2efad818e2d75e284495c7a6de939 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) -> @@ -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 = diff --git a/tezt/tests/adaptive_issuance.ml b/tezt/tests/adaptive_issuance.ml index 19d8d03cef7f9d0e2e2ff2ca618dd7902ce3e61d..bfb5c5ab8d5f0e5caefa02ae49a77df933eb35c9 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 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 0f3ba89ec8716d258e68bd7d65c44cf9fefc781d..1d9060d2c4c89ece64b38bc9eca803c8f4844d57 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 aac8177c008a6cda7f816f9b602608e26c4a330a..e0ab02cc8c52fd40b1599b250e8a5e0d68823e9a 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 2149eb2092eb6cc7b77a11f3ab09cf08bc353650..e0016303b2aa6cff1e4ed6f1a227b06333dc9aed 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 3b39db3348d5c02fecd74e6ad7e93f7caac6bb46..4b95bc68d5c4c0f32e51869da26724ea68406edd 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 3b39db3348d5c02fecd74e6ad7e93f7caac6bb46..4b95bc68d5c4c0f32e51869da26724ea68406edd 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]",