From 13931897d72707fe3fefb5ccdfc50ff6d80cd4d5 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 13 Feb 2023 13:52:00 +0100 Subject: [PATCH 1/2] baker: apply operations on round greater than zero --- .../lib_delegate/baking_actions.ml | 11 +++++++++-- .../lib_delegate/baking_actions.mli | 5 +++++ src/proto_016_PtMumbai/lib_delegate/baking_lib.ml | 2 ++ .../lib_delegate/state_transitions.ml | 14 ++++++++++++-- src/proto_alpha/lib_delegate/baking_actions.ml | 11 +++++++++-- src/proto_alpha/lib_delegate/baking_actions.mli | 5 +++++ src/proto_alpha/lib_delegate/baking_lib.ml | 2 ++ src/proto_alpha/lib_delegate/state_transitions.ml | 14 ++++++++++++-- 8 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml b/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml index e05821d643bc..b24a54100308 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_actions.ml @@ -119,6 +119,7 @@ type block_to_bake = { round : Round.t; delegate : Baking_state.consensus_key_and_delegate; kind : block_kind; + force_apply : bool; } type action = @@ -214,7 +215,13 @@ let sign_block_header state proposer unsigned_block_header = return {Block_header.shell; protocol_data = {contents; signature}} let inject_block ~state_recorder state block_to_bake ~updated_state = - let {predecessor; round; delegate = (consensus_key, _) as delegate; kind} = + let { + predecessor; + round; + delegate = (consensus_key, _) as delegate; + kind; + force_apply; + } = block_to_bake in Events.( @@ -311,7 +318,7 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = ~payload_round ~liquidity_baking_toggle_vote ~user_activated_upgrades - ~force_apply:state.global_state.config.force_apply + ~force_apply state.global_state.config.fees simulation_mode simulation_kind diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli b/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli index 91b9bf772915..5b9715905497 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli +++ b/src/proto_016_PtMumbai/lib_delegate/baking_actions.mli @@ -41,6 +41,11 @@ type block_to_bake = { round : Round.t; delegate : consensus_key_and_delegate; kind : block_kind; + force_apply : bool; + (** if true, while baking the block, try and apply the block and its + operations instead of only validating them. this can be permanently + set using the [--force-apply] flag (see [force_apply_switch_arg] in + [baking_commands.ml]). *) } type action = diff --git a/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml b/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml index 5adbda789e44..ebb2cd35fc0c 100644 --- a/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml +++ b/src/proto_016_PtMumbai/lib_delegate/baking_lib.ml @@ -235,6 +235,7 @@ let propose_at_next_level ~minimal_timestamp state = round = minimal_round; delegate; kind; + force_apply = state.global_state.config.force_apply; } in let state_recorder ~new_state = @@ -476,6 +477,7 @@ let baking_minimal_timestamp state = round = minimal_round; delegate; kind; + force_apply = state.global_state.config.force_apply; } in let state_recorder ~new_state = diff --git a/src/proto_016_PtMumbai/lib_delegate/state_transitions.ml b/src/proto_016_PtMumbai/lib_delegate/state_transitions.ml index d39c05dbc8cd..5cc55044263d 100644 --- a/src/proto_016_PtMumbai/lib_delegate/state_transitions.ml +++ b/src/proto_016_PtMumbai/lib_delegate/state_transitions.ml @@ -413,7 +413,12 @@ let propose_fresh_block_action ~endorsements ?last_proposal in let kind = Fresh operation_pool in Events.(emit proposing_fresh_block (delegate, round)) >>= fun () -> - let block_to_bake = {predecessor; round; delegate; kind} in + let force_apply = + state.global_state.config.force_apply || Round.(round <> zero) + (* This is used as a safety net by applying blocks on round > 0, in case + validation-only did not produce a correct round-0 block. *) + in + let block_to_bake = {predecessor; round; delegate; kind; force_apply} in let updated_state = update_current_phase state Idle in Lwt.return @@ Inject_block {block_to_bake; updated_state} @@ -498,8 +503,13 @@ let propose_block_action state delegate round (proposal : proposal) = let kind = Reproposal {consensus_operations; payload_hash; payload_round; payload} in + let force_apply = + true + (* This is used as a safety net by applying blocks on round > 0, in case + validation-only did not produce a correct round-0 block. *) + in let block_to_bake = - {predecessor = proposal.predecessor; round; delegate; kind} + {predecessor = proposal.predecessor; round; delegate; kind; force_apply} in let updated_state = update_current_phase state Idle in Lwt.return @@ Inject_block {block_to_bake; updated_state} diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index 42153493a602..3b78c068e85d 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -119,6 +119,7 @@ type block_to_bake = { round : Round.t; delegate : Baking_state.consensus_key_and_delegate; kind : block_kind; + force_apply : bool; } type action = @@ -214,7 +215,13 @@ let sign_block_header state proposer unsigned_block_header = return {Block_header.shell; protocol_data = {contents; signature}} let inject_block ~state_recorder state block_to_bake ~updated_state = - let {predecessor; round; delegate = (consensus_key, _) as delegate; kind} = + let { + predecessor; + round; + delegate = (consensus_key, _) as delegate; + kind; + force_apply; + } = block_to_bake in Events.( @@ -311,7 +318,7 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = ~payload_round ~liquidity_baking_toggle_vote ~user_activated_upgrades - ~force_apply:state.global_state.config.force_apply + ~force_apply state.global_state.config.fees simulation_mode simulation_kind diff --git a/src/proto_alpha/lib_delegate/baking_actions.mli b/src/proto_alpha/lib_delegate/baking_actions.mli index 07665261acea..360f1f761e27 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.mli +++ b/src/proto_alpha/lib_delegate/baking_actions.mli @@ -41,6 +41,11 @@ type block_to_bake = { round : Round.t; delegate : consensus_key_and_delegate; kind : block_kind; + force_apply : bool; + (** if true, while baking the block, try and apply the block and its + operations instead of only validating them. this can be permanently + set using the [--force-apply] flag (see [force_apply_switch_arg] in + [baking_commands.ml]). *) } type action = diff --git a/src/proto_alpha/lib_delegate/baking_lib.ml b/src/proto_alpha/lib_delegate/baking_lib.ml index 113cab5a0a57..8ce23bda6549 100644 --- a/src/proto_alpha/lib_delegate/baking_lib.ml +++ b/src/proto_alpha/lib_delegate/baking_lib.ml @@ -235,6 +235,7 @@ let propose_at_next_level ~minimal_timestamp state = round = minimal_round; delegate; kind; + force_apply = state.global_state.config.force_apply; } in let state_recorder ~new_state = @@ -488,6 +489,7 @@ let baking_minimal_timestamp state = round = minimal_round; delegate; kind; + force_apply = state.global_state.config.force_apply; } in let state_recorder ~new_state = diff --git a/src/proto_alpha/lib_delegate/state_transitions.ml b/src/proto_alpha/lib_delegate/state_transitions.ml index d39c05dbc8cd..5cc55044263d 100644 --- a/src/proto_alpha/lib_delegate/state_transitions.ml +++ b/src/proto_alpha/lib_delegate/state_transitions.ml @@ -413,7 +413,12 @@ let propose_fresh_block_action ~endorsements ?last_proposal in let kind = Fresh operation_pool in Events.(emit proposing_fresh_block (delegate, round)) >>= fun () -> - let block_to_bake = {predecessor; round; delegate; kind} in + let force_apply = + state.global_state.config.force_apply || Round.(round <> zero) + (* This is used as a safety net by applying blocks on round > 0, in case + validation-only did not produce a correct round-0 block. *) + in + let block_to_bake = {predecessor; round; delegate; kind; force_apply} in let updated_state = update_current_phase state Idle in Lwt.return @@ Inject_block {block_to_bake; updated_state} @@ -498,8 +503,13 @@ let propose_block_action state delegate round (proposal : proposal) = let kind = Reproposal {consensus_operations; payload_hash; payload_round; payload} in + let force_apply = + true + (* This is used as a safety net by applying blocks on round > 0, in case + validation-only did not produce a correct round-0 block. *) + in let block_to_bake = - {predecessor = proposal.predecessor; round; delegate; kind} + {predecessor = proposal.predecessor; round; delegate; kind; force_apply} in let updated_state = update_current_phase state Idle in Lwt.return @@ Inject_block {block_to_bake; updated_state} -- GitLab From 1f2fc2f3e484447786fb2f962e6832f6783cdae6 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 13 Feb 2023 10:19:16 +0100 Subject: [PATCH 2/2] Changes: add entry --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 41911f4d9849..04b6cc133062 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -86,6 +86,10 @@ Baker states in order to avoid unexpected crashes when the baker gets updated, or when a new protocol's baker starts. (MR :gl:`!7640`) +- Restored previous behaviour from :gl:`!7490` for blocks at round + greater than 0. Application-dependent checks are re-enabled for + re-proposal and fresh blocks at round greater than 0. + Accuser ------- -- GitLab