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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logos-devnet"
version = "0.9.1"
version = "0.9.2"
edition = "2024"
rust-version = "1.89"
description = "A local LEZ chain for Logos development: one command to start it, fund accounts and deploy programs"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cargo install --locked logos-devnet
Or take a binary from the [latest release](https://github.com/drptbl/logos-devnet/releases/latest), built for macOS (`aarch64-apple-darwin`, `x86_64-apple-darwin`) and Linux (`x86_64-unknown-linux-musl`, `aarch64-unknown-linux-musl`, static, so any distribution), and check it against its `.sha256`:

```bash
v=v0.9.1 t=aarch64-apple-darwin
v=v0.9.2 t=aarch64-apple-darwin
curl -fsSL --remote-name-all https://github.com/drptbl/logos-devnet/releases/download/$v/logos-devnet-$v-$t.tar.gz{,.sha256}
shasum -a 256 -c logos-devnet-$v-$t.tar.gz.sha256 \
&& tar -xzf logos-devnet-$v-$t.tar.gz \
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 (and which stopped while the chain runs), 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 `[programs]` files, the port, the hub's ports, the faucet, sessions that stopped while the chain runs, `curl` for programs from a release and, when sessions or the 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, the hub's nodes and sessions that stopped while the chain runs, `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 @@ -279,7 +279,7 @@ With `--json`, a command prints one JSON document and nothing else on stdout. No
The repo is a GitHub Action. On a Linux runner it installs `logos-devnet`, starts the devnet from your project file and exports the env into the job:

```yaml
- uses: drptbl/logos-devnet@v0.9.1
- uses: drptbl/logos-devnet@v0.9.2
with:
args: --max-txs-per-block 100 # optional, more options for up
- run: cargo test # LOGOS_DEVNET_SEQUENCER, LOGOS_PROGRAM_*, LOGOS_DEVNET_ACCOUNTS_*, RISC0_DEV_MODE are set
Expand Down
2 changes: 1 addition & 1 deletion examples/github-actions/devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# Installs logos-devnet, starts the devnet from logos-devnet.toml, and exports its env
# (LOGOS_DEVNET_SEQUENCER, LOGOS_PROGRAM_*, LOGOS_DEVNET_ACCOUNTS_*, RISC0_DEV_MODE).
- id: devnet
uses: drptbl/logos-devnet@v0.9.1
uses: drptbl/logos-devnet@v0.9.2
- run: cargo test
- name: The devnet's logs
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion skills/logos-devnet/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Each refusal changes nothing. `up` prefixes a program's refusal with `program <n
| `port <n> on 127.0.0.1 is taken` | `up --port <free port>`, remembered unless the file sets a fixed `port`. A new project home with `[devnet] port = 0` takes a free one on its first `up`. |
| `sessions and the messaging hub need logosctl` | Install the Logos Core CLI, or remove the sessions and `[messaging]`. |
| `port <n> on 127.0.0.1, which the messaging hub keeps, is taken` | Stop what holds it, or `messaging rm` and `up` for new ports and peer ids. |
| `the session has <module>, not <module@version>` | A session keeps the versions it was made with: `session rm <name>`, then `up` makes it again. |
| `the session has <module> <version>, not <version>` or `its daemon has no <module> package` | A session keeps the versions it was made with: `session rm <name>`, then `up` makes it again. |
| `not a RISC Zero program binary` | Deploy the guest's `.bin` from `cargo risczero build`, not its ELF. |
| `no Docker daemon answers` | Start Docker (OrbStack, Docker Desktop or Colima). |
| `no block within` / `the sequencer stopped while starting` | Read `logos-devnet logs`. |
Expand Down
81 changes: 62 additions & 19 deletions src/devnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub const DEFAULT_FUND: u64 = 10_000_000_000;
const READY_TIMEOUT: Duration = Duration::from_secs(180);
/// How long `status` waits for the runtime to say whether the sequencer runs.
const RUNTIME_CHECK_TIMEOUT: Duration = Duration::from_secs(10);
/// How long `status`, `doctor` and `session ls` wait for a session's daemon to answer: a wedged
/// one would sit out logosctl's 20 s.
const SESSION_CHECK_TIMEOUT: Duration = Duration::from_secs(5);
/// How often wallets poll the devnet for a transaction: a block or two.
const WALLET_POLL_TIMEOUT: &str = "2s";

Expand Down Expand Up @@ -749,17 +752,20 @@ impl Devnet {

/// Restarts each of `names`' daemons, in order, and brings it back as `up` does: a fresh
/// start for modules that keep state while loaded, e.g. `libp2p_module`, which advertises one
/// service per load. Their packages, keys and funded wallets stay. Every name is checked
/// first, so a typo restarts none.
/// service per load. Their packages, keys and funded wallets stay. Every session is checked
/// first, so a typo or a broken one restarts none.
pub fn session_restart(&self, names: &[String]) -> Result<Done> {
// A session that can't come back stays as it is, and so do the others.
let sessions = names
.iter()
.map(|name| self.existing_session(name))
.map(|name| {
let session = self.existing_session(name)?;
session.info()?;
Ok(session)
})
.collect::<Result<Vec<_>>>()?;
self.require_running()?;
for session in &sessions {
// A session that can't come back stays as it is.
session.info()?;
session.logosctl().stop()?;
self.resume_session(session, false)
.with_context(|| format!("restarting session {}", session.name))?;
Expand Down Expand Up @@ -788,7 +794,7 @@ impl Devnet {
fn sessions_not_running(&self) -> Vec<String> {
self.sessions()
.into_iter()
.filter(|s| !s.logosctl().running())
.filter(|s| !s.logosctl().answers_within(SESSION_CHECK_TIMEOUT))
.map(|s| s.name)
.collect()
}
Expand Down Expand Up @@ -997,6 +1003,15 @@ impl Devnet {
})
}

/// The parts of the hub that should run and don't, or `None` when the devnet has no hub or
/// no logosctl to ask it with.
pub fn hub_down(&self) -> Option<Vec<&'static str>> {
let hub = self.hub();
let (messaging, storage) = (hub.runs_messaging(), hub.runs_storage());
((messaging || storage) && session::logosctl_on_path())
.then(|| hub.health().down(messaging, storage))
}

fn storage_status(&self) -> Option<report::Storage> {
let hub = self.hub();
hub.runs_storage().then(|| report::Storage {
Expand Down Expand Up @@ -1106,23 +1121,31 @@ impl Devnet {
let mut info = session.info()?;
let ctl = session.logosctl();
let had = info.modules.clone();
let missing =
session::missing_modules(&mut info.modules, extra, |m| ctl.installed_version(m))?;
// Started only when needed: to ask it what a pin names, or to install. `up` may get
// here before it resumes the session.
let wake = || -> Result<()> {
if session.start_daemon(&ctl, self.settings.dev_mode, &self.session_storage())? {
// A daemon that started now has nothing loaded: bring the session back first.
ctl.resume(
&had,
&session.wallet_config(),
&session.wallet_storage(),
&self.settings.sequencer_url(),
)?;
}
Ok(())
};
let missing = session::missing_modules(&mut info.modules, extra, |m| {
wake()?;
ctl.installed_version(m)
})?;
if info.modules != had {
session.save_info(&info)?;
}
if missing.is_empty() {
return Ok(missing);
}
if session.start_daemon(&ctl, self.settings.dev_mode, &self.session_storage())? {
// A daemon that started now has nothing loaded: bring the session back first.
ctl.resume(
&info.modules,
&session.wallet_config(),
&session.wallet_storage(),
&self.settings.sequencer_url(),
)?;
}
wake()?;
// Recorded one at a time, so a module that fails keeps the ones before it.
for module in &missing {
let one = std::slice::from_ref(module);
Expand All @@ -1132,6 +1155,14 @@ impl Devnet {
session.save_info(&info)?;
ctl.load(one)?;
}
// An install that upgraded what other modules depend on unloads them, and an upgraded
// lez_core comes back with its wallet closed: bring the whole session back.
ctl.resume(
&info.modules,
&session.wallet_config(),
&session.wallet_storage(),
&self.settings.sequencer_url(),
)?;
self.join_hub(&ctl)?;
Ok(missing)
}
Expand Down Expand Up @@ -1176,7 +1207,7 @@ impl Devnet {
let rows = session::list(&self.home.sessions_dir())?
.into_iter()
.map(|session| {
let running = session.logosctl().running();
let running = session.logosctl().answers_within(SESSION_CHECK_TIMEOUT);
match session.info() {
Ok(info) => SessionRow {
balance: chain_up
Expand Down Expand Up @@ -1886,9 +1917,21 @@ mod tests {
let devnet = devnet_in(&dir.path().join("home"));
let err = devnet.session_restart(&["nobody".into()]).unwrap_err();
assert!(err.to_string().contains("no session nobody"), "{err}");
std::fs::create_dir_all(devnet.home.sessions_dir().join("alice")).unwrap();
let alice = devnet.home.sessions_dir().join("alice");
std::fs::create_dir_all(&alice).unwrap();
let info = format!(r#"{{"modules":["lez_core"],"account":"{ID}","funded":1}}"#);
std::fs::write(alice.join("session.json"), info).unwrap();
let err = devnet.session_restart(&["alice".into()]).unwrap_err();
assert!(err.to_string().contains("not running"), "{err}");
// A session that couldn't come back is found before any restarts.
std::fs::create_dir_all(devnet.home.sessions_dir().join("bob")).unwrap();
let err = devnet
.session_restart(&["alice".into(), "bob".into()])
.unwrap_err();
assert!(
format!("{err:#}").contains("session bob is incomplete"),
"{err:#}"
);
// Every name is checked before any session restarts.
let err = devnet
.session_restart(&["alice".into(), "nobody".into()])
Expand Down
17 changes: 17 additions & 0 deletions src/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ pub fn run(devnet: &Devnet, project_error: Option<&anyhow::Error>) -> Doctor {
)
});

// The hub stops with the chain, so like sessions it's only news while the chain runs.
if running && let Some(down) = devnet.hub_down() {
checks.push(if down.is_empty() {
pass("hub", "running")
} else {
fail(
"hub",
format!(
"its {} {} running",
down.join(" and "),
if down.len() == 1 { "isn't" } else { "aren't" }
),
"`logos-devnet up` starts it",
)
});
}

let stopped = devnet.stopped_sessions(running);
if !stopped.is_empty() {
checks.push(fail(
Expand Down
46 changes: 46 additions & 0 deletions src/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ pub struct Health {
pub storage: bool,
}

impl Health {
/// The parts that should run and don't, for a hub that runs messaging, storage or both.
pub fn down(&self, messaging: bool, storage: bool) -> Vec<&'static str> {
if !self.daemon {
return vec!["daemon"];
}
[
(messaging && !self.delivery, "delivery node"),
(messaging && !self.discovery, "discovery node"),
(storage && !self.storage, "storage node"),
]
.into_iter()
.filter_map(|(down, part)| down.then_some(part))
.collect()
}
}

impl Hub {
pub fn new(dir: PathBuf, packages: PathBuf) -> Self {
let ctl = Logosctl::new(dir.join("logosctl"));
Expand Down Expand Up @@ -706,6 +723,35 @@ esac"#
hub
}

#[test]
fn names_the_parts_of_the_hub_that_are_down() {
let all = Health {
daemon: true,
delivery: true,
discovery: true,
storage: true,
};
assert!(all.down(true, true).is_empty());
let no_storage = Health {
storage: false,
..all
};
assert_eq!(no_storage.down(true, true), ["storage node"]);
assert!(
no_storage.down(true, false).is_empty(),
"storage wasn't asked for"
);
let no_discovery = Health {
discovery: false,
..all
};
assert_eq!(no_discovery.down(true, false), ["discovery node"]);
let no_daemon = Health {
daemon: false,
..all
};
assert_eq!(no_daemon.down(true, true), ["daemon"]);
}
#[test]
fn a_storage_hub_records_its_bootstrap_and_runs_no_messaging_nodes() {
let dir = tempfile::tempdir().unwrap();
Expand Down
Loading
Loading