diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index 575ee5ea732f39a437e8496fc69ab063381ea6a5..d3844550952c8891d0a0ca89b0ab552bbab97db2 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -51,15 +51,6 @@ let rpc_ctxt = rpc_context Plugin.RPC.rpc_services -let to_alpha_ctxt b = - Alpha_context.prepare - b.context - ~level:b.header.shell.level - ~predecessor_timestamp:b.header.shell.timestamp - ~timestamp:b.header.shell.timestamp - >|= Environment.wrap_tzresult - >>=? fun (ctxt, _balance_updates, _migration_results) -> return ctxt - (******** Policies ***********) (* Policies are functions that take a block and return a tuple diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index f89a68a844a2e9de13ee142c439c2fe0f2317a95..4fdf2a4d1f9baee146ecc95041a8dd78fecafcdb 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -39,9 +39,6 @@ type block = t val rpc_ctxt : t Environment.RPC_context.simple -(** Build an alpha context using {!Alpha_context.prepare}. *) -val to_alpha_ctxt : t -> Alpha_context.t tzresult Lwt.t - (** Policies to select the next baker: - [By_round r] selects the baker at round [r] - [By_account pkh] selects the first slot for baker [pkh] diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index c11f17a55521c620f1a2742e6f01cd8c36da8c96..20e0c6dbf19721737a777efd2405d794ba4a33af 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -40,10 +40,6 @@ let level = function B b -> b.header.shell.level | I i -> Incremental.level i let get_level ctxt = level ctxt |> Raw_level.of_int32 |> Environment.wrap_tzresult -let to_alpha_ctxt = function - | B b -> Block.to_alpha_ctxt b - | I i -> return (Incremental.alpha_ctxt i) - let rpc_ctxt = object method call_proto_service0 @@ -259,6 +255,9 @@ module Vote = struct let get_protocol (b : Block.t) = Tezos_protocol_environment.Context.get_protocol b.context + let get_delegate_proposal_count ctxt pkh = + Alpha_services.Voting.delegate_proposal_count rpc_ctxt ctxt pkh + let get_participation_ema (b : Block.t) = Environment.Context.find b.context ["votes"; "participation_ema"] >|= function @@ -277,11 +276,6 @@ module Vote = struct current_proposals : Protocol_hash.t list; remaining_proposals : int; } - - let get_delegate_proposal_count ctxt pkh = - to_alpha_ctxt ctxt >>=? fun alpha_ctxt -> - Vote.get_delegate_proposal_count alpha_ctxt pkh - >|= Environment.wrap_tzresult end module Contract = struct diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 87c3415b8e4421c764d8ec27c89b66bf1f4be6a9..d798566b30b4cfe1adb629e8a266aeee8ebf36a7 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -36,10 +36,6 @@ val pred_branch : t -> Block_hash.t val get_level : t -> Raw_level.t tzresult -(** Either retrieve the alpha context (in the [Incremental] case) or - build one (in the [Block] case). *) -val to_alpha_ctxt : t -> Alpha_context.t tzresult Lwt.t - (** Given a context, returns the list of endorsers charactized by the [level], the public key hash of the [delegate], its [consensus_key] and its assigned [slots]. 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 11b64a5122005765beda5cb5ad0aa0c5651f9f94..97b385e8ce8687e2518afae18e6a86539a0f4ae1 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 @@ -1294,7 +1294,7 @@ let test_older_cemented_commitment () = (Some 1) in let* max_num_stored_cemented_commitments = - let* ctxt = Context.to_alpha_ctxt (I incr) in + let ctxt = Incremental.alpha_ctxt incr in return @@ Alpha_context.Constants.max_number_of_stored_cemented_commitments ctxt in @@ -2986,7 +2986,10 @@ let init_with_4_conflicts () = let start_refutation_game_op block rollup (p1, p1_pkh) p2_pkh = let open Lwt_result_syntax in - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in let* (p1_point, p2_point), _ctxt = Sc_rollup.Refutation_storage.Internal_for_tests.get_conflict_point ctxt @@ -3171,7 +3174,10 @@ let test_conflict_point_on_a_branch () = let* ( ( {commitment = _; hash = conflict_pA_hash}, {commitment = _; hash = conflict_pB_hash} ), _ctxt ) = - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in Sc_rollup.Refutation_storage.Internal_for_tests.get_conflict_point ctxt rollup diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml index a57507ee8c97d17ebdd78efac5968f3f661890ce..dff63be21aad8c4f62f57a700e7ba336ca9e0d14 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml @@ -116,7 +116,10 @@ let voting_context_params params = let ballot_exploration_prelude state = let open Lwt_result_syntax in - let* ctxt = Context.to_alpha_ctxt (B state.block) in + let* ctxt = + let+ i = Incremental.begin_construction state.block in + Incremental.alpha_ctxt i + in let blocks_per_cycle = Alpha_context.Constants.blocks_per_cycle ctxt in let rem = Int32.rem state.block.Block.header.Block_header.shell.level blocks_per_cycle @@ -232,7 +235,10 @@ let ballot_promotion_descriptor = ( On 2, fun state -> let open Lwt_result_syntax in - let* ctxt = Context.to_alpha_ctxt (B state.block) in + let* ctxt = + let+ incr = Incremental.begin_construction state.block in + Incremental.alpha_ctxt incr + in let blocks_per_cycle = Alpha_context.Constants.blocks_per_cycle ctxt in @@ -410,7 +416,10 @@ let double_baking_descriptor = let c = Block_hash.compare hash1 hash2 in if c < 0 then (bh1, bh2) else (bh2, bh1) in - let* ctxt = Context.to_alpha_ctxt (B state.block) in + let* ctxt = + let+ incr = Incremental.begin_construction state.block in + Incremental.alpha_ctxt incr + in let blocks_per_cycle = Alpha_context.Constants.blocks_per_cycle ctxt in @@ -455,7 +464,10 @@ let double_baking_descriptor = delegate updates its key to this key. *) let drain_delegate_prelude state = let open Lwt_result_syntax in - let* ctxt = Context.to_alpha_ctxt (B state.block) in + let* ctxt = + let+ incr = Incremental.begin_construction state.block in + Incremental.alpha_ctxt incr + in let blocks_per_cycle = Alpha_context.Constants.blocks_per_cycle ctxt in let rem = Int32.rem state.block.Block.header.Block_header.shell.level blocks_per_cycle @@ -636,7 +648,10 @@ let dal_attestation_descriptor = candidates_generator = (fun state -> let gen (delegate, _) = - let* ctxt = Context.to_alpha_ctxt (B state.block) in + let* ctxt = + let+ incr = Incremental.begin_construction state.block in + Incremental.alpha_ctxt incr + in let* op = dal_slot_availibility ctxt delegate >|= Environment.wrap_tzresult in diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index 017442f4a96d394f0f2c368576b9d9004406f0ba..07b83b17f42d97c6a92476fb59de2accf60a9c2e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -1186,7 +1186,14 @@ let expected_witness witness probes ~mode ctxt = let observe ~mode ~deallocated ctxt_pre ctxt_post op = let open Lwt_result_syntax in let check_deallocated ctxt contract = - let* actxt = Context.to_alpha_ctxt ctxt in + let* actxt = + let+ i = + match ctxt with + | Context.B b -> Incremental.begin_construction b + | I i -> return i + in + Incremental.alpha_ctxt i + in let*! res = Contract.must_be_allocated actxt contract in match Environment.wrap_tzresult res with | Ok () -> diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/test_mempool.ml b/src/proto_alpha/lib_protocol/test/integration/validate/test_mempool.ml index 4fb1ecd70617fce9dfed6d773d5aa8680e502802..8174a9130213d15c62c5028ae2e21c9ed543bb2a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/test_mempool.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/test_mempool.ml @@ -98,7 +98,10 @@ let assert_operation_present_in_mempool ~__LOC__ mempool ophl = let test_simple () = let open Lwt_result_syntax in let* block, (c1, c2) = Context.init2 () in - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in let predecessor_level, predecessor_round, predecessor_hash, grandparent_round = extract_values ctxt block @@ -130,7 +133,10 @@ let test_imcompatible_mempool () = let open Lwt_result_syntax in let* block, _ = Context.init1 ~consensus_threshold:0 () in let* block = Block.bake block in - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in let predecessor_level, predecessor_round, predecessor_hash, grandparent_round = extract_values ctxt block @@ -146,7 +152,10 @@ let test_imcompatible_mempool () = in (* Create a second mempool on a different block *) let* block2 = Block.bake block in - let* ctxt2 = Block.to_alpha_ctxt block2 in + let* ctxt2 = + let+ incr = Incremental.begin_construction block2 in + Incremental.alpha_ctxt incr + in let predecessor_level, predecessor_round, predecessor_hash2, grandparent_round = extract_values ctxt2 block2 @@ -175,7 +184,10 @@ let test_imcompatible_mempool () = let test_merge () = let open Lwt_result_syntax in let* block, (c1, c2) = Context.init2 () in - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in let predecessor_level, predecessor_round, predecessor_hash, grandparent_round = extract_values ctxt block @@ -267,7 +279,10 @@ let test_merge () = let test_add_invalid_operation () = let open Lwt_result_syntax in let* block, c1 = Context.init1 () in - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in let predecessor_level, predecessor_round, predecessor_hash, grandparent_round = extract_values ctxt block @@ -292,7 +307,10 @@ let test_add_invalid_operation () = let test_add_and_replace () = let open Lwt_result_syntax in let* block, (c1, c2) = Context.init2 () in - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in let predecessor_level, predecessor_round, predecessor_hash, grandparent_round = extract_values ctxt block @@ -344,7 +362,10 @@ let test_add_and_replace () = let test_remove_operation () = let open Lwt_result_syntax in let* block, (c1, c2) = Context.init2 () in - let* ctxt = Block.to_alpha_ctxt block in + let* ctxt = + let+ incr = Incremental.begin_construction block in + Incremental.alpha_ctxt incr + in let predecessor_level, predecessor_round, predecessor_hash, grandparent_round = extract_values ctxt block diff --git a/src/proto_alpha/lib_protocol/voting_services.ml b/src/proto_alpha/lib_protocol/voting_services.ml index b005d4d47a9c27e09eb13153cdacaca65f3bc134..a93fdf641651c08b05a42b357c7da736bf9c69e2 100644 --- a/src/proto_alpha/lib_protocol/voting_services.ml +++ b/src/proto_alpha/lib_protocol/voting_services.ml @@ -100,6 +100,13 @@ module S = struct ~query:RPC_query.empty ~output:Data_encoding.int64 RPC_path.(path / "total_voting_power") + + let delegate_proposal_count = + RPC_service.get_service + ~description:"Number of votes casted during the current period." + ~query:RPC_query.empty + ~output:Data_encoding.int31 + RPC_path.(path / "proposal_count" /: Signature.Public_key_hash.rpc_arg) end let register () = @@ -120,7 +127,9 @@ let register () = register0 ~chunked:false S.current_proposal (fun ctxt () () -> Vote.find_current_proposal ctxt) ; register0 ~chunked:false S.total_voting_power (fun ctxt () () -> - Vote.get_total_voting_power_free ctxt) + Vote.get_total_voting_power_free ctxt) ; + register1 ~chunked:false S.delegate_proposal_count (fun ctxt pkh () () -> + Vote.get_delegate_proposal_count ctxt pkh) let ballots ctxt block = RPC_context.make_call0 S.ballots ctxt block () () @@ -145,3 +154,6 @@ let current_proposal ctxt block = let total_voting_power ctxt block = RPC_context.make_call0 S.total_voting_power ctxt block () () + +let delegate_proposal_count ctxt block pkh = + RPC_context.make_call1 S.delegate_proposal_count ctxt block pkh () () diff --git a/src/proto_alpha/lib_protocol/voting_services.mli b/src/proto_alpha/lib_protocol/voting_services.mli index 693ac397e91578c9ed0b056ff6ef91ac47004036..377ce080659742f866b422519d162db1942a9c38 100644 --- a/src/proto_alpha/lib_protocol/voting_services.mli +++ b/src/proto_alpha/lib_protocol/voting_services.mli @@ -61,3 +61,9 @@ val register : unit -> unit val total_voting_power : 'a #RPC_context.simple -> 'a -> Int64.t shell_tzresult Lwt.t + +val delegate_proposal_count : + 'a #RPC_context.simple -> + 'a -> + Signature.Public_key_hash.t -> + int shell_tzresult Lwt.t