Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A local LEZ chain for Logos development. One command starts a sequencer on your machine with 1 second blocks and a funded faucet, and a project file in your repo says what else it needs: programs, a hundred funded test accounts, `logosctl` sessions. A transfer lands in about 2 seconds and a program deploy in about 10, and you never run out of testnet funds.

Keep the public testnet for final checks. Messages and service discovery can stay local too: a project that asks for it gets a messaging hub on `127.0.0.1` instead of the Logos fleets.
Keep the public testnet for final checks. Messages, service discovery and storage can stay local too: a project that asks for them gets a hub on `127.0.0.1` instead of the Logos fleets.

## Install

Expand Down Expand Up @@ -41,7 +41,7 @@ source ~/.logos-devnet/env # LOGOS_DEVNET_SEQUENCER, LOG
| `down` | Stops it. The chain is kept. |
| `reset` | Deletes the chain and starts a new one, every account group funded at genesis. Takes the same options as `up`. |
| `status` | What runs, the chain head, the faucet, programs, account groups, sessions, the messaging hub and local storage. |
| `doctor` | Checks the project file, Docker and the image (or git and cargo with `--native`), whether the chain takes the project's settings, the port, the faucet and, when sessions or the messaging hub need it, `logosctl`, and says how to fix what fails. |
| `doctor` | Checks the project file, Docker and the image (or git and cargo with `--native`), whether the chain takes the project's settings, the `[programs]` files, the port, the hub's ports, the faucet, `curl` for programs from a release and, when sessions or the hub need it, `logosctl`, and says how to fix what fails. |
| `fund <account> [amount]` | Sends lepta from the faucet to a public account, 10B by default. |
| `deploy <name> <bin> [--mutable]` | Deploys a program, from its `.bin` (what `cargo risczero build` makes, not the bare ELF), and adds `LOGOS_PROGRAM_<NAME>` and `LOGOS_PROGRAM_<NAME>_HEX` to the env file. Names are lower-case letters, digits and `-`. With `--mutable`, a new build updates it in place. |
| `wallet-config <dir>` | Writes a `wallet_config.json` pointing at the devnet into a new wallet directory. |
Expand Down Expand Up @@ -270,7 +270,7 @@ With `--json`, a command prints one JSON document and nothing else on stdout. No
| `session ls` | a list of `name`, `running`, `account`, `balance`, `error` |
| `env`, `session env` | an object of variable to value |
| `wallet-config` | `path` |
| `down`, `session rm`, `messaging rm` | `message` |
| `down`, `session rm`, `session restart`, `messaging rm` | `message` |
| `doctor` | `ok`, `checks` (`name`, `ok`, `detail`, `fix`) |

## In CI
Expand Down
12 changes: 10 additions & 2 deletions skills/logos-devnet/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ description: logos-devnet runs a local LEZ (Logos Execution Zone) chain. Use whe

`logos-devnet` runs LEZ's own sequencer on this machine, with 1 s blocks and a faucet funded at genesis. A project describes what it needs in `logos-devnet.toml`, and `up` makes the devnet match it. The README (https://github.com/drptbl/logos-devnet) has every detail, and `logos-devnet <command> --help` every flag.

## Before you start

- **logos-devnet 0.8.0 or newer**: `logos-devnet --version`. Install it with `cargo install --locked logos-devnet`, or a binary from https://github.com/drptbl/logos-devnet/releases/latest (macOS and Linux).
- **Docker**: OrbStack, Docker Desktop or Colima, running. `logos-devnet doctor` says when it isn't.
- **`logosctl`**, the Logos Core CLI, on `PATH`, only for sessions, `[messaging]` and `[storage]`: a release from https://github.com/logos-co/logos-logoscore-cli/releases.
- **LEZ programs** you deploy are built with `cargo risczero build`, which makes the `.bin` the devnet takes.

## The loop

Pass `--json` to every command: on success stdout holds one JSON document, and notes go to stderr. On failure the exit is non-zero, stdout is empty, and the error is on stderr, starting `Error:`.
Expand All @@ -24,7 +31,7 @@ Pass `--json` to every command: on success stdout holds one JSON document, and n
[sessions.alice] # a logosctl session with a funded wallet
```
Program, group and session names are lower-case letters, digits and `-`. A project-local home is state, not source: add `.logos-devnet/` to `.gitignore`.
2. `logos-devnet doctor --json`, from the project's directory so it checks the file's settings. It checks the setup (Docker, the port, the chain), not program builds: `up` does that. Done when `.ok` is true. Each failed check carries a `detail`, and a `fix` when the detail doesn't already say what to do.
2. `logos-devnet doctor --json`, from the project's directory so it checks the file's settings: Docker, the ports, the chain, `logosctl`, and that each `[programs]` file is a built program. Done when `.ok` is true. Each failed check carries a `detail`, and a `fix` when the detail doesn't already say what to do.
3. `logos-devnet up --json`. Done when it exits 0 and `.sequencer.running` is true. It is idempotent, so run it again after any change to the file or a rebuild. When it exits non-zero after starting, the error starts "the devnet is up, but" and names what failed: fix that and run `up` again.
4. `source <(logos-devnet env)`, or read `logos-devnet env --json`. Code and tests read these, so they work on any devnet:
- `LOGOS_DEVNET_SEQUENCER`: the RPC URL.
Expand All @@ -34,7 +41,7 @@ Pass `--json` to every command: on success stdout holds one JSON document, and n
- `LOGOS_DEVNET_SESSION_<NAME>`: a session's `LOGOSCTL_CONFIG_DIR`, with `_WALLET`, `_ACCOUNT` (`Public/<id>`) and `_ACCOUNT_HEX` (what `lez_core` takes), for a test driving several sessions.
- `RISC0_DEV_MODE`: `1` or `0`, matching the chain.
- With `[messaging]`: `LOGOS_DEVNET_DELIVERY_CONFIG`, the `delivery_module.createNode` config of a node that uses the local hub, `LOGOS_DEVNET_DELIVERY_ENTRY_NODE`, `LOGOS_DEVNET_DISCOVERY_BOOTSTRAP`, a `libp2p_module` bootstrap node, and `LOGOS_DEVNET_DISCOVERY_CONFIG`, its node's config.
5. `logos-devnet status --json` shows what runs: chain head, faucet, programs, groups, sessions. `.sequencer.runtime_answered` is false when Docker didn't answer within 10 s: Docker is stuck, so restart it rather than running `up`.
5. `logos-devnet status --json` shows what runs: chain head, faucet, programs, groups, sessions, the hub and storage. `.sequencer.runtime_answered` is false when Docker didn't answer within 10 s: Docker is stuck, so restart it rather than running `up`.
6. Check the chain instead of sleeping:
- `logos-devnet tx --wait <hash>` returns once a block holds the transaction (`lez_core`'s `tx_hash`), with the block in `--json`'s `.block`, and fails after `--timeout` (60 s).
- `logos-devnet account <id>` shows an account's balance, nonce and data. It takes `Public/<id>`, base58, the 64-hex form `lez_core` uses, or a deployed program's name, and prints both forms.
Expand All @@ -49,6 +56,7 @@ Pass `--json` to every command: on success stdout holds one JSON document, and n
- **Funding.** Groups that exist when a chain starts are funded at genesis, at once. A group added to a running chain is funded one transfer at a time, about 2.4 s per account. Every call holds about 1.6M lepta of fees up front, so an account that sends needs more than that. `logos-devnet fund Public/<id> [lepta]` tops one account up.
- **Messaging.** An empty `[messaging]` table runs a local hub: a delivery node and a discovery bootstrap on `127.0.0.1`, so messages and service lookups skip the public fleet. Sessions with `delivery_module` or `libp2p_module` loaded (`chat_module` loads the first) get nodes on the hub from `up`; outside a session, create the app's nodes from `LOGOS_DEVNET_DELIVERY_CONFIG` and `LOGOS_DEVNET_DISCOVERY_CONFIG` first in its daemon: the first `createNode` picks the network. `chat_module` still reaches a public key registry. `status --json` shows whether each hub node runs, in `.messaging.delivery_node` and `.messaging.discovery_node`, and `messaging rm` deletes the hub: a project that asks for one gets a new hub, with new addresses, on its next `up`.
- **Storage.** Each session runs a storage node of its own, on `127.0.0.1` and in no network. An empty `[storage]` table connects the sessions through a node in the hub, so one session downloads by CID what another uploaded. Sessions need nothing passed in.
- **Calling the modules.** To send or receive messages, advertise or look up a service, or upload and download a file from a session, read [modules.md](modules.md): `delivery_module`, `libp2p_module` and `storage_module` take arguments in an order and form their errors don't explain.
- **Sessions** need `logosctl` on `PATH`. `logos-devnet session restart <name>` gives one a fresh daemon in seconds, keeping its wallet: use it where a module keeps state while loaded (libp2p_module 1.1.0 advertises one service per load) instead of `logosctl module reload`. They suit apps that talk to Logos through `logosctl` and `lez_core`. Before calling `lez_core` yourself, read [lez_core.md](lez_core.md): it takes ids and amounts in forms its errors don't explain.

## Reset
Expand Down
5 changes: 3 additions & 2 deletions skills/logos-devnet/lez_core.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ What `lez_core`, the LEZ module in a `logosctl` session, expects. A session's en
- Amounts are 16 little-endian bytes in hex: 1000 lepta is `e8030000000000000000000000000000`.
- Strings take a `str:` prefix. Booleans go bare, as `true` or `false`.
- `get_balance str:<hex> true` reads a public account and `... false` a private one, in lepta. An empty result means the call failed.
- A private balance needs the wallet synced first: `call lez_core sync_to_block <head>`, with the head from the RPC's `getLastBlockId`.
- A transfer returns its `tx_hash` in a JSON string: `| jq -r .result | jq -r .tx_hash`. `logos-devnet tx --wait <hash>` returns once a block holds it, instead of a `sleep`.
- A private balance needs the wallet synced first: `call lez_core sync_to_block <block>`, with the block from `logos-devnet tx --wait --json <hash> | jq .block`.
- `transfer_public str:<from> str:<to> str:<amount>` pays a public account. `transfer_shielded_owned` with the same arguments shields funds into one of the wallet's own private accounts, which `create_account_private` makes. In dev mode its proof takes about a second.

`examples/sessions` in the repo runs these end to end.
https://github.com/drptbl/logos-devnet/tree/main/examples/sessions runs these end to end.
33 changes: 33 additions & 0 deletions skills/logos-devnet/modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Messaging, discovery and storage through logosctl

What `delivery_module`, `libp2p_module` and `storage_module` expect when a session calls them. `source <(logos-devnet session env <name>)` points `logosctl` at a session's daemon; `logos-devnet exec --session <name> -- <command>` does the same for one command.

- Calls answer `{"success": ..., "value": ..., "error": ...}` in the reply's `result`: `logosctl --json call <module> <method> <args> | tail -1 | jq .result`. A call can succeed at the logosctl level and still carry `success: false`.
- Strings take a `str:` prefix. Numbers and booleans go bare.
- Uploads, downloads and received messages finish in the background and arrive as events: `logosctl --json watch <module> > events.log &` before the call, one line of JSON per event.

## Delivery (`[messaging]`)

With `[messaging]`, `up` gives a session that loads `delivery_module` (directly, or through `chat_module`) a node on the hub, started and connected. Don't create another.

- `getConnectionStatus` answers `PartiallyConnected` with the hub as the only peer: that's enough to send.
- `subscribe str:<topic>` listens on a content topic, e.g. `/my-app/1/chat/proto`.
- `send str:<topic> str:<payload>` sends.
- A received message is a `messageReceived` event: `.data.arg1` is the topic, `.data.arg2._bytes` the payload in base64 (`jq -r '.data.arg2._bytes | @base64d'`), and `.data.arg3` is `live`, or `history` when the node caught up from the hub's store.

## Discovery (`[messaging]`)

The session's `libp2p_module` node takes the hub as its only bootstrap node, also from `up`.

- `discoStartAdvertising str:<service> str:<data> str:` advertises a service. libp2p_module 1.1.0 advertises one service per load: `logos-devnet session restart <name>` starts it over.
- `discoRegisterInterest str:<service>`, then `discoLookup str:<service> str:<data>` a few seconds later: `.value` is a list of `{peerId, addrs, services}`.

## Storage (`[storage]`)

Every session's daemon starts its storage node on its own; with `[storage]` the sessions share a network through the hub.

- `uploadUrl str:<absolute path> 65536 true` uploads a file (chunk size, then whether to announce it). The CID comes in the `storageUploadDone` event: `jq -r 'select(.event == "storageUploadDone") | .data.arg0 | fromjson | .cid'`.
- `exists str:<cid>` says whether this node holds it.
- `downloadToUrl str:<cid> str:<absolute path> false 65536 false true` fetches it from the network (local only, chunk size, through Mix, announce). `storageDownloadDone` says when it's written.

https://github.com/drptbl/logos-devnet/tree/main/examples/messaging and https://github.com/drptbl/logos-devnet/tree/main/examples/storage run these end to end.
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ enum Command {
/// Delete the chain and start a new one. Program ids stay the same and every account group
/// is funded at genesis.
Reset(UpOptions),
/// Show what runs, the chain head, the faucet, programs, account groups and sessions.
/// Show what runs, the chain head, the faucet, programs, account groups, sessions, the
/// messaging hub and local storage.
Status,
/// Check what logos-devnet needs, and say how to fix what's missing.
Doctor,
Expand Down
Loading