From cea8d44e57136df2cd844a9761db335809aca015 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Mon, 8 Jan 2024 15:22:47 +0100 Subject: [PATCH 1/4] SR: make constants depend on block time --- .../lib_parameters/default_parameters.ml | 190 +++++++++--------- src/proto_alpha/lib_protocol/raw_context.ml | 16 ++ 2 files changed, 116 insertions(+), 90 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 97e6a172dcce..1fd837f2dab9 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -27,52 +27,103 @@ open Protocol.Alpha_context -(** The challenge window is about two weeks with 15s block-time, - (4 * 60 * 24 * 14). - WARNING: changing this value also impacts - [sc_rollup_max_active_outbox_levels]. See below. *) -let sc_rollup_challenge_window_in_blocks = 80_640 - -(** Number of active levels kept for executing outbox messages. - - WARNING: Changing this value impacts the storage charge for - applying messages from the outbox. It also requires migration for - remapping existing active outbox levels to new indices. *) -let sc_rollup_max_active_outbox_levels = - Int32.of_int sc_rollup_challenge_window_in_blocks - -(** Maximum number of outbox messages per level. - - WARNING: changing this value impacts the storage size a rollup has to - pay for at origination time. *) -let sc_rollup_max_outbox_messages_per_level = 100 - -(** The timeout period is about a week with 15s block-time, - (4 * 60 * 24 * 7). - - It suffers from the same risk of censorship as - {!sc_rollup_challenge_windows_in_blocks} so we use the same value. -*) -let sc_rollup_timeout_period_in_blocks = 40_320 - -(** We want to allow a max lookahead in blocks of 4 weeks, so the rollup - can still move forward even if its impossible to cement commitments. - - As there is a challenge window of 2 weeks, and because the maximum - duration of a game is 2 weeks, the hypothetical maximum time - to cement a block is a month, (4 * 60 * 24 * 30). - - Be careful, this constant has an impact of the maximum cost of - a rollup on the storage: - [maximum_cost_in_storage = - (sc_rollup_max_lookahead_in_blocks / commitment_period) * - max_commitment_storage_size_in_bytes * - cost_per_byte] - - With the current values: - [maximum_cost_in_storage = 348.3 tez] -*) -let sc_rollup_max_lookahead_in_blocks = 172_800l +let seconds_in_a_day = 60 * 60 * 24 + +let seconds_in_a_week = seconds_in_a_day * 7 + +let make_sc_rollup_parameter ~dal_activation_level block_time = + (* Maximum number of outbox messages per level. + + WARNING: changing this value impacts the storage size a rollup has to + pay for at origination time. *) + let max_outbox_messages_per_level = 100 in + + (* The commitment period in blocks is about 15 minutes. *) + let commitment_period_in_blocks = 60 * 15 / block_time in + + (* The challenge window is about two weeks. WARNING: changing this + value also impacts [sc_rollup_max_active_outbox_levels]. See + below. *) + let challenge_window_in_blocks = seconds_in_a_week * 2 / block_time in + + (* Number of active levels kept for executing outbox messages. + + WARNING: Changing this value impacts the storage charge for + applying messages from the outbox. It also requires migration for + remapping existing active outbox levels to new indices. *) + let max_active_outbox_levels = Int32.of_int challenge_window_in_blocks in + + (* The timeout period is about a week. It suffers from the same + risk of censorship as {!sc_rollup_challenge_windows_in_blocks} so + we use the same value. *) + let timeout_period_in_blocks = seconds_in_a_week / block_time in + + (* We want to allow a max lookahead in blocks of 4 weeks, so the + rollup can still move forward even if its impossible to cement + commitments. + + As there is a challenge window of 2 weeks, and because the maximum + duration of a game is 2 weeks, the hypothetical maximum time + to cement a block is a month. + + Be careful, this constant has an impact of the maximum cost of + a rollup on the storage: + [maximum_cost_in_storage = + (sc_rollup_max_lookahead_in_blocks / commitment_period) * + max_commitment_storage_size_in_bytes * + cost_per_byte] + + With the current values: + [maximum_cost_in_storage = 348.3 tez] + *) + let max_lookahead_in_blocks = + let seconds_in_a_month = Int32.of_int (seconds_in_a_day * 30) in + let block_time = Int32.of_int block_time in + Int32.div seconds_in_a_month block_time + in + Constants.Parametric. + { + arith_pvm_enable = false; + (* The following value is chosen to prevent spam. *) + origination_size = 6_314; + challenge_window_in_blocks; + commitment_period_in_blocks; + stake_amount = Tez.of_mutez_exn 10_000_000_000L; + max_lookahead_in_blocks; + max_active_outbox_levels; + max_outbox_messages_per_level; + (* The default number of required sections in a dissection *) + number_of_sections_in_dissection = 32; + timeout_period_in_blocks; + (* We store multiple cemented commitments because we want to + allow the execution of outbox messages against cemented + commitments that are older than the last cemented commitment. + The execution of an outbox message is a manager operation, + and manager operations are kept in the mempool for one + hour. Hence we only need to ensure that an outbox message can + be validated against a cemented commitment produced in the + last hour. If we assume that the rollup is operating without + issues, that is no commitments are being refuted and + commitments are published and cemented regularly by one + rollup node, we can expect commitments to be cemented + approximately every 15 minutes, or equivalently we can expect + 5 commitments to be published in one hour (at minutes 0, 15, + 30, 45 and 60). Therefore, we need to keep 5 cemented + commitments to guarantee that the execution of an outbox + operation can always be validated against a cemented + commitment while it is in the mempool. *) + max_number_of_stored_cemented_commitments = 5; + max_number_of_parallel_games = 32; + reveal_activation_level = + { + raw_data = {blake2B = Raw_level.root}; + metadata = Raw_level.root; + dal_page = dal_activation_level; + dal_parameters = dal_activation_level; + }; + private_enable = true; + riscv_pvm_enable = false; + } (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3177 @@ -97,8 +148,8 @@ let default_dal = } let constants_mainnet = - let consensus_committee_size = 7000 in let block_time = 10 in + let consensus_committee_size = 7000 in let Constants.Generated. { consensus_threshold; @@ -127,6 +178,7 @@ let constants_mainnet = exception with the value [Int32.int_min] (see tezt/tests/mockup.ml). *) Raw_level.of_int32_exn Int32.(pred max_int) in + let sc_rollup = make_sc_rollup_parameter ~dal_activation_level block_time in { Constants.Parametric.preserved_cycles = 5; consensus_rights_delay = 5; @@ -209,49 +261,7 @@ let constants_mainnet = (* One for the sampler state for all cycles stored at any moment (as above). *) cache_sampler_state_cycles = 8; dal = default_dal; - sc_rollup = - { - arith_pvm_enable = false; - (* The following value is chosen to prevent spam. *) - origination_size = 6_314; - challenge_window_in_blocks = sc_rollup_challenge_window_in_blocks; - commitment_period_in_blocks = 60; - stake_amount = Tez.of_mutez_exn 10_000_000_000L; - max_lookahead_in_blocks = sc_rollup_max_lookahead_in_blocks; - max_active_outbox_levels = sc_rollup_max_active_outbox_levels; - max_outbox_messages_per_level = sc_rollup_max_outbox_messages_per_level; - (* The default number of required sections in a dissection *) - number_of_sections_in_dissection = 32; - timeout_period_in_blocks = sc_rollup_timeout_period_in_blocks; - (* We store multiple cemented commitments because we want to - allow the execution of outbox messages against cemented - commitments that are older than the last cemented commitment. - The execution of an outbox message is a manager operation, - and manager operations are kept in the mempool for one - hour. Hence we only need to ensure that an outbox message - can be validated against a cemented commitment produced in the - last hour. If we assume that the rollup is operating without - issues, that is no commitments are being refuted and commitments - are published and cemented regularly by one rollup node, we can - expect commitments to be cemented approximately every 15 - minutes, or equivalently we can expect 5 commitments to be - published in one hour (at minutes 0, 15, 30, 45 and 60). - Therefore, we need to keep 5 cemented commitments to guarantee - that the execution of an outbox operation can always be - validated against a cemented commitment while it is in the - mempool. *) - max_number_of_stored_cemented_commitments = 5; - max_number_of_parallel_games = 32; - reveal_activation_level = - { - raw_data = {blake2B = Raw_level.root}; - metadata = Raw_level.root; - dal_page = dal_activation_level; - dal_parameters = dal_activation_level; - }; - private_enable = true; - riscv_pvm_enable = false; - }; + sc_rollup; zk_rollup = { enable = false; diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 8d1ad90eadb2..6379f8b52042 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -955,8 +955,24 @@ let update_block_time_related_constants (c : Constants_parametric_repr.t) = let nonce_revelation_threshold = half_more c.nonce_revelation_threshold in let blocks_per_stake_snapshot = half_more c.blocks_per_stake_snapshot in let max_operations_time_to_live = 3 * c.max_operations_time_to_live / 2 in + let seconds_in_a_day = 60 * 60 * 24 in + let seconds_in_a_week = seconds_in_a_day * 7 in + let block_time = Int64.to_int (Period_repr.to_seconds minimal_block_delay) in + let sc_rollup = + { + c.sc_rollup with + challenge_window_in_blocks = seconds_in_a_week * 2 / block_time; + (* Same as challenge_window_in_blocks *) + max_active_outbox_levels = + Int32.of_int (seconds_in_a_week * 2 / block_time); + commitment_period_in_blocks = 60 * 15 / block_time; + max_lookahead_in_blocks = Int32.of_int (seconds_in_a_day * 30 / block_time); + timeout_period_in_blocks = seconds_in_a_week / block_time; + } + in { c with + sc_rollup; blocks_per_cycle; blocks_per_commitment; nonce_revelation_threshold; -- GitLab From 441ed5adac47df180263bd4cea0319c63e595526 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Mon, 8 Jan 2024 15:23:37 +0100 Subject: [PATCH 2/4] Test: update tests to new constants --- .../lib_protocol/test/integration/operations/test_sc_rollup.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index a5b84debeaa0..360051b5afb2 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -2900,7 +2900,7 @@ let test_curfew () = let open Lwt_result_syntax in let* block, (account1, account2, account3), rollup = (* sc_rollup_challenge_window_in_blocks should be at least commitment period *) - init_and_originate ~sc_rollup_challenge_window_in_blocks:60 Context.T3 + init_and_originate ~sc_rollup_challenge_window_in_blocks:90 Context.T3 in let* constants = Context.get_constants (B block) in let challenge_window = -- GitLab From 46fb66c5d7a45cb83a2039247ea233be0c4de7f0 Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Mon, 8 Jan 2024 17:59:18 +0100 Subject: [PATCH 3/4] Test: deactivate liquid balance check --- tezt/tests/sc_rollup.ml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 90770aefde7a..a83a39bdeca1 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -2160,6 +2160,7 @@ let attempt_withdraw_stake = ?(check_liquid_balance = true) ?(src = Constant.bootstrap1.public_key_hash) ?(staker = Constant.bootstrap1.public_key_hash) + ?(keys = [Constant.bootstrap2.alias]) client -> let recover_bond_fee = 1_000_000 in let inject_op () = @@ -2175,9 +2176,7 @@ let attempt_withdraw_stake = | None -> let*! () = inject_op () in let* old_bal = contract_balances ~pkh:staker client in - let* () = - Client.bake_for_and_wait ~keys:[Constant.bootstrap2.alias] client - in + let* () = Client.bake_for_and_wait ~keys client in let* new_bal = contract_balances ~pkh:staker client in let expected_liq_new_bal = old_bal.liquid - recover_bond_fee + sc_rollup_stake_amount @@ -2259,6 +2258,7 @@ let commitment_before_lcc_not_published protocol sc_rollup_node sc_rollup node ~sc_rollup ~sc_rollup_stake_amount:(Tez.to_mutez constants.stake_amount) client + ~keys:[] ~expect_failure: "Attempted to withdraw while not staked on the last cemented \ commitment." @@ -2277,6 +2277,8 @@ let commitment_before_lcc_not_published protocol sc_rollup_node sc_rollup node attempt_withdraw_stake ~sc_rollup ~sc_rollup_stake_amount:(Tez.to_mutez constants.stake_amount) + ~keys:[] + ~check_liquid_balance:false client in -- GitLab From ed577b11c6cf08663786059d322fa501cf1c86df Mon Sep 17 00:00:00 2001 From: Valentin Chaboche Date: Fri, 12 Jan 2024 16:41:45 +0100 Subject: [PATCH 4/4] Tezt: update regressions --- ...ode client) RPC regression tests- misc_protocol.out | 10 +++++----- ...mode light) RPC regression tests- misc_protocol.out | 10 +++++----- ...mode proxy) RPC regression tests- misc_protocol.out | 10 +++++----- ...r_data_dir) RPC regression tests- misc_protocol.out | 10 +++++----- ...server_rpc) RPC regression tests- misc_protocol.out | 10 +++++----- 5 files changed, 25 insertions(+), 25 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 1bdf69cf6f60..a20f0c53dcd6 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 @@ -42,14 +42,14 @@ "redundancy_factor": 8, "page_size": 128, "slot_size": 32768, "number_of_shards": 64 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, - "smart_rollup_challenge_window_in_blocks": 80640, + "smart_rollup_challenge_window_in_blocks": 120960, "smart_rollup_stake_amount": "10000000000", - "smart_rollup_commitment_period_in_blocks": 60, - "smart_rollup_max_lookahead_in_blocks": 172800, - "smart_rollup_max_active_outbox_levels": 80640, + "smart_rollup_commitment_period_in_blocks": 90, + "smart_rollup_max_lookahead_in_blocks": 259200, + "smart_rollup_max_active_outbox_levels": 120960, "smart_rollup_max_outbox_messages_per_level": 100, "smart_rollup_number_of_sections_in_dissection": 32, - "smart_rollup_timeout_period_in_blocks": 40320, + "smart_rollup_timeout_period_in_blocks": 60480, "smart_rollup_max_number_of_cemented_commitments": 5, "smart_rollup_max_number_of_parallel_games": 32, "smart_rollup_reveal_activation_level": 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 296dd6f32fc8..0951e336ff0d 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 @@ -42,14 +42,14 @@ "redundancy_factor": 8, "page_size": 128, "slot_size": 32768, "number_of_shards": 64 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, - "smart_rollup_challenge_window_in_blocks": 80640, + "smart_rollup_challenge_window_in_blocks": 120960, "smart_rollup_stake_amount": "10000000000", - "smart_rollup_commitment_period_in_blocks": 60, - "smart_rollup_max_lookahead_in_blocks": 172800, - "smart_rollup_max_active_outbox_levels": 80640, + "smart_rollup_commitment_period_in_blocks": 90, + "smart_rollup_max_lookahead_in_blocks": 259200, + "smart_rollup_max_active_outbox_levels": 120960, "smart_rollup_max_outbox_messages_per_level": 100, "smart_rollup_number_of_sections_in_dissection": 32, - "smart_rollup_timeout_period_in_blocks": 40320, + "smart_rollup_timeout_period_in_blocks": 60480, "smart_rollup_max_number_of_cemented_commitments": 5, "smart_rollup_max_number_of_parallel_games": 32, "smart_rollup_reveal_activation_level": 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 3c4fd283f2c3..793d37798206 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 @@ -42,14 +42,14 @@ "redundancy_factor": 8, "page_size": 128, "slot_size": 32768, "number_of_shards": 64 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, - "smart_rollup_challenge_window_in_blocks": 80640, + "smart_rollup_challenge_window_in_blocks": 120960, "smart_rollup_stake_amount": "10000000000", - "smart_rollup_commitment_period_in_blocks": 60, - "smart_rollup_max_lookahead_in_blocks": 172800, - "smart_rollup_max_active_outbox_levels": 80640, + "smart_rollup_commitment_period_in_blocks": 90, + "smart_rollup_max_lookahead_in_blocks": 259200, + "smart_rollup_max_active_outbox_levels": 120960, "smart_rollup_max_outbox_messages_per_level": 100, "smart_rollup_number_of_sections_in_dissection": 32, - "smart_rollup_timeout_period_in_blocks": 40320, + "smart_rollup_timeout_period_in_blocks": 60480, "smart_rollup_max_number_of_cemented_commitments": 5, "smart_rollup_max_number_of_parallel_games": 32, "smart_rollup_reveal_activation_level": 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 57e26d9e7df7..4c760b0af97f 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 @@ -42,14 +42,14 @@ "redundancy_factor": 8, "page_size": 128, "slot_size": 32768, "number_of_shards": 64 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, - "smart_rollup_challenge_window_in_blocks": 80640, + "smart_rollup_challenge_window_in_blocks": 120960, "smart_rollup_stake_amount": "10000000000", - "smart_rollup_commitment_period_in_blocks": 60, - "smart_rollup_max_lookahead_in_blocks": 172800, - "smart_rollup_max_active_outbox_levels": 80640, + "smart_rollup_commitment_period_in_blocks": 90, + "smart_rollup_max_lookahead_in_blocks": 259200, + "smart_rollup_max_active_outbox_levels": 120960, "smart_rollup_max_outbox_messages_per_level": 100, "smart_rollup_number_of_sections_in_dissection": 32, - "smart_rollup_timeout_period_in_blocks": 40320, + "smart_rollup_timeout_period_in_blocks": 60480, "smart_rollup_max_number_of_cemented_commitments": 5, "smart_rollup_max_number_of_parallel_games": 32, "smart_rollup_reveal_activation_level": 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 57e26d9e7df7..4c760b0af97f 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 @@ -42,14 +42,14 @@ "redundancy_factor": 8, "page_size": 128, "slot_size": 32768, "number_of_shards": 64 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, - "smart_rollup_challenge_window_in_blocks": 80640, + "smart_rollup_challenge_window_in_blocks": 120960, "smart_rollup_stake_amount": "10000000000", - "smart_rollup_commitment_period_in_blocks": 60, - "smart_rollup_max_lookahead_in_blocks": 172800, - "smart_rollup_max_active_outbox_levels": 80640, + "smart_rollup_commitment_period_in_blocks": 90, + "smart_rollup_max_lookahead_in_blocks": 259200, + "smart_rollup_max_active_outbox_levels": 120960, "smart_rollup_max_outbox_messages_per_level": 100, "smart_rollup_number_of_sections_in_dissection": 32, - "smart_rollup_timeout_period_in_blocks": 40320, + "smart_rollup_timeout_period_in_blocks": 60480, "smart_rollup_max_number_of_cemented_commitments": 5, "smart_rollup_max_number_of_parallel_games": 32, "smart_rollup_reveal_activation_level": -- GitLab