Skip to content

Commit

Permalink
Add tool to list bootstrapped commands
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinOndejka committed May 7, 2024
1 parent f6f2b4b commit 72e723c
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 123 deletions.
4 changes: 2 additions & 2 deletions nix/ocaml.nix
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ let
dune build --display=short \
src/app/zeko/sequencer/run.exe \
src/app/zeko/sequencer/deploy.exe \
src/app/zeko/sequencer/committer.exe \
src/app/zeko/sequencer/cli.exe \
src/app/zeko/sequencer/tests/local_network/run.exe \
src/app/logproc/logproc.exe \
src/app/cli/src/mina.exe \
Expand Down Expand Up @@ -253,7 +253,7 @@ let
cp src/app/swap_bad_balances/swap_bad_balances.exe $archive/bin/mina-swap-bad-balances
cp src/app/zeko/sequencer/run.exe $zeko/bin/zeko-run
cp src/app/zeko/sequencer/deploy.exe $zeko/bin/zeko-deploy
cp src/app/zeko/sequencer/committer.exe $zeko/bin/zeko-committer
cp src/app/zeko/sequencer/cli.exe $zeko/bin/zeko-cli
cp src/app/zeko/sequencer/tests/local_network/run.exe $localnet/bin/mina-localnet
cp -R _doc/_html $out/share/doc/html
# cp src/lib/mina_base/sample_keypairs.json $sample/share/mina
Expand Down
8 changes: 4 additions & 4 deletions src/app/zeko/sequencer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,28 @@ docker run --entrypoint archive_relay \

## Manual commit

In case automatic commit transaction fails and sequencer gets in the unrecoverable state, `committer.exe` can be used to manually resend commit transactions.
In case automatic commit transaction fails and sequencer gets in the unrecoverable state, `cli.exe` can be used to manually resend commit transactions.

To list all available commit transactions:

```bash
export DUNE_PROFILE=devnet
dune exec ./committer.exe -- list
dune exec ./cli.exe -- list
```

To get json of the commit transaction:

```bash
export DUNE_PROFILE=devnet
dune exec ./committer.exe -- get --source <source-ledger-hash> --target <target-ledger-hash>
dune exec ./cli.exe -- get --source <source-ledger-hash> --target <target-ledger-hash>
```

To resend the commit transaction:

```bash
export DUNE_PROFILE=devnet
export MINA_PRIVATE_KEY="base58 signer private key"
dune exec ./committer.exe -- send
dune exec ./cli.exe -- send
--source <source-ledger-hash> \
--target <target-ledger-hash> \
--l1-uri <l1-uri> \
Expand Down
152 changes: 152 additions & 0 deletions src/app/zeko/sequencer/cli.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
open Core
open Async
open Sequencer_lib
open Mina_base

let printf = Core.printf

let print_endline = Core.print_endline

let committer =
let list =
( "commits-list"
, Command.basic ~summary:"List all of the transactions in the database"
(let%map_open.Command db_dir =
flag "--db-dir"
(optional_with_default "db" string)
~doc:"string Directory to store the database"
in
fun () ->
let kvdb = Kvdb.of_dir db_dir in
let indices = Executor.Commits_store.get_index kvdb in
printf "Found %d transactions\n%!" (List.length indices) ;
List.iter indices ~f:(fun (source, target) ->
printf "Source: %s\nTarget: %s\n\n%!"
(Frozen_ledger_hash.to_decimal_string source)
(Frozen_ledger_hash.to_decimal_string target) ) ) )
in

let get =
( "get"
, Command.basic ~summary:"Find the command with the given source and target"
(let%map_open.Command db_dir =
flag "--db-dir"
(optional_with_default "db" string)
~doc:"string Directory to store the database"
and source =
flag "--source" (required string)
~doc:"string The source ledger of the transaction"
and target =
flag "--target" (required string)
~doc:"string The target ledger of the transaction"
in
fun () ->
let kvdb = Kvdb.of_dir db_dir in
match
Executor.Commits_store.get_commit kvdb
~source:(Frozen_ledger_hash.of_decimal_string source)
~target:(Frozen_ledger_hash.of_decimal_string target)
with
| Some commit ->
print_endline
(Yojson.Safe.pretty_to_string @@ Zkapp_command.to_yojson commit)
| None ->
printf "No commit found\n%!" ) )
in
let send =
( "send"
, Command.basic ~summary:"Send a transaction to the sequencer"
(let%map_open.Command db_dir =
flag "--db-dir"
(optional_with_default "db" string)
~doc:"string Directory to store the database"
and l1_uri = flag "--l1-uri" (required string) ~doc:"string L1 URI"
and fee_arg =
flag "--fee" (required int) ~doc:"int The fee amount in nanomina"
and nonce_opt =
flag "--nonce" (optional int)
~doc:"int Will be fetched from the network if not provided"
and source =
flag "--source" (required string)
~doc:"string The source ledger of the transaction"
and target =
flag "--target" (required string)
~doc:"string The target ledger of the transaction"
in
let signer =
Signature_lib.(
Keypair.of_private_key_exn @@ Private_key.of_base58_check_exn
@@ Sys.getenv_exn "MINA_PRIVATE_KEY")
in
let l1_uri : Uri.t Cli_lib.Flag.Types.with_name =
Cli_lib.Flag.Types.{ value = Uri.of_string l1_uri; name = "l1-uri" }
in
let kvdb = Kvdb.of_dir db_dir in
fun () ->
Thread_safe.block_on_async_exn (fun () ->
let command =
Option.value_exn ~message:"No commit found"
@@ Executor.Commits_store.get_commit kvdb
~source:(Frozen_ledger_hash.of_decimal_string source)
~target:(Frozen_ledger_hash.of_decimal_string target)
in
let%bind nonce =
match nonce_opt with
| Some nonce ->
return nonce
| None ->
Sequencer_lib.Gql_client.fetch_nonce l1_uri
(Signature_lib.Public_key.compress signer.public_key)
in
let executor = Executor.create ~nonce ~l1_uri ~signer ~kvdb () in
let command =
Zkapp_command.
{ command with
fee_payer =
{ command.fee_payer with
body =
{ command.fee_payer.body with
fee = Currency.Fee.of_nanomina_int_exn fee_arg
}
}
}
in
Executor.send_zkapp_command executor command ) ) )
in
( "committer"
, Command.group
~summary:"Script to manually send commiting transactions to L1"
[ list; get; send ] )

let da_layer =
let bootstrap_commands =
( "bootstrap-commands"
, Command.basic ~summary:"List commands to be applied when bootstrapping"
(let%map_open.Command target =
flag "--target" (required string)
~doc:"string The target ledger of the transaction (decimal string)"
and da_contract_address =
flag "--da-contract-address" (required string)
~doc:"string The address of the DA contract"
in
fun () ->
Thread_safe.block_on_async_exn (fun () ->
let%bind commands =
Da_layer.get_batches
Da_layer.{ da_contract_address = Some da_contract_address }
~to_:target
in
printf "Found %d commands\n%!" (List.length commands) ;
return
@@ List.iter commands ~f:(fun command ->
printf "%s\n\n%!"
( Yojson.Safe.pretty_to_string
@@ User_command.to_yojson command ) ) ) ) )
in
( "da-layer"
, Command.group ~summary:"Tool to interact with the DA layer of the sequencer"
[ bootstrap_commands ] )

let () =
Command.group ~summary:"Sequencer CLI" [ committer; da_layer ]
|> Command_unix.run
115 changes: 0 additions & 115 deletions src/app/zeko/sequencer/committer.ml

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/zeko/sequencer/dune
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
(modules deploy))

(executable
(name committer)
(name cli)
(libraries
sequencer_lib
;; mina ;;
Expand All @@ -81,4 +81,4 @@
core_unix.command_unix)
(preprocess
(pps ppx_jane))
(modules committer))
(modules cli))

0 comments on commit 72e723c

Please sign in to comment.