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

try to fix the staged_ledger test #14058

Merged
merged 22 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ef9993c
try to fix the staged_ledger test
Sep 7, 2023
45ed508
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 8, 2023
0a46488
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 8, 2023
4e7b101
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 11, 2023
04a4995
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 11, 2023
a11adfb
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 14, 2023
052ec52
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 18, 2023
d322317
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 19, 2023
ca58b8c
renaming `keypairs` to `newkeypairs` for readability
Sep 19, 2023
9b708a7
Merge branch 'fix/staged-ledger-test-zkapp-gen' of github.com:MinaPro…
Sep 19, 2023
7d9f0b3
Merge branch 'berkeley' of github.com:MinaProtocol/mina into fix/stag…
Sep 19, 2023
fc54b27
fix compilation error
Sep 19, 2023
9624f29
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 20, 2023
4f018a0
reformat
Sep 20, 2023
591c826
Merge branch 'fix/staged-ledger-test-zkapp-gen' of github.com:MinaPro…
Sep 20, 2023
370b4b6
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 20, 2023
2c9528a
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 21, 2023
a914649
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 21, 2023
eb241e2
Merge branch 'berkeley' into fix/staged-ledger-test-zkapp-gen
ghost-not-in-the-shell Sep 21, 2023
cb8d87c
use Keypair.gen instead Keypair.create
Sep 25, 2023
a52b845
Merge branch 'fix/staged-ledger-test-zkapp-gen' of github.com:MinaPro…
Sep 25, 2023
5588a22
Merge branch 'berkeley' of github.com:MinaProtocol/mina into fix/stag…
Sep 25, 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
42 changes: 32 additions & 10 deletions src/lib/mina_generators/user_command_generators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ include User_command.Gen
(* using Precomputed_values depth introduces a cyclic dependency *)
[%%inject "ledger_depth", ledger_depth]

let zkapp_command_with_ledger ?num_keypairs ?max_account_updates
?max_token_updates ?account_state_tbl ?vk ?failure () =
let zkapp_command_with_ledger ?(ledger_init_state : Ledger.init_state option)
?num_keypairs ?max_account_updates ?max_token_updates ?account_state_tbl ?vk
?failure () =
let open Quickcheck.Let_syntax in
let open Signature_lib in
(* Need a fee payer keypair, a keypair for the "balancing" account (so that the balance changes
Expand All @@ -37,15 +38,36 @@ let zkapp_command_with_ledger ?num_keypairs ?max_account_updates
Option.value num_keypairs
~default:((max_account_updates * 2) + (max_token_updates * 3) + 2)
in
let keypairs = List.init num_keypairs ~f:(fun _ -> Keypair.create ()) in
let%bind new_keypairs =
let existing_keypairs =
let tbl = Public_key.Compressed.Hash_set.create () in
Option.iter ledger_init_state ~f:(fun l ->
Array.iter l ~f:(fun (kp, _balance, _nonce, _timing) ->
Hash_set.add tbl (Public_key.compress kp.public_key) ) ) ;
tbl
in
let rec go acc n =
if n = 0 then return acc
else
let%bind kp =
Quickcheck.Generator.filter Keypair.gen ~f:(fun kp ->
not
(Hash_set.mem existing_keypairs
(Public_key.compress kp.public_key) ) )
in
Hash_set.add existing_keypairs (Public_key.compress kp.public_key) ;
go (kp :: acc) (n - 1)
in
go [] num_keypairs
in
let keymap =
List.fold keypairs ~init:Public_key.Compressed.Map.empty
List.fold new_keypairs ~init:Public_key.Compressed.Map.empty
~f:(fun map { public_key; private_key } ->
let key = Public_key.compress public_key in
Public_key.Compressed.Map.add_exn map ~key ~data:private_key )
in
let num_keypairs_in_ledger = num_keypairs / 2 in
let keypairs_in_ledger = List.take keypairs num_keypairs_in_ledger in
let keypairs_in_ledger = List.take new_keypairs num_keypairs_in_ledger in
let account_ids =
List.map keypairs_in_ledger ~f:(fun { public_key; _ } ->
Account_id.create (Public_key.compress public_key) Token_id.default )
Expand Down Expand Up @@ -110,7 +132,7 @@ let zkapp_command_with_ledger ?num_keypairs ?max_account_updates
let account = Account.create account_id balance in
if ndx mod 2 = 0 then account else snappify_account account )
in
let fee_payer_keypair = List.hd_exn keypairs in
let fee_payer_keypair = List.hd_exn new_keypairs in
let ledger = Ledger.create ~depth:ledger_depth () in
List.iter2_exn account_ids accounts ~f:(fun acct_id acct ->
match Ledger.get_or_create_account ledger acct_id acct with
Expand Down Expand Up @@ -147,8 +169,8 @@ let zkapp_command_with_ledger ?num_keypairs ?max_account_updates
return
(User_command.Zkapp_command zkapp_command, fee_payer_keypair, keymap, ledger)

let sequence_zkapp_command_with_ledger ?max_account_updates ?max_token_updates
?length ?vk ?failure () =
let sequence_zkapp_command_with_ledger ?ledger_init_state ?max_account_updates
?max_token_updates ?length ?vk ?failure () =
let open Quickcheck.Let_syntax in
let%bind length =
match length with
Expand All @@ -169,8 +191,8 @@ let sequence_zkapp_command_with_ledger ?max_account_updates ?max_token_updates
(* Keep track of account states across multiple zkapp_command transaction *)
let account_state_tbl = Account_id.Table.create () in
let%bind zkapp_command, fee_payer_keypair, keymap, ledger =
zkapp_command_with_ledger ~num_keypairs ~max_account_updates
~max_token_updates ~account_state_tbl ?vk ?failure ()
zkapp_command_with_ledger ?ledger_init_state ~num_keypairs
~max_account_updates ~max_token_updates ~account_state_tbl ?vk ?failure ()
in
let rec go zkapp_command_and_fee_payer_keypairs n =
if n <= 1 then
Expand Down
16 changes: 10 additions & 6 deletions src/lib/staged_ledger/staged_ledger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2818,14 +2818,14 @@ let%test_module "staged ledger tests" =
assert (List.length cmds = num_cmds) ;
return (ledger_init_state, cmds, List.init iters ~f:(Fn.const None))

let gen_zkapps ?failure ~num_zkapps zkapps_per_iter :
let gen_zkapps ?ledger_init_state ?failure ~num_zkapps zkapps_per_iter :
(Ledger.t * User_command.Valid.t list * int option list)
Quickcheck.Generator.t =
let open Quickcheck.Generator.Let_syntax in
let%bind zkapp_command_and_fee_payer_keypairs, ledger =
Mina_generators.User_command_generators
.sequence_zkapp_command_with_ledger ~max_token_updates:1
~length:num_zkapps ~vk ?failure ()
.sequence_zkapp_command_with_ledger ?ledger_init_state
~max_token_updates:1 ~length:num_zkapps ~vk ?failure ()
in
let zkapps =
List.map zkapp_command_and_fee_payer_keypairs ~f:(function
Expand Down Expand Up @@ -2887,7 +2887,8 @@ let%test_module "staged ledger tests" =
let num_zkapps = transaction_capacity * iters in
gen_zkapps ~num_zkapps (List.init iters ~f:(Fn.const None))

let gen_zkapps_below_capacity ?(extra_blocks = false) () :
let gen_zkapps_below_capacity ?ledger_init_state ?(extra_blocks = false) ()
:
(Ledger.t * User_command.Valid.t list * int option list)
Quickcheck.Generator.t =
let open Quickcheck.Generator.Let_syntax in
Expand All @@ -2902,7 +2903,8 @@ let%test_module "staged ledger tests" =
(Int.gen_incl 1 ((transaction_capacity / 2) - 1))
in
let num_zkapps = List.fold zkapps_per_iter ~init:0 ~f:( + ) in
gen_zkapps ~num_zkapps (List.map ~f:Option.some zkapps_per_iter)
gen_zkapps ?ledger_init_state ~num_zkapps
(List.map ~f:Option.some zkapps_per_iter)

(*Same as gen_at_capacity except that the number of iterations[iters] is
the function of [extra_block_count] and is same for all generated values*)
Expand Down Expand Up @@ -2948,10 +2950,12 @@ let%test_module "staged ledger tests" =

let gen_all_user_commands_below_capacity () =
let open Quickcheck.Generator.Let_syntax in
let%bind ledger, zkapps, iters_zkapps = gen_zkapps_below_capacity () in
let%bind ledger_init_state, cmds, iters_signed_commands =
gen_below_capacity ()
in
let%bind ledger, zkapps, iters_zkapps =
gen_zkapps_below_capacity ~ledger_init_state ()
in
Ledger.apply_initial_ledger_state ledger ledger_init_state ;
let iters = iters_zkapps @ iters_signed_commands in
let%map cmds =
Expand Down