Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft limit zkApp commands per block #14644

Merged
merged 21 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
641b361
Apply txns: move the stop check to the beginning of the function.
Sventimir Nov 29, 2023
041c426
Add the zkapp command per block limit for block production.
Sventimir Nov 30, 2023
09bcee6
Skip transactions whose dependencies have been skipped.
Sventimir Dec 4, 2023
83b0b1d
Add a compile-time configuration of zkapp command limit.
Sventimir Dec 5, 2023
333c518
Make an optional argument mandatory.
Sventimir Dec 6, 2023
9f2d840
Insert missing new line.
Sventimir Dec 6, 2023
824bd28
Make the limit mutable. Style improvements.
Sventimir Dec 6, 2023
d89299e
Implement a GQL mutation to alter the limit.
Sventimir Dec 7, 2023
6bfdbb4
Move test helpers from transaction_logic tests to appropriate libs.
Sventimir Dec 8, 2023
89dd6c8
Tests for the soft zkapp command limit.
Sventimir Dec 8, 2023
304ccd9
Code review changes
ejMina226 Dec 12, 2023
5f55e32
Code review changes for Staged Ledger
ejMina226 Dec 13, 2023
0dd7c1e
Code review - remove config location for zkapp_lim
ejMina226 Dec 13, 2023
a61d60a
Code review - ref in block-producer using and graphql changes
ejMina226 Dec 13, 2023
f189927
Remove redundant argument
ejMina226 Dec 14, 2023
9b690c7
Fix formatting in test so pipeline will pass
ejMina226 Dec 14, 2023
0703dff
Add ppx_version to fix linting error
ejMina226 Dec 14, 2023
7cc4eb3
Code review changes - conditional compilation
ejMina226 Dec 15, 2023
efc6256
Merge branch 'rampup' into sventimir/zkapp-cmd-per-block-limit
ejMina226 Dec 15, 2023
ea442a0
Remove unneeded variable
ejMina226 Dec 15, 2023
a0238c0
Merge branch 'rampup' into sventimir/zkapp-cmd-per-block-limit
ejMina226 Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

ejMina226 marked this conversation as resolved.
Show resolved Hide resolved
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
ejMina226 marked this conversation as resolved.
Show resolved Hide resolved

[%%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