Skip to content

Commit

Permalink
Merge pull request #14644 from MinaProtocol/sventimir/zkapp-cmd-per-b…
Browse files Browse the repository at this point in the history
…lock-limit

Soft limit zkApp commands per block
  • Loading branch information
ejMina226 authored Jan 4, 2024
2 parents 0694f50 + a0238c0 commit 8c2faea
Show file tree
Hide file tree
Showing 56 changed files with 480 additions and 135 deletions.
1 change: 1 addition & 0 deletions src/config/debug.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/dev.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/dev_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/dev_snark.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/devnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
(* 2*block_window_duration *)
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/fake_hash.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/fork.mlh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[%%undef fork_previous_length]
[%%undef fork_previous_state_hash]
[%%undef fork_genesis_slot]
[%%undef zkapp_cmd_limit]
3 changes: 2 additions & 1 deletion src/config/fork_at_3757.mlh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[%%define fork_previous_length 3757]
[%%define fork_previous_state_hash "3NKR3QYJ7qwxiGgX39umahgdT8BH5yXBQwQtpYZdvodCXcsndK7f"]
[%%define fork_genesis_slot 12796]
[%%define fork_genesis_slot 12796]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/fuzz_medium.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/fuzz_small.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/integration_tests.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
(* This profile is only used for the test executive binary, so we don't need
snark keys, a valid genesis proof, etc. *)
[%%import "/src/config/proof_level/none.mlh"]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/lightnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
(* 2*block_window_duration *)
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/mainnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
(* 2*block_window_duration *)
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/nonconsensus_mainnet.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

[%%undef consensus_mechanism]
[%%undef compaction_interval]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/nonconsensus_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/print_versioned_types.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_archive_processor.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_catchup.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_five_even_txns.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_full_epoch.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_holy_grail.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/fork.mlh"]
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_snarkless.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_snarkless_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_split.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_split_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/test_postake_three_producers.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/testnet_postake.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/testnet_postake_many_producers.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/testnet_postake_medium_curves.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
(* 2*block_window_duration *)
[%%define compaction_interval 360000]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/testnet_postake_snarkless.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/testnet_postake_snarkless_fake_hash.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 0]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/testnet_public.mlh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
[%%import "/src/config/features/dev.mlh"]
[%%undef compaction_interval]
[%%define vrf_poll_interval 5000]
[%%undef zkapp_cmd_limit]
1 change: 1 addition & 0 deletions src/config/txpool_size.mlh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(* Note this value needs to be consistent across nodes to prevent spurious bans.
see comment in transaction_pool.ml for more details. *)
[%%define pool_max_size 3000]
[%%undef zkapp_cmd_limit]
13 changes: 8 additions & 5 deletions src/lib/block_producer/block_producer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ let lift_sync f =
[%log' error (Logger.create ())] "Ivar.fill bug is here!" ;
Ivar.fill ivar (f ()) ) )

let zkapp_cmd_limit = ref Mina_compile_config.zkapp_cmd_limit

module Singleton_scheduler : sig
type t

Expand Down Expand Up @@ -160,10 +162,10 @@ let report_transaction_inclusion_failures ~logger failed_txns =
let leftover_bytes = available_bytes - base_error_size - 2 in
wrap_error (`List (generate_errors failed_txns leftover_bytes)) )

let generate_next_state ~constraint_constants ~previous_protocol_state
~time_controller ~staged_ledger ~transactions ~get_completed_work ~logger
~(block_data : Consensus.Data.Block_data.t) ~winner_pk ~scheduled_time
~log_block_creation ~block_reward_threshold =
let generate_next_state ~zkapp_cmd_limit ~constraint_constants
~previous_protocol_state ~time_controller ~staged_ledger ~transactions
~get_completed_work ~logger ~(block_data : Consensus.Data.Block_data.t)
~winner_pk ~scheduled_time ~log_block_creation ~block_reward_threshold =
let open Interruptible.Let_syntax in
let previous_protocol_state_body_hash =
Protocol_state.body previous_protocol_state |> Protocol_state.Body.hash
Expand Down Expand Up @@ -200,7 +202,7 @@ let generate_next_state ~constraint_constants ~previous_protocol_state
staged_ledger ~coinbase_receiver ~logger
~current_state_view:previous_state_view
~transactions_by_fee:transactions ~get_completed_work
~log_block_creation ~supercharge_coinbase
~log_block_creation ~supercharge_coinbase ~zkapp_cmd_limit
|> Result.map ~f:(fun (diff, failed_txns) ->
if not (List.is_empty failed_txns) then
don't_wait_for
Expand Down Expand Up @@ -752,6 +754,7 @@ let run ~context:(module Context : CONTEXT) ~vrf_evaluator ~prover ~verifier
~staged_ledger:(Breadcrumb.staged_ledger crumb)
~transactions ~get_completed_work ~logger ~log_block_creation
~winner_pk:winner_pubkey ~block_reward_threshold
~zkapp_cmd_limit:!zkapp_cmd_limit
in
[%log internal] "Generate_next_state_done" ;
match next_state_opt with
Expand Down
21 changes: 21 additions & 0 deletions src/lib/mina_base/test/helpers/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(library
(name mina_base_test_helpers)
(libraries
;; opam libraries
base
base.caml
core_kernel
integers
sexplib0
yojson
;; local libraries
currency
mina_base
mina_base.import
mina_numbers
monad_lib
signature_lib)
(preprocess
(pps ppx_base ppx_let ppx_assert ppx_version))
(instrumentation
(backend bisect_ppx)))
12 changes: 12 additions & 0 deletions src/lib/mina_compile_config/mina_compile_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,15 @@ let max_event_elements = 100
let max_action_elements = 100

[%%inject "network_id", network]

[%%ifndef zkapp_cmd_limit]

let zkapp_cmd_limit = None

[%%else]

[%%inject "zkapp_cmd_limit", zkapp_cmd_limit]

let zkapp_cmd_limit = Some zkapp_cmd_limit

[%%endif]
12 changes: 11 additions & 1 deletion src/lib/mina_graphql/mina_graphql.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,17 @@ module Queries = struct
if not with_seq_no then Error "Missing sequence information"
else Ok (Itn_logger.get_logs start_log_id) )

let commands = [ auth; slots_won; internal_logs ]
let zkapp_cmd_limit =
field "zkAppCommandLimit"
~args:
Arg.[ arg "limit" ~doc:"ZkApp commands per block limit." ~typ:int ]
~typ:int
~doc:"Set zkApp commands per block limit for the block producer."
~resolve:(fun { ctx = _; _ } () limit ->
Block_producer.zkapp_cmd_limit := limit ;
limit )

let commands = [ auth; slots_won; internal_logs; zkapp_cmd_limit ]
end
end

Expand Down
29 changes: 29 additions & 0 deletions src/lib/mina_ledger/test/helpers/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(library
(name mina_ledger_test_helpers)
(libraries
;; opam libraries
base
base.caml
core_kernel
core
integers
sexplib0
yojson
;; local libraries
currency
kimchi_backend_common
kimchi_backend.pasta
kimchi_backend.pasta.basic
mina_base
mina_base_test_helpers
mina_ledger
mina_numbers
monad_lib
pickles
pickles.backend
pickles_types
signature_lib)
(preprocess
(pps ppx_base ppx_let ppx_assert ppx_version))
(instrumentation
(backend bisect_ppx)))
37 changes: 37 additions & 0 deletions src/lib/mina_ledger/test/helpers/ledger_helpers.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
open Core
open Mina_base
open Mina_base_test_helpers
open Mina_numbers
open Signature_lib
module Ledger = Mina_ledger.Ledger.Ledger_inner

let noncemap (accounts : Test_account.t list) :
Account_nonce.t Public_key.Compressed.Map.t =
Public_key.Compressed.Map.of_alist_exn
@@ List.map ~f:(fun a -> (a.pk, a.nonce)) accounts

let bin_log n =
let rec find candidate =
if Int.pow 2 candidate >= n then candidate else find (Int.succ candidate)
in
find 0

let ledger_of_accounts accounts =
let open Result.Let_syntax in
let open Test_account in
let module R = Monad_lib.Make_ext2 (Result) in
let depth = bin_log @@ List.length accounts in
let ledger = Ledger.empty ~depth () in
let%map () =
R.iter_m accounts ~f:(fun a ->
let acc_id = account_id a in
let account : Account.t = Account.initialize acc_id in
Ledger.create_new_account ledger acc_id
{ account with
balance = a.balance
; nonce = a.nonce
; zkapp = a.zkapp
; token_id = a.token_id
} )
in
ledger
Loading

0 comments on commit 8c2faea

Please sign in to comment.