diff --git a/README.md b/README.md index 2b1b621..020e932 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 [amount]` | Sends lepta from the faucet to a public account, 10B by default. | | `deploy [--mutable]` | Deploys a program, from its `.bin` (what `cargo risczero build` makes, not the bare ELF), and adds `LOGOS_PROGRAM_` and `LOGOS_PROGRAM__HEX` to the env file. Names are lower-case letters, digits and `-`. With `--mutable`, a new build updates it in place. | | `wallet-config ` | Writes a `wallet_config.json` pointing at the devnet into a new wallet directory. | @@ -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 diff --git a/skills/logos-devnet/SKILL.md b/skills/logos-devnet/SKILL.md index c5ca0ef..637247b 100644 --- a/skills/logos-devnet/SKILL.md +++ b/skills/logos-devnet/SKILL.md @@ -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 --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:`. @@ -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. @@ -34,7 +41,7 @@ Pass `--json` to every command: on success stdout holds one JSON document, and n - `LOGOS_DEVNET_SESSION_`: a session's `LOGOSCTL_CONFIG_DIR`, with `_WALLET`, `_ACCOUNT` (`Public/`) 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 ` 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 ` shows an account's balance, nonce and data. It takes `Public/`, base58, the 64-hex form `lez_core` uses, or a deployed program's name, and prints both forms. @@ -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/ [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 ` 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 diff --git a/skills/logos-devnet/lez_core.md b/skills/logos-devnet/lez_core.md index 51b382b..cb0ae90 100644 --- a/skills/logos-devnet/lez_core.md +++ b/skills/logos-devnet/lez_core.md @@ -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: 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 `, 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 ` returns once a block holds it, instead of a `sleep`. +- A private balance needs the wallet synced first: `call lez_core sync_to_block `, with the block from `logos-devnet tx --wait --json | jq .block`. - `transfer_public str: str: str:` 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. diff --git a/skills/logos-devnet/modules.md b/skills/logos-devnet/modules.md new file mode 100644 index 0000000..a63a15a --- /dev/null +++ b/skills/logos-devnet/modules.md @@ -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 )` points `logosctl` at a session's daemon; `logos-devnet exec --session -- ` does the same for one command. + +- Calls answer `{"success": ..., "value": ..., "error": ...}` in the reply's `result`: `logosctl --json call | 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 > 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:` listens on a content topic, e.g. `/my-app/1/chat/proto`. +- `send str: str:` 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: str: str:` advertises a service. libp2p_module 1.1.0 advertises one service per load: `logos-devnet session restart ` starts it over. +- `discoRegisterInterest str:`, then `discoLookup str: str:` 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: 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:` says whether this node holds it. +- `downloadToUrl str: str: 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. diff --git a/src/main.rs b/src/main.rs index ef721c1..c4a91f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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,