Skip to content

Commit

Permalink
Merge pull request #10785 from MinaProtocol/explicit_genesis_configs
Browse files Browse the repository at this point in the history
Explicit genesis configs
  • Loading branch information
QuiteStochastic committed Apr 30, 2022
2 parents b8dcae3 + 09b0ee1 commit 6e281d9
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let g:syntastic_ocaml_checkers=['merlin']
- If you use vscode, you might like these extensions

- [OCaml and Reason IDE](https://marketplace.visualstudio.com/items?itemName=freebroccolo.reasonml)
- [Dune](https://marketplace.visualstudio.com/items?itemName=maelvalais.dune)
- [OCaml Platform](https://marketplace.visualstudio.com/items?itemName=ocamllabs.ocaml-platform)

- If you use emacs, besides the `opam` packages mentioned above, also install `tuareg`, and add the following to your .emacs file:

Expand Down
2 changes: 1 addition & 1 deletion src/app/test_executive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Note: this environment setup assumes that one is a member of o(1) labs and has a

![automated-validation service account "Keys" tab](https://user-images.githubusercontent.com/3465290/112069746-9aaed080-8b29-11eb-83f1-f36876f3ac3d.png)

4) In addition to `GCLOUD_API_KEY` and `GOOGLE_CLOUD_KEYFILE_JSON`, ensure the following other environment variables are also properly set (preferably in in .bashrc or .profile.):
4) In addition to the above mentioned `GCLOUD_API_KEY` and `GOOGLE_CLOUD_KEYFILE_JSON`, ensure the following other environment variables are also properly set (preferably in in .bashrc or .profile.):
- `KUBE_CONFIG_PATH`. this should usually be `~/.kube/config`
- the following AWS related vars, namely: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_DEFAULT_REGION=us-west-2`,
- vars relating to ocaml compilation
Expand Down
129 changes: 87 additions & 42 deletions src/app/test_executive/payments_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,24 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
[ { balance = "1000"; timing = Untimed }
; { balance = "1000"; timing = Untimed }
]
; num_snark_workers =
3
(* this test doesn't need snark workers, however turning it on in this test just to make sure the snark workers function within integration tests *)
; num_snark_workers = 4
; snark_worker_fee = "0.0001"
; work_delay = Some 1
; transaction_capacity =
Some Runtime_config.Proof_keys.Transaction_capacity.small
}

(* Call [f] [n] times in sequence *)
let repeat_seq ~n ~f =
let open Malleable_error.Let_syntax in
let rec go n =
if n = 0 then return ()
else
let%bind () = f () in
go (n - 1)
in
go n

let run network t =
let open Network in
let open Malleable_error.Let_syntax in
Expand Down Expand Up @@ -341,46 +354,78 @@ module Make (Inputs : Intf.Test.Inputs_intf) = struct
(Wait_condition.signed_command_to_be_included_in_frontier
~txn_hash:hash ~node_included_in:(`Node timed_node_c)))
in
section "unable to send payment from timed account using illiquid tokens"
(let amount = Currency.Amount.of_int 25_000_000_000_000 in
let receiver = untimed_node_b in
let%bind () =
section "unable to send payment from timed account using illiquid tokens"
(let amount = Currency.Amount.of_int 25_000_000_000_000 in
let receiver = untimed_node_b in
let%bind receiver_pub_key = Util.pub_key_of_node receiver in
let sender = timed_node_c in
let%bind sender_pub_key = Util.pub_key_of_node sender in
let%bind { total_balance = timed_node_c_total; _ } =
Network.Node.must_get_account_data ~logger timed_node_c
~public_key:sender_pub_key
in
[%log info] "timed_node_c total balance: %s"
(Currency.Balance.to_formatted_string timed_node_c_total) ;
[%log info]
"Attempting to send txn from timed_node_c to untimed_node_a for \
amount of %s"
(Currency.Amount.to_formatted_string amount) ;
(* TODO: refactor this using new [expect] dsl when it's available *)
let open Deferred.Let_syntax in
match%bind
Node.send_payment ~logger sender ~sender_pub_key ~receiver_pub_key
~amount ~fee
with
| Ok _ ->
Malleable_error.soft_error_string ~value:()
"Payment succeeded, but expected it to fail because of a \
minimum balance violation"
| Error error ->
(* expect GraphQL error due to insufficient funds *)
let err_str = Error.to_string_mach error in
let err_str_lowercase = String.lowercase err_str in
if
String.is_substring ~substring:"insufficient_funds"
err_str_lowercase
then (
[%log info] "Got expected insufficient funds error from GraphQL" ;
Malleable_error.return () )
else (
[%log error]
"Payment failed in GraphQL, but for unexpected reason: %s"
err_str ;
Malleable_error.soft_error_format ~value:()
"Payment failed for unexpected reason: %s" err_str ))
in
section
"send out a bunch more txns to fill up the snark ledger, then wait for \
proofs to be emitted"
(let receiver = untimed_node_a in
let%bind receiver_pub_key = Util.pub_key_of_node receiver in
let sender = timed_node_c in
let sender = untimed_node_b in
let%bind sender_pub_key = Util.pub_key_of_node sender in
let%bind { total_balance = timed_node_c_total; _ } =
Network.Node.must_get_account_data ~logger timed_node_c
~public_key:sender_pub_key
let%bind () =
(*
To fill up a `small` transaction capacity with work delay of 1,
there needs to be 12 total txns sent.
Calculation is as follows:
Max number trees in the scan state is
`(transaction_capacity_log+1) * (work_delay+1)`
and for 2^2 transaction capacity and work delay 1 it is
`(2+1)*(1+1)=6`.
Per block there can be 2 transactions included (other two slots would be for a coinbase and fee transfers).
In the initial state of the network, the scan state waits till all the trees are filled before emitting a proof from the first tree.
Hence, 6*2 = 12 transactions untill we get the first snarked ledger.
2 successful txn are sent in the prior course of this test,
so spamming out at least 10 more here will trigger a ledger proof to be emitted *)
repeat_seq ~n:10 ~f:(fun () ->
Network.Node.must_send_payment ~logger sender ~sender_pub_key
~receiver_pub_key ~amount:Currency.Amount.one ~fee
>>| ignore)
in
[%log info] "timed_node_c total balance: %s"
(Currency.Balance.to_formatted_string timed_node_c_total) ;
[%log info]
"Attempting to send txn from timed_node_c to untimed_node_a for \
amount of %s"
(Currency.Amount.to_formatted_string amount) ;
(* TODO: refactor this using new [expect] dsl when it's available *)
let open Deferred.Let_syntax in
match%bind
Node.send_payment ~logger sender ~sender_pub_key ~receiver_pub_key
~amount ~fee
with
| Ok _ ->
Malleable_error.soft_error_string ~value:()
"Payment succeeded, but expected it to fail because of a minimum \
balance violation"
| Error error ->
(* expect GraphQL error due to insufficient funds *)
let err_str = Error.to_string_mach error in
let err_str_lowercase = String.lowercase err_str in
if
String.is_substring ~substring:"insufficient_funds"
err_str_lowercase
then (
[%log info] "Got expected insufficient funds error from GraphQL" ;
Malleable_error.return () )
else (
[%log error]
"Payment failed in GraphQL, but for unexpected reason: %s"
err_str ;
Malleable_error.soft_error_format ~value:()
"Payment failed for unexpected reason: %s" err_str ))
wait_for t
(Wait_condition.ledger_proofs_emitted_since_genesis ~num_proofs:1))
end
12 changes: 6 additions & 6 deletions src/lib/integration_test_cloud_engine/mina_automation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ module Network_config = struct
; log_precomputed_blocks
; snark_worker_fee
; snark_worker_public_key (* ; aux_account_balance *)
; work_delay
; transaction_capacity
} =
test_config
in
Expand Down Expand Up @@ -184,9 +186,9 @@ module Network_config = struct
{ Runtime_config.Proof_keys.level = Some proof_level
; sub_windows_per_window = None
; ledger_depth = None
; work_delay = None
; block_window_duration_ms = None
; transaction_capacity = None
; work_delay
; block_window_duration_ms = Some 120000
; transaction_capacity
; coinbase_amount = None
; supercharged_coinbase_factor = None
; account_creation_fee = None
Expand All @@ -209,9 +211,7 @@ module Network_config = struct
; genesis_state_timestamp =
Some Core.Time.(to_string_abs ~zone:Zone.utc (now ()))
}
; proof =
None
(* was: Some proof_config; TODO: prebake ledger and only set hash *)
; proof = Some proof_config (* TODO: prebake ledger and only set hash *)
; ledger =
Some
{ base = Accounts (bp_accounts @ extra_accounts)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/integration_test_lib/intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ module Dsl = struct
txn_hash:Transaction_hash.t
-> node_included_in:[ `Any_node | `Node of Engine.Network.Node.t ]
-> t

val ledger_proofs_emitted_since_genesis : num_proofs:int -> t
end

module type Util_intf = sig
Expand Down
8 changes: 6 additions & 2 deletions src/lib/integration_test_lib/test_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ type t =
; num_archive_nodes : int
; log_precomputed_blocks : bool
; snark_worker_fee : string
; snark_worker_public_key : string (* ; aux_account_balance : string option *)
; snark_worker_public_key : string
; work_delay : int option
; transaction_capacity :
Runtime_config.Proof_keys.Transaction_capacity.t option
}

let default =
Expand All @@ -53,5 +56,6 @@ let default =
; snark_worker_public_key =
(let pk, _ = (Lazy.force Mina_base.Sample_keypairs.keypairs).(0) in
Signature_lib.Public_key.Compressed.to_string pk)
(* ; aux_account_balance = None *)
; work_delay = None
; transaction_capacity = None
}
16 changes: 16 additions & 0 deletions src/lib/integration_test_lib/wait_condition.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,20 @@ struct
; soft_timeout = Slots soft_timeout_in_slots
; hard_timeout = Slots (soft_timeout_in_slots * 2)
}

let ledger_proofs_emitted_since_genesis ~num_proofs =
let open Network_state in
let check () (state : Network_state.t) =
if state.snarked_ledgers_generated >= num_proofs then Predicate_passed
else Predicate_continuation ()
in
let description =
Printf.sprintf "[%d] snarked_ledgers to be generated since genesis"
num_proofs
in
{ description
; predicate = Network_state_predicate (check (), check)
; soft_timeout = Slots 15
; hard_timeout = Slots 20
}
end
2 changes: 2 additions & 0 deletions src/lib/runtime_config/runtime_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ module Proof_keys = struct
let of_yojson json =
Result.bind ~f:of_json_layout
(Json_layout.Proof_keys.Transaction_capacity.of_yojson json)

let small : t = Log_2 2
end

type t =
Expand Down

0 comments on commit 6e281d9

Please sign in to comment.