Skip to content

Commit b70fe01

Browse files
committed
Merge branch 'develop' into feature/protocol-version-chain-id
2 parents b4330db + 3b87099 commit b70fe01

File tree

23 files changed

+838
-138
lines changed

23 files changed

+838
-138
lines changed

flake.nix

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,20 @@
4848
nixosModules.mina = import ./nix/modules/mina.nix inputs;
4949
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
5050
system = "x86_64-linux";
51-
modules = [
51+
modules = let
52+
PK = "B62qiZfzW27eavtPrnF6DeDSAKEjXuGFdkouC3T5STRa6rrYLiDUP2p";
53+
wallet = {
54+
box_primitive = "xsalsa20poly1305";
55+
ciphertext =
56+
"Dmq1Qd8uNbZRT1NT7zVbn3eubpn9Myx9Je9ZQGTKDxUv4BoPNmZAGox18qVfbbEUSuhT4ZGDt";
57+
nonce = "6pcvpWSLkMi393dT5VSLR6ft56AWKkCYRqJoYia";
58+
pw_primitive = "argon2i";
59+
pwdiff = [ 134217728 6 ];
60+
pwsalt = "ASoBkV3NsY7ZRuxztyPJdmJCiz3R";
61+
};
62+
wallet-file = builtins.toFile "mina-wallet" (builtins.toJSON wallet);
63+
wallet-file-pub = builtins.toFile "mina-wallet-pub" PK;
64+
in [
5265
self.nixosModules.mina
5366
{
5467
boot.isContainer = true;
@@ -57,10 +70,46 @@
5770

5871
services.mina = {
5972
enable = true;
73+
config = {
74+
"ledger" = {
75+
"name" = "mina-demo";
76+
"accounts" = [{
77+
"pk" = PK;
78+
"balance" = "66000";
79+
"sk" = null;
80+
"delegate" = null;
81+
}];
82+
};
83+
};
6084
waitForRpc = false;
6185
external-ip = "0.0.0.0";
62-
extraArgs = [ "--seed" ];
86+
generate-genesis-proof = true;
87+
seed = true;
88+
block-producer-key = "/var/lib/mina/wallets/store/${PK}";
89+
extraArgs = [
90+
"--demo-mode"
91+
"--proof-level"
92+
"none"
93+
"--run-snark-worker"
94+
"B62qjnkjj3zDxhEfxbn1qZhUawVeLsUr2GCzEz8m1MDztiBouNsiMUL"
95+
"-insecure-rest-server"
96+
];
97+
};
98+
99+
systemd.services.mina = {
100+
preStart = ''
101+
printf '{"genesis":{"genesis_state_timestamp":"%s"}}' "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" > /var/lib/mina/daemon.json
102+
'';
103+
environment = {
104+
MINA_TIME_OFFSET = "0";
105+
MINA_PRIVKEY_PASS = "";
106+
};
63107
};
108+
109+
systemd.tmpfiles.rules = [
110+
"C /var/lib/mina/wallets/store/${PK}.pub 700 mina mina - ${wallet-file-pub}"
111+
"C /var/lib/mina/wallets/store/${PK} 700 mina mina - ${wallet-file}"
112+
];
64113
}
65114
];
66115
};

nix/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ directory, which links to a tarball containing the docker image. You
106106
can load the image using `docker load -i result`, then note the tag it
107107
outputs. You can then run Mina from this docker image with `docker run mina:<tag> mina.exe <args>`.
108108

109+
### Demo nixos-container
110+
111+
If you're running NixOS, you can use `nixos-container` to run a demo of mina daemon from your local checkout. To do so, try
112+
113+
```
114+
sudo nixos-container create mina --flake mina
115+
sudo nixos-container start mina
116+
sudo nixos-container root-login mina
117+
```
118+
119+
From there, you can poke the mina daemon, e.g. with `systemctl status mina`.
120+
121+
If you want to update the container to reflect the latest checkout, try
122+
123+
```
124+
sudo nixos-container stop mina
125+
sudo nixos-container update mina --flake mina
126+
sudo nixos-container start mina
127+
```
128+
109129
### direnv
110130

111131
It is considered as a good practice to automatically enter the Nix shell instead of keeping in mind that you need to execute the `nix develop mina` command every time you enter the Mina repo directory.

src/app/archive/archive_lib/load_data.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ let update_of_id pool update_id =
105105
in
106106
let%bind app_state =
107107
let%bind field_id_array =
108-
query_db ~f:(fun db -> Processor.Zkapp_states.load db app_state_id)
108+
query_db ~f:(fun db ->
109+
Processor.Zkapp_states_nullable.load db app_state_id )
109110
in
110111
let field_ids = Array.to_list field_id_array in
111112
let%map field_strs =
@@ -533,7 +534,8 @@ let get_other_party_body ~pool body_id =
533534
let%bind delegate = get_pk delegate_id in
534535
let%bind state =
535536
let%bind field_ids =
536-
query_db ~f:(fun db -> Processor.Zkapp_states.load db state_id)
537+
query_db ~f:(fun db ->
538+
Processor.Zkapp_states_nullable.load db state_id )
537539
in
538540
let%map fields =
539541
Deferred.List.map (Array.to_list field_ids) ~f:(fun id_opt ->
@@ -739,12 +741,10 @@ let get_account_accessed ~pool (account : Processor.Accounts_accessed.t) :
739741
let%bind app_state_ints =
740742
query_db ~f:(fun db -> Processor.Zkapp_states.load db app_state_id)
741743
in
742-
(* for app state, all elements are non-NULL *)
743-
assert (Array.for_all app_state_ints ~f:Option.is_some) ;
744744
let%bind app_state =
745745
let%map field_strs =
746746
Deferred.List.init (Array.length app_state_ints) ~f:(fun ndx ->
747-
let id = Option.value_exn app_state_ints.(ndx) in
747+
let id = app_state_ints.(ndx) in
748748
query_db ~f:(fun db -> Processor.Zkapp_state_data.load db id) )
749749
in
750750
let fields = List.map field_strs ~f:Zkapp_basic.F.of_string in
@@ -781,7 +781,7 @@ let get_account_accessed ~pool (account : Processor.Accounts_accessed.t) :
781781
let%map sequence_state =
782782
let%map field_strs =
783783
Deferred.List.init (Array.length sequence_state_ints) ~f:(fun ndx ->
784-
let id = Option.value_exn app_state_ints.(ndx) in
784+
let id = sequence_state_ints.(ndx) in
785785
query_db ~f:(fun db -> Processor.Zkapp_state_data.load db id) )
786786
in
787787
let fields = List.map field_strs ~f:Zkapp_basic.F.of_string in

src/app/archive/archive_lib/processor.ml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ module Zkapp_state_data_array = struct
273273
id
274274
end
275275

276-
module Zkapp_states = struct
277-
let table_name = "zkapp_states"
276+
module Zkapp_states_nullable = struct
277+
let table_name = "zkapp_states_nullable"
278278

279279
let add_if_doesn't_exist (module Conn : CONNECTION)
280280
(fps : (Pickles.Backend.Tick.Field.t option, 'n) Vector.vec) =
@@ -300,6 +300,31 @@ module Zkapp_states = struct
300300
id
301301
end
302302

303+
module Zkapp_states = struct
304+
let table_name = "zkapp_states"
305+
306+
let add_if_doesn't_exist (module Conn : CONNECTION)
307+
(fps : (Pickles.Backend.Tick.Field.t, 'n) Vector.vec) =
308+
let open Deferred.Result.Let_syntax in
309+
let%bind (element_ids : int array) =
310+
Mina_caqti.deferred_result_list_map (Vector.to_list fps)
311+
~f:(Zkapp_state_data.add_if_doesn't_exist (module Conn))
312+
>>| Array.of_list
313+
in
314+
Mina_caqti.select_insert_into_cols ~select:("id", Caqti_type.int)
315+
~table_name
316+
~cols:([ "element_ids" ], Mina_caqti.array_int_typ)
317+
~tannot:(function "element_ids" -> Some "int[]" | _ -> None)
318+
(module Conn)
319+
element_ids
320+
321+
let load (module Conn : CONNECTION) id =
322+
Conn.find
323+
(Caqti_request.find Caqti_type.int Mina_caqti.array_int_typ
324+
(Mina_caqti.select_cols_from_id ~table_name ~cols:[ "element_ids" ]) )
325+
id
326+
end
327+
303328
module Zkapp_sequence_states = struct
304329
let table_name = "zkapp_sequence_states"
305330

@@ -552,7 +577,7 @@ module Zkapp_updates = struct
552577
let open Deferred.Result.Let_syntax in
553578
let%bind app_state_id =
554579
Vector.map ~f:Zkapp_basic.Set_or_keep.to_option update.app_state
555-
|> Zkapp_states.add_if_doesn't_exist (module Conn)
580+
|> Zkapp_states_nullable.add_if_doesn't_exist (module Conn)
556581
in
557582
let%bind delegate_id =
558583
Mina_caqti.add_if_zkapp_set
@@ -717,7 +742,7 @@ module Zkapp_precondition_account = struct
717742
in
718743
let%bind state_id =
719744
Vector.map ~f:Zkapp_basic.Or_ignore.to_option acct.state
720-
|> Zkapp_states.add_if_doesn't_exist (module Conn)
745+
|> Zkapp_states_nullable.add_if_doesn't_exist (module Conn)
721746
in
722747
let%bind sequence_state_id =
723748
Mina_caqti.add_if_zkapp_check
@@ -2315,7 +2340,6 @@ module Zkapp_account = struct
23152340
: Mina_base.Zkapp_account.t ) =
23162341
zkapp_account
23172342
in
2318-
let app_state = Vector.map app_state ~f:(fun field -> Some field) in
23192343
let%bind app_state_id =
23202344
Zkapp_states.add_if_doesn't_exist (module Conn) app_state
23212345
in

src/app/archive/drop_tables.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ DROP TABLE zkapp_permissions;
6060

6161
DROP TABLE zkapp_state_data_array;
6262

63+
DROP TABLE zkapp_states_nullable;
64+
6365
DROP TABLE zkapp_states;
6466

6567
DROP TABLE zkapp_state_data;

src/app/archive/zkapp_tables.sql

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,24 @@ CREATE TABLE zkapp_state_data_array
4242
Postgresql does not allow enforcing that the array elements are
4343
foreign keys
4444
45-
Any element of the array may be NULL, meaning Ignore, per the
46-
NULL convention
45+
Any element of the array may be NULL, per the NULL convention
46+
*/
47+
CREATE TABLE zkapp_states_nullable
48+
( id serial PRIMARY KEY
49+
, element_ids int[] NOT NULL
50+
);
51+
52+
/* like zkapp_states_nullable, but elements are not NULL (not enforced by Postgresql)
4753
*/
4854
CREATE TABLE zkapp_states
4955
( id serial PRIMARY KEY
5056
, element_ids int[] NOT NULL
5157
);
5258

53-
/* like zkapp_states, but for sequences */
59+
/* like zkapp_states, but for sequence states; width may differ from that table
60+
61+
Elements are not NULL (not enforced by Postgresql)
62+
*/
5463
CREATE TABLE zkapp_sequence_states
5564
( id serial PRIMARY KEY
5665
, element_ids int[] NOT NULL
@@ -104,7 +113,7 @@ CREATE TABLE zkapp_uris
104113
/* NULL convention */
105114
CREATE TABLE zkapp_updates
106115
( id serial PRIMARY KEY
107-
, app_state_id int NOT NULL REFERENCES zkapp_states(id)
116+
, app_state_id int NOT NULL REFERENCES zkapp_states_nullable(id)
108117
, delegate_id int REFERENCES public_keys(id)
109118
, verification_key_id int REFERENCES zkapp_verification_keys(id)
110119
, permissions_id int REFERENCES zkapp_permissions(id)
@@ -135,7 +144,7 @@ CREATE TABLE zkapp_precondition_accounts
135144
, nonce_id int REFERENCES zkapp_nonce_bounds(id)
136145
, receipt_chain_hash text
137146
, delegate_id int REFERENCES public_keys(id)
138-
, state_id int NOT NULL REFERENCES zkapp_states(id)
147+
, state_id int NOT NULL REFERENCES zkapp_states_nullable(id)
139148
, sequence_state_id int REFERENCES zkapp_state_data(id)
140149
, proved_state boolean
141150
, is_new boolean

0 commit comments

Comments
 (0)