From 318cf61d8a4865957ea622b183cd9ea8090668c6 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:30:52 +0000 Subject: [PATCH 01/28] feat: read the LEZ line from the tag v0.4 changes how the sequencer starts, its config, the wallet's storage and how accounts are funded, so each line gets its own code path, and its own dev wallet and account groups. --- src/devnet.rs | 32 +++++++++++------ src/home.rs | 98 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 89 insertions(+), 41 deletions(-) diff --git a/src/devnet.rs b/src/devnet.rs index 3dc41fa..d00526b 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -271,7 +271,7 @@ impl Devnet { /// Runs the LEZ wallet on the dev wallet. Its config is rewritten first: the wallet would /// otherwise create a default one pointing at the public testnet. fn wallet(&self, args: Vec) -> Result { - let home = self.home.wallet_dir(); + let home = self.wallet_dir(); self.point_wallet_at(&home, &self.runtime.wallet_sequencer_url())?; self.runtime.wallet(&home, args) } @@ -283,6 +283,16 @@ impl Devnet { write_json(&home.join("wallet_config.json"), &wallet_config(sequencer)) } + /// The dev wallet of the chain's LEZ line. + fn wallet_dir(&self) -> PathBuf { + self.home.wallet_dir(self.settings.line()) + } + + /// The account groups of the chain's LEZ line. + fn groups_dir(&self) -> PathBuf { + self.home.groups_dir(self.settings.line()) + } + fn faucet(&self) -> Result<&PublicId> { self.settings .faucet @@ -505,7 +515,7 @@ impl Devnet { /// height. Keys and accounts stay. Every group is tried. fn forget_group_chains(&self) -> Result<()> { let mut failed = Vec::new(); - for group in groups::list(&self.home.groups_dir())? { + for group in groups::list(&self.groups_dir())? { if let Err(e) = group.forget_old_chain() { eprintln!("account group {}: {e:#}", group.name); failed.push(group.name); @@ -530,7 +540,7 @@ impl Devnet { failed.push(format!("session {}", session.name)); } } - for group in groups::list(&self.home.groups_dir())? { + for group in groups::list(&self.groups_dir())? { if let Err(e) = group.mark_new_chain() { eprintln!("account group {}: {e:#}", group.name); failed.push(format!("account group {}", group.name)); @@ -613,7 +623,7 @@ impl Devnet { /// Group `name` with at least `count` accounts, each to be funded with `amount`. Missing /// keys are made in one wallet batch. A group never shrinks: its keys stay. fn make_group(&self, name: &str, count: usize, amount: u64) -> Result { - let group = Group::new(&self.home.groups_dir(), name)?; + let group = Group::new(&self.groups_dir(), name)?; if !group.wallet_dir().exists() { groups::check_group_name(name)?; } @@ -676,7 +686,7 @@ impl Devnet { /// "Never funded" is read from the chain, so spent accounts aren't topped up. fn fund_groups(&self, only: Option<&str>) -> Result<()> { let rpc = self.rpc(); - for group in groups::list(&self.home.groups_dir())? { + for group in groups::list(&self.groups_dir())? { if only.is_some_and(|name| name != group.name) { continue; } @@ -707,7 +717,7 @@ impl Devnet { /// Every account group's accounts with their genesis balance. fn genesis_accounts(&self) -> Result> { let mut accounts = Vec::new(); - for group in groups::list(&self.home.groups_dir())? { + for group in groups::list(&self.groups_dir())? { let info = group.info()?; accounts.extend(info.accounts.into_iter().map(|a| (a.id, info.amount))); } @@ -890,7 +900,7 @@ impl Devnet { messaging: self.hub().addresses(), sessions: BTreeMap::new(), }; - for group in groups::list(&self.home.groups_dir())? { + for group in groups::list(&self.groups_dir())? { env.groups.insert(group.name.clone(), group.manifest()); } // A session still being made has no account yet: it joins the next env file. @@ -1061,7 +1071,7 @@ impl Devnet { } fn group_summaries(&self) -> Result> { - groups::list(&self.home.groups_dir())? + groups::list(&self.groups_dir())? .into_iter() .map(|group| { let info = group.info()?; @@ -2547,7 +2557,7 @@ mod tests { ("admins", "not json"), ("users", crate::wallet_storage::tests::SYNCED_STORAGE), ] { - let group = Group::new(&home.groups_dir(), name).unwrap(); + let group = Group::new(&home.groups_dir(crate::home::LezLine::V03), name).unwrap(); std::fs::create_dir_all(group.wallet_dir()).unwrap(); std::fs::write(group.wallet_storage(), storage).unwrap(); group.mark_new_chain().unwrap(); @@ -2900,11 +2910,11 @@ mod tests { } #[test] - fn up_refuses_a_lez_tag_outside_v0_3_before_saving_anything() { + fn up_refuses_a_lez_tag_outside_v0_3_and_v0_4_before_saving_anything() { let dir = tempfile::tempdir().unwrap(); let home = Home::locate(Some(dir.path().into())).unwrap(); let opts = UpOptions { - lez: Some("v0.4.0-rc3".into()), + lez: Some("v0.5.0".into()), ..UpOptions::default() }; let err = Devnet::open(home.clone(), None) diff --git a/src/home.rs b/src/home.rs index 753b6ac..be271c4 100644 --- a/src/home.rs +++ b/src/home.rs @@ -36,21 +36,38 @@ pub const DEFAULT_MAX_TXS_PER_BLOCK: u32 = 20; /// The sequencer's log filter (`RUST_LOG`): its own progress, without its actor framework's. pub const DEFAULT_LOG_FILTER: &str = "info,kameo=warn"; -/// A LEZ tag logos-devnet runs: one of the v0.3 line, e.g. `v0.3.1`. LEZ v0.4 changes the -/// sequencer's config and commands, the wallet's format and how accounts are funded. -pub fn check_lez(tag: &str) -> Result<()> { - let patch = tag.strip_prefix("v0.3.").unwrap_or_default(); - let numbered = patch - .split(['-', '.']) - .next() - .is_some_and(|n| !n.is_empty() && n.bytes().all(|b| b.is_ascii_digit())); - if !numbered { - anyhow::bail!( - "logos-devnet runs LEZ v0.3 tags, and {tag} isn't one: use `--lez {DEFAULT_LEZ}` or \ - another v0.3 tag. LEZ v0.4 changes the sequencer and wallet, and isn't supported yet" - ); +/// The LEZ release line a tag belongs to. v0.4 changes how the sequencer starts, its config, +/// the wallet's storage and how accounts are funded, so each line has its own code path. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum LezLine { + V03, + V04, +} + +impl LezLine { + /// The line of `tag`, e.g. `v0.3.1` or `v0.4.0-rc3`. + pub fn of(tag: &str) -> Result { + let numbered = |prefix: &str| { + tag.strip_prefix(prefix) + .and_then(|patch| patch.split(['-', '.']).next()) + .is_some_and(|n| !n.is_empty() && n.bytes().all(|b| b.is_ascii_digit())) + }; + if numbered("v0.3.") { + Ok(Self::V03) + } else if numbered("v0.4.") { + Ok(Self::V04) + } else { + anyhow::bail!( + "logos-devnet runs LEZ v0.3 and v0.4 tags, and {tag} isn't one: use \ + `--lez {DEFAULT_LEZ}`, or a v0.4 tag such as `v0.4.0-rc3`" + ) + } } - Ok(()) +} + +/// A LEZ tag logos-devnet runs: one of the v0.3 or v0.4 line. +pub fn check_lez(tag: &str) -> Result<()> { + LezLine::of(tag).map(drop) } /// A log filter the sequencer takes: `RUST_LOG` syntax, e.g. `debug` or @@ -115,6 +132,12 @@ fn default_log_filter() -> String { } impl Settings { + /// The LEZ line the settings' tag belongs to. `up` checks the tag before it saves one, so + /// a tag from no line, in a hand-edited file, reads as v0.3. + pub fn line(&self) -> LezLine { + LezLine::of(&self.lez).unwrap_or(LezLine::V03) + } + pub fn image(&self) -> String { format!("{IMAGE_REPO}:{}", self.lez) } @@ -225,8 +248,13 @@ impl Home { let value = crate::envfile::dev_mode_value(dev_mode); std::fs::write(&file, value).with_context(|| format!("writing {}", file.display())) } - pub fn wallet_dir(&self) -> PathBuf { - self.root.join("wallet") + /// The dev wallet: the faucet and each program's header key. A v0.4 wallet can't read + /// v0.3 storage, so each LEZ line has its own, and its own program ids. + pub fn wallet_dir(&self, line: LezLine) -> PathBuf { + self.root.join(match line { + LezLine::V03 => "wallet", + LezLine::V04 => "wallet-v0.4", + }) } pub fn compose_file(&self) -> PathBuf { self.root.join("compose.yaml") @@ -237,8 +265,12 @@ impl Home { pub fn sessions_dir(&self) -> PathBuf { self.root.join("sessions") } - pub fn groups_dir(&self) -> PathBuf { - self.root.join("accounts") + /// Account groups, each with a wallet: one set per LEZ line, like the dev wallet. + pub fn groups_dir(&self, line: LezLine) -> PathBuf { + self.root.join(match line { + LezLine::V03 => "accounts", + LezLine::V04 => "accounts-v0.4", + }) } /// Program binaries downloaded from a URL, named by their SHA-256. pub fn downloads_dir(&self) -> PathBuf { @@ -365,22 +397,28 @@ mod tests { use super::*; #[test] - fn runs_only_lez_v0_3_tags() { + fn runs_lez_v0_3_and_v0_4_tags() { for tag in ["v0.3.1", "v0.3.2", "v0.3.10", "v0.3.2-rc1"] { - assert!(check_lez(tag).is_ok(), "{tag}"); + assert_eq!(LezLine::of(tag).unwrap(), LezLine::V03, "{tag}"); } - for tag in [ - "v0.4.0-rc3", - "v0.4.0", - "v0.3", - "v0.3.", - "v0.3.x", - "0.3.1", - "main", - ] { + for tag in ["v0.4.0-rc3", "v0.4.0", "v0.4.12"] { + assert_eq!(LezLine::of(tag).unwrap(), LezLine::V04, "{tag}"); + } + for tag in ["v0.5.0", "v0.3", "v0.4.", "v0.3.x", "0.3.1", "main"] { assert!(check_lez(tag).is_err(), "{tag}"); } - assert!(check_lez(DEFAULT_LEZ).is_ok()); + assert_eq!(LezLine::of(DEFAULT_LEZ).unwrap(), LezLine::V03); + } + + #[test] + fn each_lez_line_keeps_its_own_wallets() { + let dir = tempfile::tempdir().unwrap(); + let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); + // A v0.4 wallet can't read v0.3 storage, so a v0.4 chain starts its own. + assert_eq!(home.wallet_dir(LezLine::V03), home.root().join("wallet")); + assert_eq!(home.groups_dir(LezLine::V03), home.root().join("accounts")); + assert_eq!(home.wallet_dir(LezLine::V04), home.root().join("wallet-v0.4")); + assert_eq!(home.groups_dir(LezLine::V04), home.root().join("accounts-v0.4")); } #[test] From ebe003bf99759546abf936cc8e9ee057ec9bed82 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:30:56 +0000 Subject: [PATCH 02/28] build: find the v0.4 upstream config --- docker/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5cee107..288f685 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -30,9 +30,10 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \ && mkdir -p /out \ && cp target/release/sequencer_service target/release/wallet /out/ \ && strip /out/sequencer_service /out/wallet -# Upstream's debug config for this tag; the CLI patches it rather than shipping its own. +# Upstream's local config for this tag; the CLI patches it rather than shipping its own. LEZ +# v0.3 keeps it in `configs/debug/`, v0.4 as `networks/local.json`. RUN mkdir -p /out/share \ - && config="$(find . -path ./target -prune -o -path '*sequencer/service/configs/debug/sequencer_config.json' -print | head -1)" \ + && config="$(find . -path ./target -prune -o \( -path '*sequencer/service/configs/debug/sequencer_config.json' -o -path '*sequencer/service/networks/local.json' \) -print | head -1)" \ && test -n "$config" \ && cp "$config" /out/share/sequencer_config.json From f141fc7cb60477e0a2311b6b913d640d1295fe63 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:34:39 +0000 Subject: [PATCH 03/28] feat: fund a v0.4 genesis by public key A v0.4 genesis names each funded account by its public key, so the faucet's key is kept when the wallet makes it, and each group account's key is derived from the secret logos-devnet imports, checked against the id the wallet reports. --- Cargo.lock | 127 ++++++++++++++++++++++- Cargo.toml | 1 + src/account.rs | 77 +++++++++++--- src/chain_config.rs | 244 +++++++++++++++++++++++++++++++++++++------- src/devnet.rs | 98 ++++++++++++++---- src/groups.rs | 35 +++++-- src/home.rs | 15 ++- 7 files changed, 512 insertions(+), 85 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02668d0..ef8cc90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,12 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.23.1" @@ -146,6 +152,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const-oid" version = "0.10.3" @@ -190,6 +202,18 @@ dependencies = [ "libc", ] +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.2.2" @@ -199,6 +223,16 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid 0.9.6", + "zeroize", +] + [[package]] name = "deranged" version = "0.5.9" @@ -212,7 +246,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer", - "const-oid", + "const-oid 0.10.3", "crypto-common", ] @@ -236,6 +270,23 @@ dependencies = [ "litrs", ] +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "ff", + "generic-array", + "group", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "equivalent" version = "1.0.3" @@ -258,6 +309,16 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "ff" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "rand_core", + "subtle", +] + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -267,6 +328,17 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "generic-array" +version = "0.14.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -278,6 +350,17 @@ dependencies = [ "r-efi", ] +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + [[package]] name = "hashbrown" version = "0.17.1" @@ -441,6 +524,16 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" +[[package]] +name = "k256" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" +dependencies = [ + "cfg-if", + "elliptic-curve", +] + [[package]] name = "libc" version = "0.2.191" @@ -478,6 +571,7 @@ dependencies = [ "anyhow", "bs58", "clap", + "k256", "serde", "serde_json", "sha2", @@ -555,6 +649,12 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + [[package]] name = "rustix" version = "1.1.6" @@ -568,6 +668,19 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] + [[package]] name = "serde" version = "1.0.229" @@ -649,6 +762,12 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "3.0.10" @@ -925,6 +1044,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa" + [[package]] name = "zerotrie" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index 8e5d997..4087c3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ path = "src/main.rs" anyhow = "1.0.104" bs58 = "0.5.1" clap = { version = "4.6.7", features = ["derive", "env"] } +k256 = { version = "0.13.4", default-features = false, features = ["arithmetic"] } serde = { version = "1.0.229", features = ["derive"] } serde_json = { version = "1.0.154", features = ["raw_value"] } sha2 = "0.11.1" diff --git a/src/account.rs b/src/account.rs index 49a6c82..660d782 100644 --- a/src/account.rs +++ b/src/account.rs @@ -1,7 +1,7 @@ //! Public account ids as the LEZ wallet prints and takes them: 32 bytes in base58, optionally //! prefixed `Public/`. -use anyhow::{Result, bail}; +use anyhow::{Context, Result, bail}; use serde::{Deserialize, Serialize}; /// A public account id, validated as 32 bytes of base58. Stored as bare base58. @@ -40,21 +40,28 @@ impl PublicId { /// From 64 hex characters, the form `lez_core` returns. pub fn from_hex(hex: &str) -> Result { - let bytes = (0..hex.len()) - .step_by(2) - .map(|i| { - hex.get(i..i + 2) - .and_then(|b| u8::from_str_radix(b, 16).ok()) - }) - .collect::>>(); - match bytes { - Some(bytes) if bytes.len() == 32 && hex.len() == 64 => { - Ok(Self(bs58::encode(bytes).into_string())) - } - _ => bail!("{hex} is not an account id (64 hex characters)"), + match hex32(hex) { + Some(bytes) => Ok(Self(bs58::encode(bytes).into_string())), + None => bail!("{hex} is not an account id (64 hex characters)"), } } + /// The public account `key` (64 hex digits, as `public_key_of` gives it) controls: the + /// SHA-256 of LEZ's public account prefix and the key, the same on v0.3 and v0.4. + pub fn of_key(key: &str) -> Result { + use sha2::{Digest, Sha256}; + const PREFIX: &[u8; 32] = b"/LEE/v0.3/AccountId/Public/\x00\x00\x00\x00\x00"; + let Some(key) = hex32(key) else { + bail!("{key} is not a public key (64 hex characters)"); + }; + let id: [u8; 32] = Sha256::new() + .chain_update(PREFIX) + .chain_update(key) + .finalize() + .into(); + Ok(Self(bs58::encode(id).into_string())) + } + /// The bare base58 id. pub fn as_str(&self) -> &str { &self.0 @@ -74,6 +81,31 @@ impl PublicId { } } +/// The public key of `secret` (64 hex digits) as LEZ writes it: the x coordinate of its +/// secp256k1 public key, in hex. What a LEZ v0.4 genesis and `send --to-pk` take. +pub fn public_key_of(secret: &str) -> Result { + use k256::elliptic_curve::sec1::ToEncodedPoint; + let bytes = hex32(secret).context("a private key is 64 hex characters")?; + let secret = k256::SecretKey::from_bytes(&bytes.into()) + .ok() + .context("not a valid private key")?; + let point = secret.public_key().to_encoded_point(false); + let x = point.x().context("the public key has no x coordinate")?; + Ok(x.iter().map(|b| format!("{b:02x}")).collect()) +} + +/// 32 bytes from 64 hex characters. +fn hex32(text: &str) -> Option<[u8; 32]> { + if text.len() != 64 { + return None; + } + let bytes = (0..64) + .step_by(2) + .map(|i| u8::from_str_radix(text.get(i..i + 2)?, 16).ok()) + .collect::>>()?; + bytes.try_into().ok() +} + /// The first `Public/` in wallet output, e.g. from /// `Generated new account with account_id Public/ at path /0`. pub fn first_public_id(output: &str) -> Option { @@ -87,6 +119,25 @@ pub fn first_public_id(output: &str) -> Option { mod tests { use super::*; + #[test] + fn derives_a_public_key_and_its_account_id_as_the_wallet_does() { + // From LEZ v0.3.1's wallet: `account import public --private-key 0101…01`, and + // `account new public`, which prints the key it made. + let secret = "01".repeat(32); + let key = public_key_of(&secret).unwrap(); + assert_eq!( + PublicId::of_key(&key).unwrap().as_str(), + "B1UN3hPgxacgHKBRoThcAmsPajGcUf6YXUhgB36x4DAd" + ); + let made = "4afc5da3b6acabc4892dddb1e49226599326ae3a6a700828e395b5bc9a4b30ba"; + assert_eq!( + PublicId::of_key(made).unwrap().as_str(), + "23cbN9uZbLU1zhcuiZ1qu1eneL8ed8HeHzDEF1br6rEd" + ); + assert!(public_key_of("zz").is_err()); + assert!(PublicId::of_key("abc").is_err()); + } + // A real account id from the LEZ testnet, in base58 and in hex. const SAMPLE_ID: &str = "HpavNGFYxjyhLsy171aXsvv146yUeXmRWiho22uvT43d"; const SAMPLE_HEX: &str = "f9eba477278c918fadafbcb4a6463e947d0fd8de344b5431ee0aa3cd41d7e3a4"; diff --git a/src/chain_config.rs b/src/chain_config.rs index 7469a62..e979633 100644 --- a/src/chain_config.rs +++ b/src/chain_config.rs @@ -1,26 +1,38 @@ -//! The sequencer config a devnet runs on: upstream's own debug config for the pinned LEZ tag, -//! with our chain home, block interval and faucet. Patching upstream's file rather than shipping -//! our own keeps every field a newer tag adds. +//! The sequencer config a devnet runs on: upstream's own local config for the pinned LEZ tag +//! (`configs/debug/sequencer_config.json` on v0.3, `networks/local.json` on v0.4), with our +//! chain home, block interval and faucet. Patching upstream's file rather than shipping our own +//! keeps every field a newer tag adds. use anyhow::{Context, Result, bail}; -use serde_json::{Value, json}; +use serde_json::{Map, Value, json}; use crate::account::PublicId; +use crate::home::LezLine; -/// What a devnet changes in upstream's debug config. +/// What a devnet changes in upstream's config. pub struct ChainOptions<'a> { /// Where the sequencer keeps its database and keys, as the sequencer sees the path. pub home: &'a str, /// Block interval, in the sequencer's humantime format (`1s`, `500ms`). pub block_time: &'a str, /// The faucet, funded at genesis. - pub faucet: &'a PublicId, - /// The faucet's genesis balance in lepta. - pub faucet_balance: u64, + pub faucet: &'a Funded, /// The most user transactions a block takes. pub max_txs_per_block: u32, - /// More accounts to fund at genesis, with their balances. - pub genesis_accounts: &'a [(PublicId, u64)], + /// More accounts to fund at genesis. + pub genesis_accounts: &'a [Funded], + /// Keep upstream's own genesis accounts, whose keys are published, funded too: tools such + /// as LEZ's examples fund themselves from them. + pub keep_upstream_accounts: bool, +} + +/// An account funded at genesis. v0.3 names it by id, v0.4 by its public key. +pub struct Funded { + pub id: PublicId, + /// Its public key, as 64 hex digits: what a v0.4 genesis funds. + pub key: Option, + /// Lepta. + pub balance: u64, } /// The bounds `max_txs_per_block` must fall in: upstream's mempool holds 1000 transactions. @@ -37,10 +49,11 @@ pub fn check_max_txs_per_block(max: u32) -> Result<()> { Ok(()) } -/// Returns `debug` with `opts` applied. The faucet is the only funded account: upstream's -/// supply accounts have published keys. -pub fn patch(mut debug: Value, opts: &ChainOptions) -> Result { - let config = debug +/// Returns upstream's config with `opts` applied, in `line`'s schema. Unless the options keep +/// them, the faucet and the given accounts are the only ones funded: upstream's supply accounts +/// have published keys. +pub fn patch(line: LezLine, mut upstream: Value, opts: &ChainOptions) -> Result { + let config = upstream .as_object_mut() .context("the upstream sequencer config is not a JSON object")?; config.insert("home".into(), json!(opts.home)); @@ -48,29 +61,65 @@ pub fn patch(mut debug: Value, opts: &ChainOptions) -> Result { check_max_txs_per_block(opts.max_txs_per_block)?; config.insert("max_num_tx_in_block".into(), json!(opts.max_txs_per_block)); // Both would listen on every interface: metrics on 9000 and gossip on a UDP port. A single - // devnet sequencer needs neither. - config.insert("metrics_address".into(), Value::Null); + // devnet sequencer needs neither. v0.4 refuses fields it doesn't know, and renamed one. + let metrics = match line { + LezLine::V03 => "metrics_address", + LezLine::V04 => "metrics_listen_address", + }; + config.insert(metrics.into(), Value::Null); config.insert("gossip".into(), Value::Null); - let genesis = config - .entry("genesis") - .or_insert_with(|| json!([])) - .as_array_mut() - .context("the upstream config's `genesis` is not a list")?; - genesis.retain(|action| action.get("supply_account").is_none()); - genesis.push(json!({ - "supply_account": { "account_id": opts.faucet.as_str(), "balance": opts.faucet_balance } - })); - for (account, balance) in opts.genesis_accounts { - genesis.push(json!({ - "supply_account": { "account_id": account.as_str(), "balance": balance } - })); + let funded = std::iter::once(opts.faucet).chain(opts.genesis_accounts); + let posting_timeout = match line { + LezLine::V03 => { + let genesis = config + .entry("genesis") + .or_insert_with(|| json!([])) + .as_array_mut() + .context("the upstream config's `genesis` is not a list")?; + if !opts.keep_upstream_accounts { + genesis.retain(|action| action.get("supply_account").is_none()); + } + for account in funded { + genesis.push(json!({ + "supply_account": { "account_id": account.id.as_str(), "balance": account.balance } + })); + } + config.get("bedrock_config").map(|b| &b["channel_params"]) + } + LezLine::V04 => { + let genesis = config + .get_mut("genesis") + .and_then(Value::as_object_mut) + .context("the upstream config's `genesis` is not an object")?; + let actions = actions(genesis)?; + if !opts.keep_upstream_accounts { + actions.retain(|action| { + action.get("supply_account").is_none() + && action.get("supply_private_account").is_none() + }); + } + for account in funded { + let key = account.key.as_deref().with_context(|| { + format!( + "{} has no public key on record, and a LEZ v0.4 genesis funds by key", + account.id.wallet_form() + ) + })?; + actions.push(json!({ + "supply_account": { + "recipient": { "identified": { "key": key } }, + "balance": account.balance + } + })); + } + config.get("genesis").map(|g| &g["channel_params"]) + } } + .and_then(|params| params["posting_timeout"].as_u64()); let block_secs = block_time_secs(opts.block_time)?; - if let Some(timeout) = config - .get("bedrock_config") - .and_then(|b| b["channel_params"]["posting_timeout"].as_u64()) + if let Some(timeout) = posting_timeout && block_secs >= timeout as f64 { bail!( @@ -78,7 +127,16 @@ pub fn patch(mut debug: Value, opts: &ChainOptions) -> Result { opts.block_time ); } - Ok(debug) + Ok(upstream) +} + +/// A v0.4 genesis's `actions`. +fn actions(genesis: &mut Map) -> Result<&mut Vec> { + genesis + .entry("actions") + .or_insert_with(|| json!([])) + .as_array_mut() + .context("the upstream config's `genesis.actions` is not a list") } /// Seconds in a `1s` / `500ms` / `2m` block time: the forms the sequencer's humantime config @@ -106,6 +164,7 @@ pub fn block_time_secs(text: &str) -> Result { #[cfg(test)] mod tests { use super::*; + use crate::home::LezLine; fn upstream() -> Value { json!({ @@ -125,17 +184,26 @@ mod tests { const USER: &str = "6YvesSEDWW25kpi8SSki2c8o5m3uACsigvGnNQ6wMruh"; fn patched_with(block_time: &str, max_txs_per_block: u32) -> Result { - let faucet = PublicId::parse(FAUCET).unwrap(); - let users = [(PublicId::parse(USER).unwrap(), 7)]; + let faucet = Funded { + id: PublicId::parse(FAUCET).unwrap(), + key: None, + balance: 1_000, + }; + let users = [Funded { + id: PublicId::parse(USER).unwrap(), + key: None, + balance: 7, + }]; patch( + LezLine::V03, upstream(), &ChainOptions { home: "/devnet/chain", block_time, faucet: &faucet, - faucet_balance: 1_000, max_txs_per_block, genesis_accounts: &users, + keep_upstream_accounts: false, }, ) } @@ -181,6 +249,110 @@ mod tests { assert!(patched("500ms").is_ok()); } + /// LEZ v0.4.0-rc3's `networks/local.json`, cut down. + fn upstream_v04() -> Value { + json!({ + "home": ".", + "max_num_tx_in_block": 20, + "block_create_timeout": "15s", + "bedrock_config": { "channel_id": "0101", "node_url": "http://localhost:18080" }, + "genesis": { + "channel_params": { "posting_timeout": 25, "exit_delay": 100 }, + "actions": [ + { "supply_account": { "recipient": { "identified": { "key": "aa" } }, "balance": 1 } }, + { "supply_private_account": { "address": "Priv", "balance": 2 } }, + { "stake_sequencer": { "sequencer_key": "k" } } + ] + }, + "gossip": { "listen_addr": "/ip4/0.0.0.0/udp/0/quic-v1", "bootstrap_peers": [] } + }) + } + + const FAUCET_KEY: &str = "6aa4c365699b89d963ef85a59868b9612b6001f90750b4970662a62776332e81"; + + fn patched_v04(user_key: Option<&str>, keep_upstream_accounts: bool) -> Result { + let faucet = Funded { + id: PublicId::parse(FAUCET).unwrap(), + key: Some(FAUCET_KEY.into()), + balance: 1_000, + }; + let users = [Funded { + id: PublicId::parse(USER).unwrap(), + key: user_key.map(str::to_owned), + balance: 7, + }]; + patch( + LezLine::V04, + upstream_v04(), + &ChainOptions { + home: "/devnet/chain", + block_time: "1s", + faucet: &faucet, + max_txs_per_block: 50, + genesis_accounts: &users, + keep_upstream_accounts, + }, + ) + } + + #[test] + fn a_v0_4_config_runs_alone_and_keeps_the_tags_channel() { + let out = patched_v04(Some("bb"), false).unwrap(); + assert_eq!(out["home"], "/devnet/chain"); + assert_eq!(out["block_create_timeout"], "1s"); + assert_eq!(out["max_num_tx_in_block"], 50); + // v0.4 refuses unknown fields: `metrics_address` would fail the whole config. + assert!(out["metrics_listen_address"].is_null()); + assert!(out.get("metrics_address").is_none()); + assert!(out["gossip"].is_null()); + // rc3 needs `exit_delay`, later tags `finality_depth`: the tag's own params stay. + assert_eq!(out["genesis"]["channel_params"]["exit_delay"], 100); + } + + #[test] + fn a_v0_4_genesis_funds_by_public_key() { + let out = patched_v04(Some("bb"), false).unwrap(); + let funded = |key: &str, balance: u64| json!({ "supply_account": { "recipient": { "identified": { "key": key } }, "balance": balance } }); + assert_eq!( + out["genesis"]["actions"].as_array().unwrap(), + &vec![ + json!({ "stake_sequencer": { "sequencer_key": "k" } }), + funded(FAUCET_KEY, 1000), + funded("bb", 7), + ] + ); + let err = patched_v04(None, false).unwrap_err(); + assert!(format!("{err:#}").contains(USER), "{err:#}"); + } + + #[test] + fn a_v0_4_genesis_can_keep_upstreams_published_accounts() { + let out = patched_v04(Some("bb"), true).unwrap(); + let actions = out["genesis"]["actions"].as_array().unwrap(); + assert_eq!(actions.len(), 5, "{actions:?}"); + assert!(actions[1].get("supply_private_account").is_some()); + } + + #[test] + fn a_v0_4_block_time_stays_under_the_posting_timeout() { + let mut upstream = upstream_v04(); + upstream["genesis"]["channel_params"]["posting_timeout"] = json!(1); + let faucet = Funded { + id: PublicId::parse(FAUCET).unwrap(), + key: Some(FAUCET_KEY.into()), + balance: 1, + }; + let opts = ChainOptions { + home: "/devnet/chain", + block_time: "1s", + faucet: &faucet, + max_txs_per_block: 20, + genesis_accounts: &[], + keep_upstream_accounts: false, + }; + assert!(patch(LezLine::V04, upstream, &opts).is_err()); + } + #[test] fn refuses_malformed_block_times() { for bad in ["1", "s", "1h", "0s", ""] { diff --git a/src/devnet.rs b/src/devnet.rs index d00526b..34bb1be 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -11,7 +11,7 @@ use std::collections::BTreeMap; use crate::account::{PublicId, first_public_id}; use crate::binary; -use crate::chain_config::{self, ChainOptions}; +use crate::chain_config::{self, ChainOptions, Funded}; use crate::envfile::{self, Env}; use crate::fetch; use crate::groups::{self, Group, GroupInfo}; @@ -360,7 +360,7 @@ impl Devnet { } next.runtime.prepare(opts.rebuild)?; - let faucet = next.dev_faucet()?; + let (faucet, faucet_key) = next.dev_faucet()?; if continuing && funds_another_faucet(self.settings.faucet.as_ref(), &faucet) { bail!( "this chain's genesis funds another faucet than the dev wallet holds. \ @@ -368,6 +368,7 @@ impl Devnet { ); } next.settings.faucet = Some(faucet); + next.settings.faucet_key = faucet_key; // Keys first, so a new chain funds every group at genesis. next.make_project_groups()?; let config = next.chain_config()?; @@ -657,24 +658,39 @@ impl Devnet { // chunks, saving after each: a batch is one shell argument, and a long one fails. while info.accounts.len() < count { let missing = (count - info.accounts.len()).min(BATCH_CHUNK); - let runs = (0..missing) - .map(|_| { - Ok(vec![ + let secrets = (0..missing) + .map(|_| random_key()) + .collect::>>()?; + let runs: Vec> = secrets + .iter() + .map(|secret| { + vec![ "account".into(), "import".into(), "public".into(), "--private-key".into(), - random_key()?, - ]) + secret.clone(), + ] }) - .collect::>>>()?; - let ids = self - .runtime - .wallet_batch(&wallet, &runs)? + .collect(); + let outputs = self.runtime.wallet_batch(&wallet, &runs)?; + let accounts = secrets .iter() - .map(|out| first_public_id(out).context("the wallet made no account")) + .zip(&outputs) + .map(|(secret, out)| { + let id = first_public_id(out).context("the wallet made no account")?; + let key = crate::account::public_key_of(secret)?; + // A key that names another account would fund the wrong one at genesis. + if PublicId::of_key(&key)? != id { + bail!( + "the wallet made {} from a key that names another", + id.wallet_form() + ); + } + Ok((id, key)) + }) .collect::>>()?; - info = Group::extended(info, ids); + info = Group::extended(info, accounts); group.save_info(&info)?; } group.save_info(&info)?; @@ -715,11 +731,15 @@ impl Devnet { } /// Every account group's accounts with their genesis balance. - fn genesis_accounts(&self) -> Result> { + fn genesis_accounts(&self) -> Result> { let mut accounts = Vec::new(); for group in groups::list(&self.groups_dir())? { let info = group.info()?; - accounts.extend(info.accounts.into_iter().map(|a| (a.id, info.amount))); + accounts.extend(info.accounts.into_iter().map(|a| Funded { + id: a.id, + key: a.key, + balance: info.amount, + })); } Ok(accounts) } @@ -854,26 +874,41 @@ impl Devnet { self.rpc().balance(to) } - /// The dev wallet's faucet account, made on first use. Read from the wallet rather than - /// the settings, so a lost settings file finds the same faucet. - fn dev_faucet(&self) -> Result { + /// The dev wallet's faucet account, made on first use, with its public key when known. + /// Read from the wallet rather than the settings, so a lost settings file finds the same + /// faucet. The wallet prints the key only when it makes the account, so it's kept in the + /// settings, and used only while it still matches the faucet. + fn dev_faucet(&self) -> Result<(PublicId, Option)> { match self.labelled_account(FAUCET_LABEL)? { - Some(faucet) => Ok(faucet), - None => self.new_account(Some(FAUCET_LABEL)), + Some(faucet) => { + let key = self + .settings + .faucet_key + .clone() + .filter(|key| PublicId::of_key(key).is_ok_and(|id| id == faucet)); + Ok((faucet, key)) + } + None => self.new_keyed_account(FAUCET_LABEL), } } fn chain_config(&self) -> Result { let genesis_accounts = self.genesis_accounts()?; + let faucet = Funded { + id: self.faucet()?.clone(), + key: self.settings.faucet_key.clone(), + balance: FAUCET_BALANCE, + }; chain_config::patch( + self.settings.line(), self.runtime.upstream_config()?, &ChainOptions { home: &self.runtime.chain_home(), block_time: &self.settings.block_time, - faucet: self.faucet()?, - faucet_balance: FAUCET_BALANCE, + faucet: &faucet, max_txs_per_block: self.settings.max_txs_per_block, genesis_accounts: &genesis_accounts, + keep_upstream_accounts: false, }, ) } @@ -1394,6 +1429,25 @@ impl Devnet { } } + /// A new labelled account and its public key, as `account new public` prints it once. + fn new_keyed_account(&self, label: &str) -> Result<(PublicId, Option)> { + let output = self.wallet(vec![ + "account".into(), + "new".into(), + "public".into(), + "--label".into(), + label.into(), + ])?; + let id = first_public_id(&output) + .with_context(|| format!("the wallet made no account:\n{output}"))?; + let key = output + .lines() + .find_map(|line| line.trim().strip_prefix("With pk ")) + .map(|key| key.trim().to_owned()) + .filter(|key| PublicId::of_key(key).is_ok_and(|of| of == id)); + Ok((id, key)) + } + fn new_account(&self, label: Option<&str>) -> Result { let mut args: Vec = vec!["account".into(), "new".into(), "public".into()]; if let Some(label) = label { diff --git a/src/groups.rs b/src/groups.rs index e7e2895..73d82d9 100644 --- a/src/groups.rs +++ b/src/groups.rs @@ -65,6 +65,10 @@ pub struct GroupAccount { pub id: PublicId, /// Hex, the form `lez_core` takes. pub hex: String, + /// Its public key, in hex: what a LEZ v0.4 genesis funds, and `send --to-pk` pays. Groups + /// made before v0.10.0 have none. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub key: Option, } #[derive(Debug, Clone)] @@ -125,15 +129,21 @@ impl Group { write_json(&self.manifest(), &serde_json::to_value(info)?) } - /// `info` with `ids` appended, numbered after the accounts it has. - pub fn extended(mut info: GroupInfo, ids: Vec) -> GroupInfo { + /// `info` with `accounts` (each id with its public key) appended, numbered after the + /// accounts it has. + pub fn extended(mut info: GroupInfo, accounts: Vec<(PublicId, String)>) -> GroupInfo { let start = info.accounts.len(); - info.accounts - .extend(ids.into_iter().enumerate().map(|(i, id)| GroupAccount { - index: start + i, - hex: id.hex(), - id, - })); + info.accounts.extend( + accounts + .into_iter() + .enumerate() + .map(|(i, (id, key))| GroupAccount { + index: start + i, + hex: id.hex(), + id, + key: Some(key), + }), + ); info } } @@ -161,8 +171,11 @@ mod tests { #[test] fn numbers_new_accounts_after_the_existing_ones() { - let one = Group::extended(GroupInfo::default(), vec![PublicId::parse(A).unwrap()]); - let two = Group::extended(one, vec![PublicId::parse(B).unwrap()]); + let one = Group::extended( + GroupInfo::default(), + vec![(PublicId::parse(A).unwrap(), "aa".to_owned())], + ); + let two = Group::extended(one, vec![(PublicId::parse(B).unwrap(), "bb".to_owned())]); assert_eq!(two.accounts[0].index, 0); assert_eq!(two.accounts[1].index, 1); assert_eq!(two.accounts[1].id.as_str(), B); @@ -179,7 +192,7 @@ mod tests { amount: 5, ..GroupInfo::default() }, - vec![PublicId::parse(A).unwrap()], + vec![(PublicId::parse(A).unwrap(), "aa".to_owned())], ); group.save_info(&info).unwrap(); assert_eq!(group.info().unwrap(), info); diff --git a/src/home.rs b/src/home.rs index be271c4..baa3ac0 100644 --- a/src/home.rs +++ b/src/home.rs @@ -106,6 +106,10 @@ pub struct Settings { /// The dev wallet's faucet account, funded at genesis. Created on the first `up`. #[serde(default, skip_serializing_if = "Option::is_none")] pub faucet: Option, + /// The faucet's public key, in hex, which a LEZ v0.4 genesis funds by. The wallet prints it + /// only when it makes the account. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub faucet_key: Option, } impl Default for Settings { @@ -119,6 +123,7 @@ impl Default for Settings { dev_mode: false, log_filter: DEFAULT_LOG_FILTER.into(), faucet: None, + faucet_key: None, } } } @@ -417,8 +422,14 @@ mod tests { // A v0.4 wallet can't read v0.3 storage, so a v0.4 chain starts its own. assert_eq!(home.wallet_dir(LezLine::V03), home.root().join("wallet")); assert_eq!(home.groups_dir(LezLine::V03), home.root().join("accounts")); - assert_eq!(home.wallet_dir(LezLine::V04), home.root().join("wallet-v0.4")); - assert_eq!(home.groups_dir(LezLine::V04), home.root().join("accounts-v0.4")); + assert_eq!( + home.wallet_dir(LezLine::V04), + home.root().join("wallet-v0.4") + ); + assert_eq!( + home.groups_dir(LezLine::V04), + home.root().join("accounts-v0.4") + ); } #[test] From cf07d2a3d7ac0e8d1d9b7f31b7abb9c40f6d830c Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:38:36 +0000 Subject: [PATCH 04/28] build: build risc0's CPU kernels From LEZ v0.4 the sequencer links the wallet, whose prover needs the CPU kernels that RISC0_SKIP_BUILD_KERNELS left out, so the rc3 build failed to link. Upstream doesn't skip them either. --- docker/Dockerfile | 12 ++++++------ src/runtime/native.rs | 13 +++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 288f685..7160692 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,8 +6,8 @@ # docker build --build-arg LEZ_TAG=v0.3.1 -t ghcr.io/drptbl/logos-devnet-sequencer:v0.3.1 - < docker/Dockerfile # # `standalone` replaces Bedrock with an in-process mock, and `prove` runs guests in-process, so -# the image needs neither a Bedrock node nor r0vm. RISC0_SKIP_BUILD_KERNELS skips the GPU kernels -# `prove` would otherwise compile; the sequencer only executes, it never proves. +# the image needs neither a Bedrock node nor r0vm. risc0's CPU kernels are built too: from LEZ +# v0.4 the sequencer links the wallet, whose prover needs them. FROM rust:1-slim-trixie AS build ARG LEZ_TAG @@ -19,13 +19,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* RUN git clone --depth 1 --branch "$LEZ_TAG" https://github.com/logos-blockchain/logos-execution-zone.git /lez WORKDIR /lez -# The tag's rust-toolchain.toml picks the compiler; rustup installs it on first use. Two builds: -# in one, `prove` would reach the wallet too, which then links the kernels skipped here. The -# target cache is locked, so a concurrent build of another tag can't swap binaries before the copy. +# The tag's rust-toolchain.toml picks the compiler; rustup installs it on first use. Two builds, +# so `prove` stays out of the wallet binary. The target cache is locked, so a concurrent build of +# another tag can't swap binaries before the copy. RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/lez/target,sharing=locked \ - RISC0_SKIP_BUILD_KERNELS=1 cargo build --release --features "$FEATURES" -p sequencer_service \ + cargo build --release --features "$FEATURES" -p sequencer_service \ && cargo build --release -p wallet \ && mkdir -p /out \ && cp target/release/sequencer_service target/release/wallet /out/ \ diff --git a/src/runtime/native.rs b/src/runtime/native.rs index 84bf5e8..3250e09 100644 --- a/src/runtime/native.rs +++ b/src/runtime/native.rs @@ -114,19 +114,16 @@ impl Runtime for Native { .args(["build", "--release", "-p", package]); cmd }; - // Two builds: in one, `prove` would reach the wallet too, which then links the prover - // kernels that RISC0_SKIP_BUILD_KERNELS leaves out. - run_building( - cargo("sequencer_service") - .env("RISC0_SKIP_BUILD_KERNELS", "1") - .args(["--features", SEQUENCER_FEATURES]), - )?; + // Two builds, so `prove` stays out of the wallet binary. risc0's CPU kernels are built + // too: from LEZ v0.4 the sequencer links the wallet, whose prover needs them. + run_building(cargo("sequencer_service").args(["--features", SEQUENCER_FEATURES]))?; run_building(&mut cargo("wallet")) } fn upstream_config(&self) -> Result { let path = find_debug_config(&self.src()).context( - "the LEZ checkout has no sequencer/service/configs/debug/sequencer_config.json", + "the LEZ checkout has no sequencer/service/configs/debug/sequencer_config.json \ + or sequencer/service/networks/local.json", )?; let text = std::fs::read_to_string(&path)?; serde_json::from_str(&text).with_context(|| format!("{} is not JSON", path.display())) From 9afc05f9a845cd85d14b44d89f2e790f648b04b8 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:38:36 +0000 Subject: [PATCH 05/28] feat: start a v0.4 sequencer with setup and start A new v0.4 chain is set up once from the patched config, which writes its channel signing key, then runs with start from its home. The wallet gets an empty password, as it would prompt for one otherwise, and native runs drop inherited SEQUENCER_ variables. --- src/devnet.rs | 19 +++++++++- src/home.rs | 8 +++++ src/runtime/docker.rs | 80 +++++++++++++++++++++++++++++++++++++++---- src/runtime/mod.rs | 40 ++++++++++++++++++++++ src/runtime/native.rs | 68 +++++++++++++++++++++++++++++++----- 5 files changed, 199 insertions(+), 16 deletions(-) diff --git a/src/devnet.rs b/src/devnet.rs index 34bb1be..0178cc3 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -15,7 +15,7 @@ use crate::chain_config::{self, ChainOptions, Funded}; use crate::envfile::{self, Env}; use crate::fetch; use crate::groups::{self, Group, GroupInfo}; -use crate::home::{Home, RuntimeKind, Settings, write_json}; +use crate::home::{Home, LezLine, RuntimeKind, Settings, write_json}; use crate::messaging::{Hub, Wants}; use crate::project::{ProgramSource, ProgramSpec, Project}; use crate::report::{ @@ -380,6 +380,7 @@ impl Devnet { } next.home.save_settings(&next.settings)?; std::fs::create_dir_all(next.home.chain_dir())?; + next.set_chain_up(&config)?; write_json(&next.home.chain_config(), &config)?; next.home.record_chain_dev_mode(next.settings.dev_mode)?; // Every one is tried, and a failure is reported once the chain runs. @@ -892,6 +893,22 @@ impl Devnet { } } + /// Sets a new LEZ v0.4 chain up from `config`: `setup` writes its channel signing key and + /// funding key file beside a copy of the config, which `up` then keeps up to date. A chain + /// set up before, and every v0.3 chain, has nothing to do. + fn set_chain_up(&self, config: &Value) -> Result<()> { + if self.settings.line() == LezLine::V03 || self.home.chain_set_up() { + return Ok(()); + } + // `setup` refuses a home that has a config, e.g. from one that stopped halfway. + remove_if_present(&self.home.chain_config(), |p| std::fs::remove_file(p))?; + let template = self.home.setup_template(); + write_json(&template, config)?; + let set_up = self.runtime.setup_chain(); + remove_if_present(&template, |p| std::fs::remove_file(p))?; + set_up + } + fn chain_config(&self) -> Result { let genesis_accounts = self.genesis_accounts()?; let faucet = Funded { diff --git a/src/home.rs b/src/home.rs index baa3ac0..43f28d5 100644 --- a/src/home.rs +++ b/src/home.rs @@ -236,6 +236,14 @@ impl Home { pub fn chain_config(&self) -> PathBuf { self.chain_dir().join("sequencer_config.json") } + /// The config a new LEZ v0.4 chain is set up from; `setup` copies it to `chain_config`. + pub fn setup_template(&self) -> PathBuf { + self.chain_dir().join("setup-template.json") + } + /// Whether a LEZ v0.4 chain here has been set up: `setup` makes its channel signing key. + pub fn chain_set_up(&self) -> bool { + self.chain_dir().join("channel_signing_key").exists() + } /// The chain's own record of its dev mode, which `reset` deletes with it. fn chain_dev_mode_file(&self) -> PathBuf { self.chain_dir().join("dev-mode") diff --git a/src/runtime/docker.rs b/src/runtime/docker.rs index 32d9436..678a002 100644 --- a/src/runtime/docker.rs +++ b/src/runtime/docker.rs @@ -14,7 +14,7 @@ use super::{ Runtime, TimedOut, WalletArg, all_output_of, batch_script, redact_recovery_phrase, redacted, run_attached, sequencer_env, split_batch, stdout_of, stdout_within, }; -use crate::home::{Home, Settings, write_json}; +use crate::home::{Home, LezLine, Settings, write_json}; /// The image's build recipe. Built from stdin, it needs no context: it clones LEZ itself. pub const DOCKERFILE: &str = include_str!("../../docker/Dockerfile"); @@ -74,6 +74,7 @@ impl Docker { chain_dir: &self.home.chain_dir().to_string_lossy(), dev_mode: self.settings.dev_mode, log_filter: &self.settings.log_filter, + line: self.settings.line(), }); // JSON is YAML, and serde quotes every path correctly. write_json(&self.home.compose_file(), &spec) @@ -212,6 +213,26 @@ impl Runtime for Docker { stdout_of(self.compose().args(["up", "--detach", "sequencer"])).map(drop) } + fn setup_chain(&self) -> Result<()> { + self.write_compose_file()?; + let template = format!("{CHAIN_MOUNT}/{}", file_name(&self.home.setup_template())); + stdout_of( + self.compose() + .args([ + "run", + "--rm", + "--no-deps", + "-T", + "--interactive=false", + "sequencer", + ]) + .arg("sequencer_service") + .args(super::setup_args(CHAIN_MOUNT, &template)), + ) + .map(drop) + .context("setting the chain up") + } + /// Takes the project down whatever state its containers are in (running, paused, /// restarting). Only an unreachable Docker counts as nothing to stop. fn stop(&self) -> Result<()> { @@ -282,6 +303,13 @@ impl Runtime for Docker { } } +/// The last part of `path`. +fn file_name(path: &Path) -> String { + path.file_name() + .map(|name| name.to_string_lossy().into_owned()) + .unwrap_or_default() +} + /// `logos-devnet` for the default home, and a name derived from the path for any other, so /// two homes never share containers. fn compose_project(home: &Home) -> String { @@ -366,21 +394,33 @@ struct ComposeInputs<'a> { chain_dir: &'a str, dev_mode: bool, log_filter: &'a str, + line: LezLine, } /// The compose file. The RPC is published on loopback only: it has no caller auth. fn compose_spec(i: &ComposeInputs) -> Value { + let command = match i.line { + LezLine::V03 => json!([ + "sequencer_service", + format!("{CHAIN_MOUNT}/sequencer_config.json"), + "--port", + CONTAINER_PORT.to_string() + ]), + LezLine::V04 => json!([ + "sequencer_service", + "start", + CHAIN_MOUNT, + "--rpc-listen-address", + format!("0.0.0.0:{CONTAINER_PORT}") + ]), + }; json!({ "name": i.project, "services": { "sequencer": { "image": i.image, "user": i.user, - "command": [ - "sequencer_service", - format!("{CHAIN_MOUNT}/sequencer_config.json"), - "--port", CONTAINER_PORT.to_string() - ], + "command": command, "ports": [format!("127.0.0.1:{}:{CONTAINER_PORT}", i.port)], // The long form takes any path, `:` included. "volumes": [{ @@ -399,7 +439,9 @@ fn compose_spec(i: &ComposeInputs) -> Value { "user": i.user, "profiles": ["tools"], "entrypoint": ["wallet"], - "environment": { "LEE_WALLET_HOME_DIR": WALLET_MOUNT } + // From v0.4 the wallet asks for a password on the terminal unless this is set, + // and an empty one keeps its storage unencrypted. + "environment": { "LEE_WALLET_HOME_DIR": WALLET_MOUNT, "LEE_WALLET_PASSWORD": "" } } } }) @@ -418,9 +460,33 @@ mod tests { chain_dir: "/Users/me/My Devnet/chain", dev_mode: false, log_filter: "info,kameo=warn", + line: LezLine::V03, } } + #[test] + fn a_v0_4_sequencer_starts_from_its_home() { + let spec = compose_spec(&ComposeInputs { + line: LezLine::V04, + ..inputs() + }); + assert_eq!( + spec["services"]["sequencer"]["command"], + json!([ + "sequencer_service", + "start", + "/devnet/chain", + "--rpc-listen-address", + "0.0.0.0:3040" + ]) + ); + // A v0.4 wallet asks for a password on the terminal unless this is set; empty is none. + assert_eq!( + spec["services"]["wallet"]["environment"]["LEE_WALLET_PASSWORD"], + "" + ); + } + #[test] fn the_sequencer_skips_proof_checks_only_in_dev_mode() { let spec = compose_spec(&inputs()); diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 507f33c..5b28fa5 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -66,6 +66,10 @@ pub trait Runtime { /// Starts the sequencer on the config in the chain directory. Returns once it is launched, /// not once it serves. fn start(&self) -> Result<()>; + /// Sets a new LEZ v0.4 chain's home up from the config at `Home::setup_template` (see + /// `setup_args`): its config, channel signing key and funding key file. v0.3 chains have + /// nothing to set up. + fn setup_chain(&self) -> Result<()>; /// Stops the sequencer if it runs. fn stop(&self) -> Result<()>; /// Whether the sequencer runs. False when the runtime can't be asked (Docker is down). @@ -94,6 +98,26 @@ pub trait Runtime { fn last_log_line(&self) -> Option; } +/// The Bedrock funding public key `setup` takes: the one LEZ's own local recipes use. A standalone +/// sequencer has no Bedrock node, so nothing ever pays with it. +pub const FUNDING_KEY: &str = "2e03b2eff5a45478e7e79668d2a146cf2c5c7925bce927f2b1c67f2ab4fc0d26"; + +/// `sequencer_service`'s arguments that set a v0.4 chain `home` up from `template`, with the +/// template's genesis, so the first `start` creates the channel. +pub(crate) fn setup_args(home: &str, template: &str) -> Vec { + [ + "setup", + home, + "--config", + template, + "--funding-public-key", + FUNDING_KEY, + "--create-channel", + ] + .map(str::to_owned) + .to_vec() +} + /// A sequencer log line without the time it starts with, `[2026-11-15T18:45:51Z INFO ...`, so /// a line repeated later reads the same. pub(crate) fn log_line_text(line: &str) -> String { @@ -360,6 +384,22 @@ fn combined(output: &Output) -> String { mod tests { use super::*; + #[test] + fn sets_a_v0_4_chain_up_from_a_template() { + assert_eq!( + setup_args("/devnet/chain", "/devnet/chain/setup-template.json"), + [ + "setup", + "/devnet/chain", + "--config", + "/devnet/chain/setup-template.json", + "--funding-public-key", + FUNDING_KEY, + "--create-channel", + ] + ); + } + #[test] fn a_log_line_without_its_time() { let at = |t: &str| { diff --git a/src/runtime/native.rs b/src/runtime/native.rs index 3250e09..f2cce67 100644 --- a/src/runtime/native.rs +++ b/src/runtime/native.rs @@ -17,7 +17,7 @@ use super::{ redact_recovery_phrase, redacted, run_attached, run_building, sequencer_env, split_batch, stdout_of, }; -use crate::home::{Home, Settings}; +use crate::home::{Home, LezLine, Settings}; pub struct Native { home: Home, @@ -150,10 +150,19 @@ impl Runtime for Native { .create(true) .append(true) .open(self.log_file())?; - let child = Command::new(self.bin("sequencer_service")) - .arg(self.home.chain_config()) - .args(["--listen-address", "127.0.0.1", "--port"]) - .arg(self.settings.port.to_string()) + let mut cmd = Command::new(self.bin("sequencer_service")); + match self.settings.line() { + LezLine::V03 => cmd + .arg(self.home.chain_config()) + .args(["--listen-address", "127.0.0.1", "--port"]) + .arg(self.settings.port.to_string()), + LezLine::V04 => cmd + .arg("start") + .arg(self.home.chain_dir()) + .arg("--rpc-listen-address") + .arg(format!("127.0.0.1:{}", self.settings.port)), + }; + let child = without_sequencer_vars(&mut cmd) .current_dir(self.home.chain_dir()) .envs(sequencer_env( self.settings.dev_mode, @@ -170,6 +179,17 @@ impl Runtime for Native { Ok(()) } + fn setup_chain(&self) -> Result<()> { + let args = super::setup_args( + &self.home.chain_dir().to_string_lossy(), + &self.home.setup_template().to_string_lossy(), + ); + let mut cmd = Command::new(self.bin("sequencer_service")); + stdout_of(without_sequencer_vars(&mut cmd).args(args)) + .map(drop) + .context("setting the chain up") + } + fn stop(&self) -> Result<()> { let Some(pid) = self.live_pid() else { let _ = std::fs::remove_file(self.pid_file()); @@ -199,6 +219,7 @@ impl Runtime for Native { all_output_of( Command::new(self.bin("wallet")) .env("LEE_WALLET_HOME_DIR", home) + .env("LEE_WALLET_PASSWORD", "") .args(args), ) .map(|out| redact_recovery_phrase(&out)) @@ -210,6 +231,7 @@ impl Runtime for Native { let out = all_output_of( Command::new("sh") .env("LEE_WALLET_HOME_DIR", home) + .env("LEE_WALLET_PASSWORD", "") .arg("-c") .arg(script), ) @@ -231,6 +253,17 @@ impl Runtime for Native { } } +/// `cmd` without the `SEQUENCER_*` variables this process has: a v0.4 sequencer reads each of +/// its flags from one, and a stray one would change the devnet. +fn without_sequencer_vars(cmd: &mut Command) -> &mut Command { + for (var, _) in std::env::vars_os() { + if var.to_string_lossy().starts_with("SEQUENCER_") { + cmd.env_remove(var); + } + } + cmd +} + /// Whether a process's command line (as `ps -o command=` prints it) runs `bin`: it starts /// with that path, then ends or goes on to the arguments. fn runs(command: &str, bin: &Path) -> bool { @@ -243,9 +276,15 @@ fn runs(command: &str, bin: &Path) -> bool { fn find_debug_config(dir: &Path) -> Option { let mut stack = vec![(dir.to_path_buf(), 0)]; while let Some((dir, depth)) = stack.pop() { - let file = dir.join("sequencer_config.json"); - if dir.ends_with("sequencer/service/configs/debug") && file.exists() { - return Some(file); + // v0.3's debug config, or v0.4's local one. + for (parent, name) in [ + ("sequencer/service/configs/debug", "sequencer_config.json"), + ("sequencer/service/networks", "local.json"), + ] { + let file = dir.join(name); + if dir.ends_with(parent) && file.exists() { + return Some(file); + } } if depth >= 6 { continue; @@ -310,6 +349,19 @@ mod tests { } } + #[test] + fn finds_the_v0_4_local_config() { + let dir = tempfile::tempdir().unwrap(); + let networks = dir.path().join("lez/sequencer/service/networks"); + std::fs::create_dir_all(&networks).unwrap(); + std::fs::write(networks.join("testnet.json"), "{}").unwrap(); + std::fs::write(networks.join("local.json"), "{}").unwrap(); + assert_eq!( + find_debug_config(dir.path()).unwrap(), + networks.join("local.json") + ); + } + #[test] fn ignores_build_output() { let dir = tempfile::tempdir().unwrap(); From 637de7b6c6c9557a730bf898a279848560829da1 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:39:45 +0000 Subject: [PATCH 06/28] feat: read v0.4 account state LEZ v0.4 keeps program data under actor_states and answers null for an account never used, so in_use and account read both shapes. --- src/devnet.rs | 2 ++ src/rpc.rs | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/devnet.rs b/src/devnet.rs index 0178cc3..78f6824 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -1519,8 +1519,10 @@ impl Devnet { let id = self.account_id(account)?; let rpc = self.rpc(); let state = rpc.account(&id)?; + // Each program's bytes: `shards` on LEZ v0.3, `actor_states` on v0.4. let shards: BTreeMap> = state["data"]["shards"] .as_object() + .or_else(|| state["data"]["actor_states"].as_object()) .map(|shards| { shards .iter() diff --git a/src/rpc.rs b/src/rpc.rs index 1524b77..92e5354 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -87,11 +87,16 @@ fn result_of(reply: Value, method: &str) -> Result { .with_context(|| format!("{method} returned no result: {reply}")) } +/// Whether `getAccount`'s answer is an account in use: it sent something, or a program keeps +/// data in it. LEZ v0.3 keeps that data under `shards`, v0.4 under `actor_states`, and v0.4 +/// answers null for an account never used. pub(crate) fn in_use(account: &Value) -> bool { let nonce = account["nonce"].as_u64().unwrap_or(0); - let has_data = account["data"]["shards"] - .as_object() - .is_some_and(|shards| !shards.is_empty()); + let has_data = ["shards", "actor_states"].iter().any(|key| { + account["data"][key] + .as_object() + .is_some_and(|data| !data.is_empty()) + }); nonce > 0 || has_data } @@ -142,5 +147,14 @@ mod tests { let fresh = json!({ "nonce": 0, "data": { "shards": {} } }); assert!(in_use(&header)); assert!(!in_use(&fresh)); + // LEZ v0.4: `getAccount` answers null for an account never used, and keeps program data + // under `actor_states`. + assert!(!in_use(&Value::Null)); + assert!(!in_use( + &json!({ "nonce": 0, "data": { "actor_states": {} } }) + )); + assert!(in_use( + &json!({ "nonce": 0, "data": { "actor_states": { "P": [1] } } }) + )); } } From c8f1bad1fcc3b27c762a088a9f7e25ca40eef8fa Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:41:23 +0000 Subject: [PATCH 07/28] feat: pay unused v0.4 accounts by key LEZ v0.4 admits an account it has never seen only when the payment names its public key, so group top-ups pass each account's key, and fund takes --key. A v0.4 wallet config sets no gas_limit, so the wallet budgets up to the block's cap. --- src/devnet.rs | 127 ++++++++++++++++++++++++++++++++++++++------------ src/main.rs | 10 +++- 2 files changed, 107 insertions(+), 30 deletions(-) diff --git a/src/devnet.rs b/src/devnet.rs index 78f6824..e6250fd 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -280,7 +280,10 @@ impl Devnet { /// run: without one the wallet creates a default pointing at the public testnet. fn point_wallet_at(&self, home: &Path, sequencer: &str) -> Result<()> { std::fs::create_dir_all(home)?; - write_json(&home.join("wallet_config.json"), &wallet_config(sequencer)) + write_json( + &home.join("wallet_config.json"), + &wallet_config(self.settings.line(), sequencer), + ) } /// The dev wallet of the chain's LEZ line. @@ -712,7 +715,7 @@ impl Devnet { let mut unfunded = Vec::new(); for account in &info.accounts { if !rpc.account_in_use(&account.id)? { - unfunded.push(&account.id); + unfunded.push(account); } } if unfunded.is_empty() { @@ -724,8 +727,8 @@ impl Devnet { unfunded.len(), group.name ); - for id in unfunded { - self.send(id, u128::from(info.amount))?; + for account in unfunded { + self.send(&account.id, account.key.as_deref(), u128::from(info.amount))?; } } Ok(()) @@ -775,7 +778,7 @@ impl Devnet { // Funding only needs the dev wallet: a daemon that won't start doesn't cost the // account its funds. let funded = if new_chain { - self.send(&info.account, info.funded).map(drop) + self.send(&info.account, None, info.funded).map(drop) } else { Ok(()) }; @@ -855,23 +858,15 @@ impl Devnet { std::fs::create_dir_all(session.wallet_dir())?; write_json( &session.wallet_config(), - &wallet_config(&self.settings.sequencer_url()), + &wallet_config(self.settings.line(), &self.settings.sequencer_url()), ) } - /// Sends `amount` lepta from the faucet to `to` and returns its new balance. - fn send(&self, to: &PublicId, amount: u128) -> Result { - let faucet = self.faucet()?; - self.wallet(vec![ - "auth-transfer".into(), - "send".into(), - "--from".into(), - faucet.wallet_form().into(), - "--to".into(), - to.wallet_form().into(), - "--amount".into(), - amount.to_string().into(), - ])?; + /// Sends `amount` lepta from the faucet to `to`, whose public key is `key` when known, and + /// returns its new balance. + fn send(&self, to: &PublicId, key: Option<&str>, amount: u128) -> Result { + let args = transfer_args(self.settings.line(), self.faucet()?, to, key, amount); + self.wallet(args.into_iter().map(WalletArg::from).collect())?; self.rpc().balance(to) } @@ -1085,12 +1080,22 @@ impl Devnet { }) } - pub fn fund(&self, account: &str, amount: u128) -> Result { + /// Sends `amount` lepta from the faucet to `account`. LEZ v0.4 pays an account it has + /// never seen only by its public key, `key`. + pub fn fund(&self, account: &str, amount: u128, key: Option<&str>) -> Result { let to = PublicId::parse(account)?; + if let Some(key) = key + && PublicId::of_key(key)? != to + { + bail!( + "that public key names another account than {}", + to.wallet_form() + ); + } // Fails before any work when there is no faucet yet. self.faucet()?; self.require_running()?; - let balance = self.send(&to, amount)?; + let balance = self.send(&to, key, amount)?; Ok(Balance { account: to.wallet_form(), balance: Some(balance), @@ -1260,7 +1265,7 @@ impl Devnet { funded: amount, }; session.save_info(&info)?; - self.send(&info.account, amount)?; + self.send(&info.account, None, amount)?; // The session is made and funded either way: the next `up` joins it again. if let Err(e) = self.join_hub(&ctl) { eprintln!("session {}: {e:#}", session.name); @@ -1662,7 +1667,10 @@ impl Devnet { } } std::fs::create_dir_all(dir)?; - write_json(&path, &wallet_config(&self.settings.sequencer_url()))?; + write_json( + &path, + &wallet_config(self.settings.line(), &self.settings.sequencer_url()), + )?; Ok(WalletConfig { path }) } } @@ -1899,9 +1907,8 @@ fn remove_if_present(path: &Path, remove: fn(&Path) -> std::io::Result<()>) -> R /// A wallet config in the shape `lez_core` 0.5.1 writes. It reads `sequencer.sequencer_addr`; /// the top-level `sequencer_addr` and `sequencers` are set too, so a build that reads those /// finds the devnet as well. -fn wallet_config(sequencer: &str) -> Value { - json!({ - "gas_limit": 200_000, +fn wallet_config(line: LezLine, sequencer: &str) -> Value { + let mut config = json!({ "multi_sequencer_client_config": { "calibration_limit": 3, "distribution_limit": 1 }, "seq_block_poll_max_amount": 100, "seq_poll_max_retries": 10, @@ -1910,7 +1917,33 @@ fn wallet_config(sequencer: &str) -> Value { "sequencer": { "sequencer_addr": sequencer }, "sequencer_addr": sequencer, "sequencers": [{ "sequencer_addr": sequencer }] - }) + }); + // v0.3 declares this much gas on each transaction. v0.4 measures it, and without a + // `gas_limit` budgets up to the block's cap, which a 96 KiB program segment needs. + if line == LezLine::V03 { + config["gas_limit"] = json!(200_000); + } + config +} + +/// The wallet's arguments that send `amount` lepta from `from` to `to`. LEZ v0.4 takes an +/// account it has never seen only when the payment names its public key (`key`), and then +/// refuses `--to` beside it. +fn transfer_args( + line: LezLine, + from: &PublicId, + to: &PublicId, + key: Option<&str>, + amount: u128, +) -> Vec { + let mut args: Vec = vec!["auth-transfer".into(), "send".into(), "--from".into()]; + args.push(from.wallet_form()); + match (line, key) { + (LezLine::V04, Some(key)) => args.extend(["--to-pk".into(), key.to_owned()]), + _ => args.extend(["--to".into(), to.wallet_form()]), + } + args.extend(["--amount".into(), amount.to_string()]); + args } /// The account `wallet account list` shows with `[label]`. @@ -2533,7 +2566,7 @@ mod tests { #[test] fn wallet_configs_point_every_address_field_at_the_devnet() { - let config = wallet_config("http://127.0.0.1:3040"); + let config = wallet_config(LezLine::V03, "http://127.0.0.1:3040"); assert_eq!( config["sequencer"]["sequencer_addr"], "http://127.0.0.1:3040" @@ -2545,6 +2578,42 @@ mod tests { ); assert_eq!(config["gas_limit"], 200_000); assert_eq!(config["seq_poll_timeout"], "2s"); + // A v0.4 wallet budgets each transaction up to the block's cap when it sets none. + let config = wallet_config(LezLine::V04, "http://127.0.0.1:3040"); + assert!(config.get("gas_limit").is_none()); + assert_eq!(config["sequencer_addr"], "http://127.0.0.1:3040"); + } + + #[test] + fn pays_an_account_by_its_key_on_v0_4() { + let faucet = PublicId::parse(ID).unwrap(); + let to = PublicId::parse("6YvesSEDWW25kpi8SSki2c8o5m3uACsigvGnNQ6wMruh").unwrap(); + let args = |line, key| transfer_args(line, &faucet, &to, key, 5); + let to_id = format!("Public/{}", to.as_str()); + assert!( + args(LezLine::V03, Some("ab")).contains(&to_id), + "v0.3 pays by id" + ); + // v0.4 admits an account it has never seen only when the payment names its key. + let by_key = args(LezLine::V04, Some("ab")); + assert!( + by_key.windows(2).any(|w| w == ["--to-pk", "ab"]), + "{by_key:?}" + ); + assert!( + !by_key.contains(&"--to".to_owned()), + "--to and --to-pk conflict" + ); + assert!(args(LezLine::V04, None).contains(&to_id)); + } + + #[test] + fn funds_by_key_only_the_account_the_key_names() { + let dir = tempfile::tempdir().unwrap(); + let devnet = devnet_in(&dir.path().join("home")); + let key = crate::account::public_key_of(&"01".repeat(32)).unwrap(); + let err = devnet.fund(ID, 5, Some(&key)).unwrap_err(); + assert!(err.to_string().contains("names another account"), "{err}"); } #[test] @@ -2970,7 +3039,7 @@ mod tests { fn fund_and_deploy_refuse_before_up() { let dir = tempfile::tempdir().unwrap(); let devnet = devnet_in(dir.path()); - let err = devnet.fund(ID, 1).unwrap_err(); + let err = devnet.fund(ID, 1, None).unwrap_err(); assert!(err.to_string().contains("logos-devnet up"), "{err}"); let elf = dir.path().join("program.bin"); std::fs::write(&elf, [0u8; 8]).unwrap(); diff --git a/src/main.rs b/src/main.rs index 79217e2..25c0b81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,10 @@ enum Command { /// Lepta to send. #[arg(default_value_t = u128::from(DEFAULT_FUND))] amount: u128, + /// The account's public key, in hex: LEZ v0.4 pays an account it has never seen only + /// by its key. + #[arg(long)] + key: Option, }, /// Deploy a program binary, and add `LOGOS_PROGRAM_` to the env file. Deploy { @@ -242,7 +246,11 @@ fn main() -> Result<()> { } Ok(()) } - Command::Fund { account, amount } => emit(&devnet.fund(&account, amount)?, json), + Command::Fund { + account, + amount, + key, + } => emit(&devnet.fund(&account, amount, key.as_deref())?, json), Command::Deploy { name, elf, mutable } => emit(&devnet.deploy(&name, &elf, mutable)?, json), Command::Accounts(command) => match command { AccountsCommand::New { From ce6a484e7ca4d99e1359c7547ef5b50997c7e375 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:42:17 +0000 Subject: [PATCH 08/28] feat: refuse sessions on LEZ v0.4 The Logos catalog has no lez_core for v0.4 yet, and 0.5.1 can't drive a v0.4 chain, so up and session new refuse before anything changes and say why. --- src/devnet.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/devnet.rs b/src/devnet.rs index e6250fd..e18372e 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -32,6 +32,11 @@ const FAUCET_BALANCE: u64 = 1_000_000_000_000_000_000; const FAUCET_LABEL: &str = "faucet"; /// What `fund`, sessions and account groups send when no amount is given. pub const DEFAULT_FUND: u64 = 10_000_000_000; +/// Why sessions don't run on LEZ v0.4 yet. +const SESSIONS_ON_V04: &str = "sessions don't run on LEZ v0.4 yet: the Logos catalog has no \ + lez_core for v0.4, and lez_core 0.5.1 can't drive a v0.4 chain. Drop [sessions] from the \ + project file and `logos-devnet session rm` any session, or stay on v0.3"; + /// How `up` waits for a starting sequencer's first block. A long chain replays first, logging /// a different line for each block (186k blocks took 34 min), so `up` waits as long as the log /// shows something new. A sequencer stuck repeating one line counts as quiet. @@ -477,6 +482,15 @@ impl Devnet { self.runtime.check_wallet_file(&binary)?; } } + if self.settings.line() == LezLine::V04 + && (!self.sessions().is_empty() + || self + .project + .as_ref() + .is_some_and(|p| !p.sessions.is_empty())) + { + bail!("{SESSIONS_ON_V04}"); + } if self.needs_logosctl() && !logosctl_on_path() { bail!( "sessions and the messaging hub need logosctl, the Logos Core CLI, on your PATH. \ @@ -1152,6 +1166,9 @@ impl Devnet { if session.exists() { bail!("session {name} exists. `logos-devnet session rm {name}` first"); } + if self.settings.line() == LezLine::V04 { + bail!("{SESSIONS_ON_V04}"); + } let modules = session::modules_with(extra)?; // Fails before any work when there is no faucet yet. self.faucet()?; @@ -2607,6 +2624,25 @@ mod tests { assert!(args(LezLine::V04, None).contains(&to_id)); } + #[test] + fn refuses_sessions_on_lez_v0_4() { + let dir = tempfile::tempdir().unwrap(); + let file = "home = \"home\"\n[devnet]\nlez = \"v0.4.0-rc3\"\n[sessions.alice]\n"; + let devnet = devnet_with_file(dir.path(), file); + let next = Devnet::with( + devnet.home.clone(), + devnet.settings_for_up(), + devnet.project.clone(), + ); + let err = next.check_needs(|| true).unwrap_err(); + assert!(err.to_string().contains("lez_core"), "{err}"); + let mut v04 = devnet.settings.clone(); + v04.lez = "v0.4.0-rc3".into(); + let bare = Devnet::with(devnet.home.clone(), v04, None); + let err = bare.session_new("bob", &[], 1).unwrap_err(); + assert!(err.to_string().contains("lez_core"), "{err}"); + } + #[test] fn funds_by_key_only_the_account_the_key_names() { let dir = tempfile::tempdir().unwrap(); From 425def88ac17ae13e73a25e588b1cb00965c132c Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:42:58 +0000 Subject: [PATCH 09/28] feat: keep upstream genesis accounts on request LEZ's examples and tools such as prog-tui fund themselves from the genesis accounts whose keys LEZ publishes, which logos-devnet drops. upstream_accounts = true in [devnet] keeps them funded on a new chain. --- src/devnet.rs | 6 +++++- src/project.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/devnet.rs b/src/devnet.rs index e18372e..9b91c1c 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -934,7 +934,11 @@ impl Devnet { faucet: &faucet, max_txs_per_block: self.settings.max_txs_per_block, genesis_accounts: &genesis_accounts, - keep_upstream_accounts: false, + keep_upstream_accounts: self + .project + .as_ref() + .and_then(|p| p.devnet.upstream_accounts) + .unwrap_or(false), }, ) } diff --git a/src/project.rs b/src/project.rs index 706eb0d..4b164b1 100644 --- a/src/project.rs +++ b/src/project.rs @@ -7,6 +7,7 @@ //! [devnet] # optional: the same settings as `up`'s flags //! block_time = "1s" //! max_txs_per_block = 100 +//! upstream_accounts = true # also fund LEZ's own genesis accounts on a new chain //! //! [programs] # name = guest binary, relative to this file //! counter = "target/riscv32im-risc0-zkvm-elf/docker/counter.bin" @@ -114,6 +115,10 @@ pub struct DevnetSection { pub max_txs_per_block: Option, pub dev_mode: Option, pub log_filter: Option, + /// Keep LEZ's own genesis accounts, whose keys are published, funded too on a new chain: + /// LEZ's examples and tools fund themselves from them. Not a setting `up` keeps: only a + /// new chain's genesis reads it. + pub upstream_accounts: Option, } impl DevnetSection { @@ -326,6 +331,15 @@ mod tests { assert!(project_in(dir.path(), "[messaging]\nport = 1\n").is_err()); } + #[test] + fn can_keep_upstreams_genesis_accounts() { + let dir = tempfile::tempdir().unwrap(); + let project = project_in(dir.path(), "[devnet]\nupstream_accounts = true\n").unwrap(); + assert_eq!(project.devnet.upstream_accounts, Some(true)); + let project = project_in(dir.path(), "").unwrap(); + assert_eq!(project.devnet.upstream_accounts, None); + } + #[test] fn reads_every_section_and_resolves_paths_against_the_file() { let dir = tempfile::tempdir().unwrap(); From 4e8608d74f9ce08bfca78dd32c54077f0ea5305d Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:44:30 +0000 Subject: [PATCH 10/28] feat: forget a v0.4 chain in v0.4's storage shape A v0.4 wallet refuses v0.3's shards, records where its sync started, and caches spent nullifiers beside its storage. Forgetting a chain now writes fresh accounts in the shape the storage holds, zeroes synced_from_block, and drops the nullifier cache. The layout was checked against a wallet rc3 made. --- src/wallet_storage.rs | 85 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/src/wallet_storage.rs b/src/wallet_storage.rs index 7f26424..b913a70 100644 --- a/src/wallet_storage.rs +++ b/src/wallet_storage.rs @@ -37,11 +37,20 @@ pub fn clear_new_chain(owner: &Path) -> Result<()> { type Raw = Box; type RawObject = BTreeMap; -/// The LEZ wallet's state of a fresh account: what every account holds on a new chain. -fn fresh_account() -> Result { - Ok(RawValue::from_string( - r#"{"nonce":0,"data":{"shards":{}}}"#.into(), - )?) +/// The LEZ wallet's state of a fresh account, what every account holds on a new chain, in the +/// shape of `was`: v0.4 keeps program data under `actor_states` and refuses v0.3's `shards`. +fn fresh_account(was: &Raw) -> Result { + let data: Option = serde_json::from_str::(was.get())? + .get("data") + .map(|data| serde_json::from_str(data.get())) + .transpose()?; + let key = match data { + Some(data) if data.contains_key("actor_states") => "actor_states", + _ => "shards", + }; + Ok(RawValue::from_string(format!( + r#"{{"nonce":0,"data":{{"{key}":{{}}}}}}"# + ))?) } /// `raw`, an object, with `change` applied to its members. @@ -72,6 +81,13 @@ fn forget_chain(text: &str) -> Result { "last_synced_block".into(), RawValue::from_string("0".into())?, ); + // v0.4 also records the block its sync started from. + if storage.contains_key("synced_from_block") { + storage.insert( + "synced_from_block".into(), + RawValue::from_string("0".into())?, + ); + } edit_member(&mut storage, "key_chain", |key_chain| { edit_object(key_chain, |key_chain| { edit_member(key_chain, "accounts", |accounts| { @@ -94,8 +110,9 @@ fn forget_chain(text: &str) -> Result { let mut entries: RawObject = serde_json::from_str(shared.get())?; for entry in entries.values_mut() { edit_object(entry, |entry| { - if entry.contains_key("account") { - entry.insert("account".into(), fresh_account()?); + if let Some(account) = entry.get("account") { + let fresh = fresh_account(account)?; + entry.insert("account".into(), fresh); } Ok(()) })?; @@ -114,7 +131,7 @@ fn forget_private_states(value: &mut Raw) -> Result<()> { let (keys, states): (Raw, Vec<(Raw, Raw)>) = serde_json::from_str(value.get())?; let states = states .into_iter() - .map(|(kind, _)| Ok((kind, fresh_account()?))) + .map(|(kind, account)| Ok((kind, fresh_account(&account)?))) .collect::>>()?; *value = serde_json::value::to_raw_value(&(keys, states))?; Ok(()) @@ -135,7 +152,15 @@ pub fn forget_chain_in(storage: &Path) -> Result<()> { ) })?; replace_file(storage, forgotten.as_bytes()) - .with_context(|| format!("replacing {}", storage.display())) + .with_context(|| format!("replacing {}", storage.display()))?; + // v0.4 caches the nullifiers it saw spent next to the storage: the old chain's. + let nullifiers = storage.with_extension("nullifiers"); + match std::fs::remove_file(&nullifiers) { + Err(e) if e.kind() != std::io::ErrorKind::NotFound => { + Err(e).with_context(|| format!("deleting {}", nullifiers.display())) + } + _ => Ok(()), + } } /// Replaces `path` with `contents` in one step, keeping its permissions: it never holds half of @@ -225,6 +250,48 @@ pub(crate) mod tests { assert_eq!(storage, expected); } + /// A v0.4 wallet's `storage.json` after a chain ran, in the layout LEZ v0.4.0-rc3's wallet + /// writes: the private state keeps program data under `actor_states`, and the wallet + /// records where its sync started. + const SYNCED_STORAGE_V04: &str = r#"{ + "key_chain": { + "accounts": [ + { "Private": { "account_id": "Q", "chain_index": "/0", "data": { + "value": [ { "keys": 2 }, [ + [ "Regular", { "nonce": 7, "data": { "actor_states": { "T": [1, 2] } } } ] + ] ] } } } + ], + "shared_private_accounts": {} + }, + "last_synced_block": 42, + "synced_from_block": 40 +}"#; + + #[test] + fn forgets_a_v0_4_chain_in_its_own_shape() { + let storage: Value = + serde_json::from_str(&forget_chain(SYNCED_STORAGE_V04).unwrap()).unwrap(); + assert_eq!(storage["last_synced_block"], 0); + assert_eq!(storage["synced_from_block"], 0); + let state = &storage["key_chain"]["accounts"][0]["Private"]["data"]["value"][1][0]; + // v0.4 refuses `shards`: a fresh account has to be in the shape it read. + assert_eq!( + state, + &serde_json::json!(["Regular", { "nonce": 0, "data": { "actor_states": {} } }]) + ); + } + + #[test] + fn drops_the_spent_nullifiers_a_v0_4_wallet_cached() { + let dir = tempfile::tempdir().unwrap(); + let storage = dir.path().join(STORAGE_FILE); + std::fs::write(&storage, SYNCED_STORAGE_V04).unwrap(); + let nullifiers = dir.path().join("storage.nullifiers"); + std::fs::write(&nullifiers, "old chain").unwrap(); + forget_chain_in(&storage).unwrap(); + assert!(!nullifiers.exists()); + } + #[test] fn forgetting_a_chain_adds_nothing_and_refuses_a_layout_it_doesnt_know() { let bare = r#"{"key_chain":{"accounts":[]},"last_synced_block":9}"#; From 0a2d47e3278ef2efa5ca1d17ad2e7f694fbe1fc8 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:46:27 +0000 Subject: [PATCH 11/28] fix: say v0.4 needs a key for an unused account --- src/devnet.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/devnet.rs b/src/devnet.rs index 9b91c1c..ffaa0af 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -1113,6 +1113,16 @@ impl Devnet { // Fails before any work when there is no faucet yet. self.faucet()?; self.require_running()?; + if self.settings.line() == LezLine::V04 + && key.is_none() + && !self.rpc().account_in_use(&to)? + { + bail!( + "{} has never been used, and LEZ v0.4 pays such an account only by its public \ + key: pass it with `--key `, as `wallet account new public` printed it", + to.wallet_form() + ); + } let balance = self.send(&to, key, amount)?; Ok(Balance { account: to.wallet_form(), From 202e8e376488095374c4b62044b22cf27ada5eb6 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:47:50 +0000 Subject: [PATCH 12/28] docs: cover LEZ v0.4 --- README.md | 34 ++++++++++++++++++++++++---------- skills/logos-devnet/SKILL.md | 7 +++++-- src/home.rs | 1 + 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7184e1e..e1677dd 100644 --- a/README.md +++ b/README.md @@ -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.4 t=aarch64-apple-darwin +v=v0.10.0 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 \ @@ -37,12 +37,12 @@ source ~/.logos-devnet/env # LOGOS_DEVNET_SEQUENCER, LOG | Command | What it does | | --- | --- | -| `up` | Starts the devnet, or resumes it, and makes it match your `logos-devnet.toml`. Takes `--docker` or `--native`, `--lez ` (a v0.3 tag), `--port`, `--block-time`, `--max-txs-per-block`, `--dev-mode` and `--log-filter`, and remembers them. `--rebuild` builds the image or binaries again. | +| `up` | Starts the devnet, or resumes it, and makes it match your `logos-devnet.toml`. Takes `--docker` or `--native`, `--lez ` (a v0.3 or v0.4 tag, see [LEZ v0.4](#lez-v04)), `--port`, `--block-time`, `--max-txs-per-block`, `--dev-mode` and `--log-filter`, and remembers them. `--rebuild` builds the image or binaries again. | | `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, 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 [amount]` | Sends lepta from the faucet to a public account, 10B by default. | +| `fund [amount] [--key ]` | Sends lepta from the faucet to a public account, 10B by default. On LEZ v0.4, an account that was never used takes its public key too. | | `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. | | `env` | Prints the env file. | @@ -83,6 +83,7 @@ block_time = "1s" max_txs_per_block = 100 dev_mode = true # fake proofs: private calls take a second log_filter = "info,sequencer_core=debug" # the sequencer's RUST_LOG, for `logs` +upstream_accounts = true # also fund LEZ's own genesis accounts on a new chain, for its examples [programs] # name = guest binary, relative to this file counter = "target/riscv32im-risc0-zkvm-elf/docker/counter.bin" @@ -119,7 +120,7 @@ Group names follow the rules for program names, and can't end in `-wallet`. A gr { "amount": 5000000000, "accounts": [ - { "index": 0, "id": "CfcghzvosNM114Akg71vuQyDApHPYpPVC9p4uPFQygye", "hex": "ad54f9c3…" } + { "index": 0, "id": "CfcghzvosNM114Akg71vuQyDApHPYpPVC9p4uPFQygye", "hex": "ad54f9c3…", "key": "57f54786…" } ] } ``` @@ -148,7 +149,7 @@ For a wallet, give it its own directory. `wallet-config` refuses a directory tha ## Sessions -A session is a throwaway `logosctl` session wired to the devnet, for an app or an agent that talks to Logos through `logosctl`. You need `logosctl` on your `PATH`. +A session is a throwaway `logosctl` session wired to the devnet, for an app or an agent that talks to Logos through `logosctl`. You need `logosctl` on your `PATH`. Sessions run on LEZ v0.3 only for now: see [LEZ v0.4](#lez-v04). ```bash logos-devnet session new alice # lez_core and a funded wallet @@ -212,7 +213,7 @@ Sessions need nothing passed in: logos-devnet configures their storage before it ## What runs -LEZ's own `sequencer_service` runs, built with two features. `standalone` replaces Bedrock, the L1, with an in-process mock that accepts every block. `prove` runs programs in-process, so you don't need `r0vm`. The default is `v0.3.1`. `--lez` picks another `v0.3` tag, and a chain only runs one tag: `reset --lez ` to switch. LEZ `v0.4` changes the sequencer's config and commands, and isn't supported yet. +LEZ's own `sequencer_service` runs, built with two features. `standalone` replaces Bedrock, the L1, with an in-process mock that accepts every block. `prove` runs programs in-process, so you don't need `r0vm`. The default is `v0.3.1`, what the public testnet runs. `--lez` picks another `v0.3` tag or a `v0.4` one, and a chain only runs one tag: `reset --lez ` to switch. | | devnet | testnet | | --- | --- | --- | @@ -222,10 +223,23 @@ LEZ's own `sequencer_service` runs, built with two features. `standalone` replac | Block timestamp | your clock | the sequencer's clock | | L1 finality, indexer | none | yes | -Fees are the testnet's. Every call holds `gas_limit × base fee` up front, plus a little for its size, so about 1.6M lepta at a `gas_limit` of 200,000. The faucet makes that irrelevant. +Fees are the testnet's. On v0.3 every call holds `gas_limit × base fee` up front, plus a little for its size, so about 1.6M lepta at a `gas_limit` of 200,000. v0.4 measures each call's gas instead. The faucet makes that irrelevant. Private calls still prove on your machine, so they take as long as on the testnet: a shielded transfer from a session took 118 s on an Apple M-series laptop. Dev mode skips that. +## LEZ v0.4 + +`reset --lez v0.4.0-rc3`, or `lez = "v0.4.0-rc3"` under `[devnet]`, runs LEZ v0.4. It's a release candidate: v0.4.0 isn't tagged yet, and the testnet still runs v0.3. On v0.4: + +- The first `up` builds the sequencer image for that tag, which takes a while: no image is published for v0.4 yet. +- The chain is set up with `sequencer_service setup`, as LEZ's own local recipe does, then started from its home. +- A v0.4 wallet can't read v0.3 storage, so v0.4 has its own dev wallet and account groups, in `wallet-v0.4/` and `accounts-v0.4/`, and so its own program ids. Switching back with `reset --lez v0.3.1` finds the v0.3 ones as they were. +- Programs must be built for v0.4: a v0.3 binary doesn't run there. +- Genesis funds accounts by their public key, which `accounts.json` records for each account. +- An account that was never used is paid only by its public key: `fund --key `. Group accounts are paid by theirs. +- Sessions aren't supported yet: the Logos catalog has no `lez_core` for v0.4, and 0.5.1 can't drive a v0.4 chain. `up` refuses `[sessions]` on v0.4. +- `upstream_accounts = true` under `[devnet]` keeps LEZ's own genesis accounts funded, whose keys LEZ publishes for its examples and tools. + ## Dev mode `up --dev-mode`, or `dev_mode = true` under `[devnet]`, runs the chain with `RISC0_DEV_MODE=1`: provers make fake proofs and the sequencer accepts them. The same transfer lands in 1 s. @@ -243,11 +257,11 @@ Everything is in `~/.logos-devnet` (or `LOGOS_DEVNET_HOME`): | `settings.json` | LEZ tag, runtime, port, block time, transactions per block, dev mode, log filter, faucet | | `env` | the env file | | `chain/` | the sequencer's config, database and keys, and whether the chain runs in dev mode. `reset` deletes it. | -| `wallet/` | the dev wallet: the faucet and each program's header key. Kept across resets. | +| `wallet/` | the dev wallet: the faucet and each program's header key. Kept across resets. `wallet-v0.4/` is LEZ v0.4's | | `compose.yaml` | the Docker runtime's compose file | | `native/` | the native runtime's LEZ checkout, build, log and pid file | | `sessions/` | one directory per session: its `logosctl` home, its daemon's `HOME` with its storage, wallet and `session.json` | -| `accounts/` | one directory per account group: its wallet and `accounts.json` | +| `accounts/` | one directory per account group: its wallet and `accounts.json`. `accounts-v0.4/` holds LEZ v0.4's | | `programs.json` | the binary hash each program was deployed from | | `downloads/` | program binaries the project file names by URL, by SHA-256, and in `packages/` the module packages every daemon installs from, downloaded once and checked against the catalog's SHA-256. Every home uses the one in `~/.logos-devnet`, so a project's own home or a worktree's doesn't download them again. One left in another home from before v0.9.0 can be deleted | | `messaging/` | the hub, for `[messaging]` and `[storage]`: its `logosctl` home, its daemon's `HOME`, message store, ports and node keys in `hub.json` | @@ -279,7 +293,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.4 +- uses: drptbl/logos-devnet@v0.10.0 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 diff --git a/skills/logos-devnet/SKILL.md b/skills/logos-devnet/SKILL.md index 7051586..e3934b0 100644 --- a/skills/logos-devnet/SKILL.md +++ b/skills/logos-devnet/SKILL.md @@ -9,7 +9,7 @@ description: logos-devnet runs a local LEZ (Logos Execution Zone) chain. Use whe ## Before you start -- **logos-devnet 0.9.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). +- **logos-devnet 0.10.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. @@ -52,6 +52,7 @@ Pass `--json` to every command: on success stdout holds one JSON document, and n ## Choices - **Home.** Without `home`, every project on the machine shares `~/.logos-devnet` on port 3040, and `up` refuses settings that disagree with what other projects run there. Tests, worktrees and parallel agents get `home = ".logos-devnet"` and `[devnet] port = 0`, a free port of their own. +- **LEZ line.** v0.3 (default `v0.3.1`) is what the testnet runs. `lez = "v0.4.0-rc3"` runs the v0.4 release candidate: programs built for v0.4, its own dev wallet and program ids, funding by public key (`accounts.json` records each account's `key`), and no sessions yet. `upstream_accounts = true` keeps LEZ's own published genesis accounts funded for its examples. - **Dev mode.** `dev_mode = true` makes private calls prove in about 1 s instead of about 2 min, with fake proofs. A chain keeps its dev mode for life: switching it takes `reset`. Use a chain without dev mode to check that real proofs verify. - **Programs.** A program can be a path, or a release: `{ url = "...", sha256 = "..." }`, downloaded once and deployed only if its SHA-256 matches. Programs deploy immutable, which undisclosed private calls require. While iterating on one, give it `{ path = "...", mutable = true }`: a rebuild then updates it in place with the same id on the next `up`. Its mutability is fixed per chain, so changing it takes `reset`. `.logos-devnet/programs.json` records each deployed program's binary SHA-256 and mutability: compare it with `shasum -a 256 ` to show which build runs. - **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. @@ -74,7 +75,9 @@ Each refusal changes nothing. `up` prefixes a program's refusal with `program is deployed mutable, asked for immutable` (or the reverse) | Put `mutable` back as deployed, or `reset`. | | `this chain runs in dev mode` / `this chain checks proofs` | Match the chain's dev mode, or `reset --dev-mode` / `reset --dev-mode false`. | | `this chain runs LEZ ` | `reset --lez `. | -| `logos-devnet runs LEZ v0.3 tags` | Use a v0.3 tag, e.g. `--lez v0.3.1`. LEZ v0.4 isn't supported yet. | +| `logos-devnet runs LEZ v0.3 and v0.4 tags` | Use a v0.3 tag, e.g. `--lez v0.3.1`, or a v0.4 one, e.g. `v0.4.0-rc3`. | +| `sessions don't run on LEZ v0.4 yet` | Drop `[sessions]` and `session rm` any session, or stay on v0.3: no `lez_core` for v0.4 is published. | +| ` has never been used, and LEZ v0.4 pays such an account only by its public key` | `fund --key `, with the key `wallet account new public` printed. | | `the shared devnet runs with ..., but asks for ...` | Other projects use that devnet. Give this project its own `home` and port. | | `port on 127.0.0.1 is taken` | `up --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]`. | diff --git a/src/home.rs b/src/home.rs index 43f28d5..d5587cb 100644 --- a/src/home.rs +++ b/src/home.rs @@ -6,6 +6,7 @@ //! env export lines for projects (see envfile) //! chain/ the sequencer's home: its config, database and keys. `reset` deletes it. //! wallet/ the dev wallet: the faucet and each program's header key. Kept across resets. +//! LEZ v0.4's is `wallet-v0.4/`, and its account groups `accounts-v0.4/` //! compose.yaml the Docker runtime's compose file //! native/ the native runtime's checkout, build, log and pid file //! sessions/ throwaway logosctl sessions with devnet wallets (see session) From 7d68b661e6b54051568da960f4d0c5c7075f159d Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:47:50 +0000 Subject: [PATCH 13/28] chore: bump the version to 0.10.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- examples/github-actions/devnet.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef8cc90..27860dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -566,7 +566,7 @@ checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" [[package]] name = "logos-devnet" -version = "0.9.4" +version = "0.10.0" dependencies = [ "anyhow", "bs58", diff --git a/Cargo.toml b/Cargo.toml index 4087c3d..93b30bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "logos-devnet" -version = "0.9.4" +version = "0.10.0" edition = "2024" rust-version = "1.89" description = "A local LEZ chain for Logos development: one command to start it, fund accounts and deploy programs" diff --git a/examples/github-actions/devnet.yml b/examples/github-actions/devnet.yml index 3d7c6d9..60273fa 100644 --- a/examples/github-actions/devnet.yml +++ b/examples/github-actions/devnet.yml @@ -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.4 + uses: drptbl/logos-devnet@v0.10.0 - run: cargo test - name: The devnet's logs if: failure() From 94e244b668c8fff930591f19dbb5df66165b496b Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:59:22 +0000 Subject: [PATCH 14/28] build: skip prover kernels only for v0.3 v0.3 builds stay as they were. Only v0.4's sequencer links the wallet whose prover needs the kernels. The native config lookup is renamed to find_upstream_config, as it finds v0.4's local.json too. --- docker/Dockerfile | 8 +++++--- src/runtime/native.rs | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 7160692..9e268a7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,8 +6,9 @@ # docker build --build-arg LEZ_TAG=v0.3.1 -t ghcr.io/drptbl/logos-devnet-sequencer:v0.3.1 - < docker/Dockerfile # # `standalone` replaces Bedrock with an in-process mock, and `prove` runs guests in-process, so -# the image needs neither a Bedrock node nor r0vm. risc0's CPU kernels are built too: from LEZ -# v0.4 the sequencer links the wallet, whose prover needs them. +# the image needs neither a Bedrock node nor r0vm. For v0.3, RISC0_SKIP_BUILD_KERNELS skips the +# prover kernels the sequencer never runs. From LEZ v0.4 the sequencer links the wallet, whose +# prover needs them, so they're built. FROM rust:1-slim-trixie AS build ARG LEZ_TAG @@ -25,7 +26,8 @@ WORKDIR /lez RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/lez/target,sharing=locked \ - cargo build --release --features "$FEATURES" -p sequencer_service \ + case "$LEZ_TAG" in v0.3.*) export RISC0_SKIP_BUILD_KERNELS=1 ;; esac \ + && cargo build --release --features "$FEATURES" -p sequencer_service \ && cargo build --release -p wallet \ && mkdir -p /out \ && cp target/release/sequencer_service target/release/wallet /out/ \ diff --git a/src/runtime/native.rs b/src/runtime/native.rs index f2cce67..289abdd 100644 --- a/src/runtime/native.rs +++ b/src/runtime/native.rs @@ -114,14 +114,18 @@ impl Runtime for Native { .args(["build", "--release", "-p", package]); cmd }; - // Two builds, so `prove` stays out of the wallet binary. risc0's CPU kernels are built - // too: from LEZ v0.4 the sequencer links the wallet, whose prover needs them. - run_building(cargo("sequencer_service").args(["--features", SEQUENCER_FEATURES]))?; + // Two builds, so `prove` stays out of the wallet binary. v0.3 skips the prover kernels + // the sequencer never runs; from v0.4 it links the wallet, whose prover needs them. + let mut sequencer = cargo("sequencer_service"); + if self.settings.line() == LezLine::V03 { + sequencer.env("RISC0_SKIP_BUILD_KERNELS", "1"); + } + run_building(sequencer.args(["--features", SEQUENCER_FEATURES]))?; run_building(&mut cargo("wallet")) } fn upstream_config(&self) -> Result { - let path = find_debug_config(&self.src()).context( + let path = find_upstream_config(&self.src()).context( "the LEZ checkout has no sequencer/service/configs/debug/sequencer_config.json \ or sequencer/service/networks/local.json", )?; @@ -273,7 +277,7 @@ fn runs(command: &str, bin: &Path) -> bool { } /// Upstream's debug sequencer config, wherever this tag keeps it. -fn find_debug_config(dir: &Path) -> Option { +fn find_upstream_config(dir: &Path) -> Option { let mut stack = vec![(dir.to_path_buf(), 0)]; while let Some((dir, depth)) = stack.pop() { // v0.3's debug config, or v0.4's local one. @@ -344,7 +348,7 @@ mod tests { let debug = dir.path().join(layout).join("configs/debug"); std::fs::create_dir_all(&debug).unwrap(); std::fs::write(debug.join("sequencer_config.json"), "{}").unwrap(); - let found = find_debug_config(dir.path()).unwrap(); + let found = find_upstream_config(dir.path()).unwrap(); assert_eq!(found, debug.join("sequencer_config.json"), "{layout}"); } } @@ -357,7 +361,7 @@ mod tests { std::fs::write(networks.join("testnet.json"), "{}").unwrap(); std::fs::write(networks.join("local.json"), "{}").unwrap(); assert_eq!( - find_debug_config(dir.path()).unwrap(), + find_upstream_config(dir.path()).unwrap(), networks.join("local.json") ); } @@ -368,6 +372,6 @@ mod tests { let debug = dir.path().join("target/sequencer/service/configs/debug"); std::fs::create_dir_all(&debug).unwrap(); std::fs::write(debug.join("sequencer_config.json"), "{}").unwrap(); - assert!(find_debug_config(dir.path()).is_none()); + assert!(find_upstream_config(dir.path()).is_none()); } } From 06878c0556f5238da9c46f95ca1b2ceaf24f5c84 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:59:22 +0000 Subject: [PATCH 15/28] fix: read the faucet's key from its wallet The key was kept in the settings, shared by both lines, so switching to v0.3 and back lost it and the next v0.4 genesis couldn't be built. The wallet's storage holds every account's key, so it's read from there, and fund uses the keys of the devnet's own accounts. Group keys are checked against their ids before use. --- src/devnet.rs | 79 +++++++++++++++++++------------------------ src/groups.rs | 29 ++++++++++++++++ src/home.rs | 5 --- src/wallet_storage.rs | 65 +++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 49 deletions(-) diff --git a/src/devnet.rs b/src/devnet.rs index ffaa0af..7a3f51c 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -368,7 +368,7 @@ impl Devnet { } next.runtime.prepare(opts.rebuild)?; - let (faucet, faucet_key) = next.dev_faucet()?; + let faucet = next.dev_faucet()?; if continuing && funds_another_faucet(self.settings.faucet.as_ref(), &faucet) { bail!( "this chain's genesis funds another faucet than the dev wallet holds. \ @@ -376,7 +376,6 @@ impl Devnet { ); } next.settings.faucet = Some(faucet); - next.settings.faucet_key = faucet_key; // Keys first, so a new chain funds every group at genesis. next.make_project_groups()?; let config = next.chain_config()?; @@ -742,7 +741,7 @@ impl Devnet { group.name ); for account in unfunded { - self.send(&account.id, account.key.as_deref(), u128::from(info.amount))?; + self.send(&account.id, account.checked_key()?, u128::from(info.amount))?; } } Ok(()) @@ -753,11 +752,13 @@ impl Devnet { let mut accounts = Vec::new(); for group in groups::list(&self.groups_dir())? { let info = group.info()?; - accounts.extend(info.accounts.into_iter().map(|a| Funded { - id: a.id, - key: a.key, - balance: info.amount, - })); + for account in &info.accounts { + accounts.push(Funded { + key: account.checked_key()?.map(str::to_owned), + id: account.id.clone(), + balance: info.amount, + }); + } } Ok(accounts) } @@ -884,22 +885,25 @@ impl Devnet { self.rpc().balance(to) } - /// The dev wallet's faucet account, made on first use, with its public key when known. - /// Read from the wallet rather than the settings, so a lost settings file finds the same - /// faucet. The wallet prints the key only when it makes the account, so it's kept in the - /// settings, and used only while it still matches the faucet. - fn dev_faucet(&self) -> Result<(PublicId, Option)> { + /// The dev wallet's faucet account, made on first use. Read from the wallet rather than + /// the settings, so a lost settings file finds the same faucet. + fn dev_faucet(&self) -> Result { match self.labelled_account(FAUCET_LABEL)? { - Some(faucet) => { - let key = self - .settings - .faucet_key - .clone() - .filter(|key| PublicId::of_key(key).is_ok_and(|id| id == faucet)); - Ok((faucet, key)) + Some(faucet) => Ok(faucet), + None => self.new_account(Some(FAUCET_LABEL)), + } + } + + /// The public key of `id` when logos-devnet holds it: a group account's, or one in the dev + /// wallet, such as the faucet. Read where the key lives, so it can't drift from it. + fn known_key(&self, id: &PublicId) -> Result> { + for group in groups::list(&self.groups_dir())? { + if let Some(account) = group.info()?.accounts.iter().find(|a| &a.id == id) { + return Ok(account.checked_key()?.map(str::to_owned)); } - None => self.new_keyed_account(FAUCET_LABEL), } + let storage = self.wallet_dir().join(crate::wallet_storage::STORAGE_FILE); + crate::wallet_storage::public_key(&storage, id) } /// Sets a new LEZ v0.4 chain up from `config`: `setup` writes its channel signing key and @@ -920,9 +924,10 @@ impl Devnet { fn chain_config(&self) -> Result { let genesis_accounts = self.genesis_accounts()?; + let faucet = self.faucet()?; let faucet = Funded { - id: self.faucet()?.clone(), - key: self.settings.faucet_key.clone(), + key: self.known_key(faucet)?, + id: faucet.clone(), balance: FAUCET_BALANCE, }; chain_config::patch( @@ -1113,17 +1118,22 @@ impl Devnet { // Fails before any work when there is no faucet yet. self.faucet()?; self.require_running()?; + let key = match key { + Some(key) => Some(key.to_owned()), + None => self.known_key(&to)?, + }; if self.settings.line() == LezLine::V04 && key.is_none() && !self.rpc().account_in_use(&to)? { bail!( "{} has never been used, and LEZ v0.4 pays such an account only by its public \ - key: pass it with `--key `, as `wallet account new public` printed it", + key: pass it with `--key `, as `wallet account new public` printed it or \ + `wallet account get --keys` prints it", to.wallet_form() ); } - let balance = self.send(&to, key, amount)?; + let balance = self.send(&to, key.as_deref(), amount)?; Ok(Balance { account: to.wallet_form(), balance: Some(balance), @@ -1482,25 +1492,6 @@ impl Devnet { } } - /// A new labelled account and its public key, as `account new public` prints it once. - fn new_keyed_account(&self, label: &str) -> Result<(PublicId, Option)> { - let output = self.wallet(vec![ - "account".into(), - "new".into(), - "public".into(), - "--label".into(), - label.into(), - ])?; - let id = first_public_id(&output) - .with_context(|| format!("the wallet made no account:\n{output}"))?; - let key = output - .lines() - .find_map(|line| line.trim().strip_prefix("With pk ")) - .map(|key| key.trim().to_owned()) - .filter(|key| PublicId::of_key(key).is_ok_and(|of| of == id)); - Ok((id, key)) - } - fn new_account(&self, label: Option<&str>) -> Result { let mut args: Vec = vec!["account".into(), "new".into(), "public".into()]; if let Some(label) = label { diff --git a/src/groups.rs b/src/groups.rs index 73d82d9..34d3298 100644 --- a/src/groups.rs +++ b/src/groups.rs @@ -71,6 +71,21 @@ pub struct GroupAccount { pub key: Option, } +impl GroupAccount { + /// Its public key, once checked to name this account: genesis and payments by key would + /// otherwise fund another. `None` for an account from before keys were kept. + pub fn checked_key(&self) -> Result> { + match &self.key { + Some(key) if PublicId::of_key(key)? != self.id => anyhow::bail!( + "{} has a public key in accounts.json that names another account: delete its \ + group, and `up` makes it again", + self.id.wallet_form() + ), + key => Ok(key.as_deref()), + } + } +} + #[derive(Debug, Clone)] pub struct Group { pub name: String, @@ -169,6 +184,20 @@ mod tests { const A: &str = "HpavNGFYxjyhLsy171aXsvv146yUeXmRWiho22uvT43d"; const B: &str = "6YvesSEDWW25kpi8SSki2c8o5m3uACsigvGnNQ6wMruh"; + #[test] + fn trusts_a_recorded_key_only_when_it_names_its_account() { + let secret = "01".repeat(32); + let key = crate::account::public_key_of(&secret).unwrap(); + let id = PublicId::of_key(&key).unwrap(); + let info = Group::extended(GroupInfo::default(), vec![(id, key.clone())]); + assert_eq!(info.accounts[0].checked_key().unwrap(), Some(key.as_str())); + let wrong = Group::extended( + GroupInfo::default(), + vec![(PublicId::parse(A).unwrap(), key)], + ); + assert!(wrong.accounts[0].checked_key().is_err()); + } + #[test] fn numbers_new_accounts_after_the_existing_ones() { let one = Group::extended( diff --git a/src/home.rs b/src/home.rs index d5587cb..3d2acb0 100644 --- a/src/home.rs +++ b/src/home.rs @@ -107,10 +107,6 @@ pub struct Settings { /// The dev wallet's faucet account, funded at genesis. Created on the first `up`. #[serde(default, skip_serializing_if = "Option::is_none")] pub faucet: Option, - /// The faucet's public key, in hex, which a LEZ v0.4 genesis funds by. The wallet prints it - /// only when it makes the account. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub faucet_key: Option, } impl Default for Settings { @@ -124,7 +120,6 @@ impl Default for Settings { dev_mode: false, log_filter: DEFAULT_LOG_FILTER.into(), faucet: None, - faucet_key: None, } } } diff --git a/src/wallet_storage.rs b/src/wallet_storage.rs index b913a70..426ebe3 100644 --- a/src/wallet_storage.rs +++ b/src/wallet_storage.rs @@ -163,6 +163,38 @@ pub fn forget_chain_in(storage: &Path) -> Result<()> { } } +/// The public key, in hex, of the public account `id` in the wallet whose storage is at +/// `storage`: as written for an account the wallet made, or derived from an imported one's +/// private key. Only a key that names `id` counts. `None` when the wallet holds no such account. +pub fn public_key(storage: &Path, id: &crate::account::PublicId) -> Result> { + use crate::account::{PublicId, public_key_of}; + let text = match std::fs::read_to_string(storage) { + Ok(text) => text, + Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None), + Err(e) => return Err(e).with_context(|| format!("reading {}", storage.display())), + }; + let wallet: serde_json::Value = serde_json::from_str(&text) + .with_context(|| format!("{} is not a LEZ wallet storage", storage.display()))?; + let accounts = wallet["key_chain"]["accounts"] + .as_array() + .into_iter() + .flatten(); + for account in accounts { + let key = if account["Public"]["account_id"] == id.as_str() { + account["Public"]["data"]["pk"].as_str().map(str::to_owned) + } else if account["ImportedPublic"]["account_id"] == id.as_str() { + account["ImportedPublic"]["pub_sign_key"] + .as_str() + .map(public_key_of) + .transpose()? + } else { + continue; + }; + return Ok(key.filter(|key| PublicId::of_key(key).is_ok_and(|of| &of == id))); + } + Ok(None) +} + /// Replaces `path` with `contents` in one step, keeping its permissions: it never holds half of /// either, and the new file is on disk before it takes the old one's place. fn replace_file(path: &Path, contents: &[u8]) -> std::io::Result<()> { @@ -292,6 +324,39 @@ pub(crate) mod tests { assert!(!nullifiers.exists()); } + #[test] + fn reads_an_accounts_public_key_from_the_wallet() { + let dir = tempfile::tempdir().unwrap(); + let storage = dir.path().join(STORAGE_FILE); + // As LEZ's wallet writes them: a generated account keeps its key as `pk`, an imported + // one its private key as `pub_sign_key`. + let made = "4afc5da3b6acabc4892dddb1e49226599326ae3a6a700828e395b5bc9a4b30ba"; + let text = format!( + r#"{{"key_chain":{{"accounts":[ + {{"Public":{{"account_id":"23cbN9uZbLU1zhcuiZ1qu1eneL8ed8HeHzDEF1br6rEd","chain_index":[0],"data":{{"sk":"x","pk":"{made}"}}}}}}, + {{"ImportedPublic":{{"account_id":"B1UN3hPgxacgHKBRoThcAmsPajGcUf6YXUhgB36x4DAd","pub_sign_key":"{}"}}}} + ]}},"last_synced_block":1}}"#, + "01".repeat(32) + ); + std::fs::write(&storage, text).unwrap(); + let key = |id: &str| public_key(&storage, &crate::account::PublicId::parse(id).unwrap()); + assert_eq!( + key("23cbN9uZbLU1zhcuiZ1qu1eneL8ed8HeHzDEF1br6rEd") + .unwrap() + .as_deref(), + Some(made) + ); + let imported = key("B1UN3hPgxacgHKBRoThcAmsPajGcUf6YXUhgB36x4DAd").unwrap(); + assert_eq!( + imported, + Some(crate::account::public_key_of(&"01".repeat(32)).unwrap()) + ); + assert_eq!( + key("HpavNGFYxjyhLsy171aXsvv146yUeXmRWiho22uvT43d").unwrap(), + None + ); + } + #[test] fn forgetting_a_chain_adds_nothing_and_refuses_a_layout_it_doesnt_know() { let bare = r#"{"key_chain":{"accounts":[]},"last_synced_block":9}"#; From a9d55d52d3dbf36efa58d6165b64a55e94167ce8 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:59:30 +0000 Subject: [PATCH 16/28] fix: keep sessions per LEZ line A v0.3 session's wallet and lez_core can't work on v0.4, so v0.4 has its own sessions directory, and v0.3's wait as they were. Only a project asking for sessions on v0.4 is refused, by up and doctor. --- src/devnet.rs | 46 +++++++++++++++++++++++++++------------------- src/doctor.rs | 8 ++++++++ src/home.rs | 17 +++++++++++++++-- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/devnet.rs b/src/devnet.rs index 7a3f51c..dd360b2 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -35,7 +35,7 @@ pub const DEFAULT_FUND: u64 = 10_000_000_000; /// Why sessions don't run on LEZ v0.4 yet. const SESSIONS_ON_V04: &str = "sessions don't run on LEZ v0.4 yet: the Logos catalog has no \ lez_core for v0.4, and lez_core 0.5.1 can't drive a v0.4 chain. Drop [sessions] from the \ - project file and `logos-devnet session rm` any session, or stay on v0.3"; + project file, or stay on v0.3, whose sessions wait as they were"; /// How `up` waits for a starting sequencer's first block. A long chain replays first, logging /// a different line for each block (186k blocks took 34 min), so `up` waits as long as the log @@ -301,6 +301,11 @@ impl Devnet { self.home.groups_dir(self.settings.line()) } + /// The sessions of the chain's LEZ line. + fn sessions_dir(&self) -> PathBuf { + self.home.sessions_dir(self.settings.line()) + } + fn faucet(&self) -> Result<&PublicId> { self.settings .faucet @@ -481,13 +486,7 @@ impl Devnet { self.runtime.check_wallet_file(&binary)?; } } - if self.settings.line() == LezLine::V04 - && (!self.sessions().is_empty() - || self - .project - .as_ref() - .is_some_and(|p| !p.sessions.is_empty())) - { + if self.refuses_sessions() { bail!("{SESSIONS_ON_V04}"); } if self.needs_logosctl() && !logosctl_on_path() { @@ -501,6 +500,15 @@ impl Devnet { self.check_hub_ports() } + /// Whether the project asks for sessions on LEZ v0.4, which can't run them yet. + pub fn refuses_sessions(&self) -> bool { + self.settings.line() == LezLine::V04 + && self + .project + .as_ref() + .is_some_and(|p| !p.sessions.is_empty()) + } + /// Fails when a port the hub keeps is taken while the hub doesn't run, so `up` couldn't /// start it there. pub fn check_hub_ports(&self) -> Result<()> { @@ -611,7 +619,7 @@ impl Devnet { } if let Some(project) = &self.project { for (name, spec) in &project.sessions { - let session = Session::new(&self.home.sessions_dir(), name)?; + let session = Session::new(&self.sessions_dir(), name)?; if session.exists() { match self.add_session_modules(&session, &spec.modules) { Ok(added) if !added.is_empty() => { @@ -862,7 +870,7 @@ impl Devnet { /// The sessions, or none (with a note) when their directory can't be read. fn sessions(&self) -> Vec { - session::list(&self.home.sessions_dir()).unwrap_or_else(|e| { + session::list(&self.sessions_dir()).unwrap_or_else(|e| { eprintln!("sessions: {e:#}"); Vec::new() }) @@ -1186,7 +1194,7 @@ impl Devnet { /// from the catalog, a devnet wallet opened in it, and a public account funded with /// `amount`. A failed attempt leaves nothing behind. pub fn session_new(&self, name: &str, extra: &[String], amount: u128) -> Result { - let session = Session::new(&self.home.sessions_dir(), name)?; + let session = Session::new(&self.sessions_dir(), name)?; if session.exists() { bail!("session {name} exists. `logos-devnet session rm {name}` first"); } @@ -1316,7 +1324,7 @@ impl Devnet { pub fn session_list(&self) -> Result { let chain_up = self.runtime.running(); - let rows = session::list(&self.home.sessions_dir())? + let rows = session::list(&self.sessions_dir())? .into_iter() .map(|session| { let running = session.logosctl().answers_within(SESSION_CHECK_TIMEOUT); @@ -1404,7 +1412,7 @@ impl Devnet { } fn existing_session(&self, name: &str) -> Result { - let session = Session::new(&self.home.sessions_dir(), name)?; + let session = Session::new(&self.sessions_dir(), name)?; if !session.exists() { bail!("no session {name}. `logos-devnet session ls` lists them"); } @@ -2150,14 +2158,14 @@ 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}"); - let alice = devnet.home.sessions_dir().join("alice"); + let alice = devnet.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(); + std::fs::create_dir_all(devnet.sessions_dir().join("bob")).unwrap(); let err = devnet .session_restart(&["alice".into(), "bob".into()]) .unwrap_err(); @@ -2246,7 +2254,7 @@ mod tests { let devnet = devnet_in(&dir.path().join("home")); assert!(devnet.sessions_not_running().is_empty()); for name in ["bob", "alice"] { - std::fs::create_dir_all(devnet.home.sessions_dir().join(name)).unwrap(); + std::fs::create_dir_all(devnet.sessions_dir().join(name)).unwrap(); } assert_eq!(devnet.sessions_not_running(), ["alice", "bob"]); // After `down`, a stopped daemon is no news. @@ -2259,7 +2267,7 @@ mod tests { let devnet = devnet_in(&dir.path().join("home")); assert!(devnet.daemon_logs().is_empty()); for name in ["bob", "alice"] { - std::fs::create_dir_all(devnet.home.sessions_dir().join(name)).unwrap(); + std::fs::create_dir_all(devnet.sessions_dir().join(name)).unwrap(); } std::fs::create_dir_all(devnet.home.messaging_dir()).unwrap(); let logs = devnet.daemon_logs(); @@ -2365,7 +2373,7 @@ mod tests { assert!(err.to_string().contains("no hub"), "{err}"); let err = devnet.logs(false, Some("alice"), false).unwrap_err(); assert!(err.to_string().contains("no session alice"), "{err}"); - std::fs::create_dir_all(devnet.home.sessions_dir().join("alice")).unwrap(); + std::fs::create_dir_all(devnet.sessions_dir().join("alice")).unwrap(); let err = devnet.logs(false, Some("alice"), false).unwrap_err(); assert!(err.to_string().contains("hasn't started"), "{err}"); } @@ -2540,7 +2548,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); // No project file: the session was made with `session new`. - std::fs::create_dir_all(home.sessions_dir().join("alice")).unwrap(); + std::fs::create_dir_all(home.sessions_dir(LezLine::V03).join("alice")).unwrap(); let devnet = Devnet::open(home, None).unwrap(); let err = devnet.check_needs(|| false).unwrap_err(); assert!(format!("{err:#}").contains("logosctl"), "{err:#}"); diff --git a/src/doctor.rs b/src/doctor.rs index ff23099..ef9b366 100644 --- a/src/doctor.rs +++ b/src/doctor.rs @@ -195,6 +195,14 @@ pub fn run(devnet: &Devnet, project_error: Option<&anyhow::Error>) -> Doctor { } } + if devnet.refuses_sessions() { + checks.push(fail( + "sessions", + "the project asks for sessions, which don't run on LEZ v0.4 yet", + "drop [sessions] from the project file, or stay on v0.3", + )); + } + if devnet.wants_hub() { checks.push(match devnet.check_hub_ports() { Ok(()) => pass("hub ports", "free, or held by the running hub"), diff --git a/src/home.rs b/src/home.rs index 3d2acb0..cc955a8 100644 --- a/src/home.rs +++ b/src/home.rs @@ -271,8 +271,13 @@ impl Home { pub fn native_dir(&self) -> PathBuf { self.root.join("native") } - pub fn sessions_dir(&self) -> PathBuf { - self.root.join("sessions") + /// Sessions, one set per LEZ line like the dev wallet: a v0.3 session's wallet and + /// `lez_core` can't work on v0.4, and stay as they were for a return to v0.3. + pub fn sessions_dir(&self, line: LezLine) -> PathBuf { + self.root.join(match line { + LezLine::V03 => "sessions", + LezLine::V04 => "sessions-v0.4", + }) } /// Account groups, each with a wallet: one set per LEZ line, like the dev wallet. pub fn groups_dir(&self, line: LezLine) -> PathBuf { @@ -434,6 +439,14 @@ mod tests { home.groups_dir(LezLine::V04), home.root().join("accounts-v0.4") ); + assert_eq!( + home.sessions_dir(LezLine::V03), + home.root().join("sessions") + ); + assert_eq!( + home.sessions_dir(LezLine::V04), + home.root().join("sessions-v0.4") + ); } #[test] From d4b906f895441e094090a62c3fc7970e874e56a2 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:59:30 +0000 Subject: [PATCH 17/28] fix: mark a v0.4 chain set up by its funding key setup writes the channel key first, so a setup that stopped right after left a chain that up never set up again. --- src/home.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/home.rs b/src/home.rs index cc955a8..c9ab09d 100644 --- a/src/home.rs +++ b/src/home.rs @@ -236,9 +236,10 @@ impl Home { pub fn setup_template(&self) -> PathBuf { self.chain_dir().join("setup-template.json") } - /// Whether a LEZ v0.4 chain here has been set up: `setup` makes its channel signing key. + /// Whether a LEZ v0.4 chain here has been set up. `setup` writes its channel signing key, + /// then this file, then the config, which `up` writes again anyway. pub fn chain_set_up(&self) -> bool { - self.chain_dir().join("channel_signing_key").exists() + self.chain_dir().join("bedrock_funding_public_key").exists() } /// The chain's own record of its dev mode, which `reset` deletes with it. fn chain_dev_mode_file(&self) -> PathBuf { @@ -424,6 +425,18 @@ mod tests { assert_eq!(LezLine::of(DEFAULT_LEZ).unwrap(), LezLine::V03); } + #[test] + fn a_v0_4_chain_is_set_up_once_setup_wrote_its_funding_key() { + let dir = tempfile::tempdir().unwrap(); + let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); + std::fs::create_dir_all(home.chain_dir()).unwrap(); + // `setup` writes the channel key first: stopped there, it must run again. + std::fs::write(home.chain_dir().join("channel_signing_key"), "k").unwrap(); + assert!(!home.chain_set_up()); + std::fs::write(home.chain_dir().join("bedrock_funding_public_key"), "f").unwrap(); + assert!(home.chain_set_up()); + } + #[test] fn each_lez_line_keeps_its_own_wallets() { let dir = tempfile::tempdir().unwrap(); From 790754f806973c11534cbbcfcc67d20da706dede Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Fri, 20 Nov 2026 23:59:30 +0000 Subject: [PATCH 18/28] docs: correct v0.4 notes from review --- README.md | 6 +++--- skills/logos-devnet/SKILL.md | 2 +- src/devnet.rs | 4 ++-- src/rpc.rs | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e1677dd..101ebde 100644 --- a/README.md +++ b/README.md @@ -236,8 +236,8 @@ Private calls still prove on your machine, so they take as long as on the testne - A v0.4 wallet can't read v0.3 storage, so v0.4 has its own dev wallet and account groups, in `wallet-v0.4/` and `accounts-v0.4/`, and so its own program ids. Switching back with `reset --lez v0.3.1` finds the v0.3 ones as they were. - Programs must be built for v0.4: a v0.3 binary doesn't run there. - Genesis funds accounts by their public key, which `accounts.json` records for each account. -- An account that was never used is paid only by its public key: `fund --key `. Group accounts are paid by theirs. -- Sessions aren't supported yet: the Logos catalog has no `lez_core` for v0.4, and 0.5.1 can't drive a v0.4 chain. `up` refuses `[sessions]` on v0.4. +- An account that was never used is paid only by its public key: `fund --key `. The devnet's own accounts, its groups' and the dev wallet's, are paid by theirs without it. +- Sessions aren't supported yet: the Logos catalog has no `lez_core` for v0.4, and 0.5.1 can't drive a v0.4 chain. `up` refuses `[sessions]` on v0.4, and v0.3's sessions wait in `sessions/` as they were. - `upstream_accounts = true` under `[devnet]` keeps LEZ's own genesis accounts funded, whose keys LEZ publishes for its examples and tools. ## Dev mode @@ -260,7 +260,7 @@ Everything is in `~/.logos-devnet` (or `LOGOS_DEVNET_HOME`): | `wallet/` | the dev wallet: the faucet and each program's header key. Kept across resets. `wallet-v0.4/` is LEZ v0.4's | | `compose.yaml` | the Docker runtime's compose file | | `native/` | the native runtime's LEZ checkout, build, log and pid file | -| `sessions/` | one directory per session: its `logosctl` home, its daemon's `HOME` with its storage, wallet and `session.json` | +| `sessions/` | one directory per session: its `logosctl` home, its daemon's `HOME` with its storage, wallet and `session.json`. `sessions-v0.4/` is LEZ v0.4's | | `accounts/` | one directory per account group: its wallet and `accounts.json`. `accounts-v0.4/` holds LEZ v0.4's | | `programs.json` | the binary hash each program was deployed from | | `downloads/` | program binaries the project file names by URL, by SHA-256, and in `packages/` the module packages every daemon installs from, downloaded once and checked against the catalog's SHA-256. Every home uses the one in `~/.logos-devnet`, so a project's own home or a worktree's doesn't download them again. One left in another home from before v0.9.0 can be deleted | diff --git a/skills/logos-devnet/SKILL.md b/skills/logos-devnet/SKILL.md index e3934b0..93bd0fb 100644 --- a/skills/logos-devnet/SKILL.md +++ b/skills/logos-devnet/SKILL.md @@ -55,7 +55,7 @@ Pass `--json` to every command: on success stdout holds one JSON document, and n - **LEZ line.** v0.3 (default `v0.3.1`) is what the testnet runs. `lez = "v0.4.0-rc3"` runs the v0.4 release candidate: programs built for v0.4, its own dev wallet and program ids, funding by public key (`accounts.json` records each account's `key`), and no sessions yet. `upstream_accounts = true` keeps LEZ's own published genesis accounts funded for its examples. - **Dev mode.** `dev_mode = true` makes private calls prove in about 1 s instead of about 2 min, with fake proofs. A chain keeps its dev mode for life: switching it takes `reset`. Use a chain without dev mode to check that real proofs verify. - **Programs.** A program can be a path, or a release: `{ url = "...", sha256 = "..." }`, downloaded once and deployed only if its SHA-256 matches. Programs deploy immutable, which undisclosed private calls require. While iterating on one, give it `{ path = "...", mutable = true }`: a rebuild then updates it in place with the same id on the next `up`. Its mutability is fixed per chain, so changing it takes `reset`. `.logos-devnet/programs.json` records each deployed program's binary SHA-256 and mutability: compare it with `shasum -a 256 ` to show which build runs. -- **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. +- **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. On v0.3 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; on v0.4 an account never used takes `--key ` too, unless it's one of the devnet's own. - **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. diff --git a/src/devnet.rs b/src/devnet.rs index dd360b2..338a218 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -1948,8 +1948,8 @@ fn wallet_config(line: LezLine, sequencer: &str) -> Value { "sequencer_addr": sequencer, "sequencers": [{ "sequencer_addr": sequencer }] }); - // v0.3 declares this much gas on each transaction. v0.4 measures it, and without a - // `gas_limit` budgets up to the block's cap, which a 96 KiB program segment needs. + // v0.3 declares this much gas on each transaction. v0.4 measures it within the + // `gas_limit` budget, whose default (2M at rc3) leaves room for a 96 KiB program segment. if line == LezLine::V03 { config["gas_limit"] = json!(200_000); } diff --git a/src/rpc.rs b/src/rpc.rs index 92e5354..9dde875 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -71,7 +71,8 @@ impl Rpc { .with_context(|| format!("getTransaction returned {value}")) } - /// An account's state: its `nonce` and its `data` shards, by program id. + /// An account's state: its `nonce` and its `data` by program id (`shards` on LEZ v0.3, + /// `actor_states` on v0.4), or null on v0.4 for an account never used. pub fn account(&self, account: &PublicId) -> Result { self.call("getAccount", json!([account.as_str()])) } From c241565bfb9a142e1c82d029dabf7d9f920d1105 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 00:04:46 +0000 Subject: [PATCH 19/28] fix: keep a chain's LEZ tag with the chain A lost settings file read as the default v0.3.1, so up could write a v0.3 config over a v0.4 chain. The chain now records its tag like its dev mode, and a mismatch is refused. --- src/devnet.rs | 30 +++++++++++++++++++++++++++++- src/home.rs | 15 +++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/devnet.rs b/src/devnet.rs index 338a218..2f8aeec 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -165,10 +165,14 @@ impl Devnet { } /// Refuses `settings` the chain here can't run on: another LEZ tag or dev mode. Its own - /// record of its dev mode counts, not settings.json's. + /// records of its tag and dev mode count, not settings.json's. fn check_chain_takes(&self, settings: &Settings) -> Result<()> { let chain = Settings { dev_mode: self.home.chain_dev_mode(), + lez: self + .home + .chain_lez() + .unwrap_or_else(|| self.settings.lez.clone()), ..self.settings.clone() }; check_chain_keeps(&chain, settings) @@ -395,6 +399,7 @@ impl Devnet { next.set_chain_up(&config)?; write_json(&next.home.chain_config(), &config)?; next.home.record_chain_dev_mode(next.settings.dev_mode)?; + next.home.record_chain_lez(&next.settings.lez)?; // Every one is tried, and a failure is reported once the chain runs. let marked = if continuing { Ok(()) @@ -2858,6 +2863,29 @@ mod tests { assert!(devnet.check_chain_takes(&dev).is_ok()); } + #[test] + fn a_chain_keeps_its_own_lez_tag_without_settings() { + // A v0.4 chain whose settings.json was lost reads as the default v0.3.1: its own record + // must stop a v0.3 config being written over it. + let dir = tempfile::tempdir().unwrap(); + let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); + std::fs::create_dir_all(home.chain_dir()).unwrap(); + home.record_chain_lez("v0.4.0-rc3").unwrap(); + let devnet = Devnet::open(home, None).unwrap(); + let err = devnet.check_chain_takes(&Settings::default()).unwrap_err(); + assert!(err.to_string().contains("runs LEZ v0.4.0-rc3"), "{err}"); + } + + #[test] + fn doctor_refuses_sessions_on_the_line_the_project_asks_for() { + let dir = tempfile::tempdir().unwrap(); + let file = "home = \"home\"\n[devnet]\nlez = \"v0.4.0-rc3\"\n[sessions.alice]\n"; + let devnet = devnet_with_file(dir.path(), file); + // No chain yet: the settings are still the default v0.3.1. + assert!(devnet.refuses_sessions(devnet.settings_for_up().line())); + assert!(!devnet.refuses_sessions(LezLine::V03)); + } + #[test] fn says_why_a_program_needs_reset() { let elf = Path::new("out/counter.bin"); diff --git a/src/home.rs b/src/home.rs index c9ab09d..f967715 100644 --- a/src/home.rs +++ b/src/home.rs @@ -258,6 +258,21 @@ impl Home { let value = crate::envfile::dev_mode_value(dev_mode); std::fs::write(&file, value).with_context(|| format!("writing {}", file.display())) } + + /// The LEZ tag the chain here runs, kept with the chain like its dev mode: a lost or edited + /// settings file would read as the default tag, and v0.3 and v0.4 can't run each other's + /// chain. Chains from before v0.10.0 have none. + pub fn chain_lez(&self) -> Option { + std::fs::read_to_string(self.chain_dir().join("lez")) + .ok() + .map(|tag| tag.trim().to_owned()) + .filter(|tag| !tag.is_empty()) + } + + pub fn record_chain_lez(&self, tag: &str) -> Result<()> { + let file = self.chain_dir().join("lez"); + std::fs::write(&file, tag).with_context(|| format!("writing {}", file.display())) + } /// The dev wallet: the faucet and each program's header key. A v0.4 wallet can't read /// v0.3 storage, so each LEZ line has its own, and its own program ids. pub fn wallet_dir(&self, line: LezLine) -> PathBuf { From b1388bdaf732c673eada37d6e61304dfd1017f69 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 00:04:48 +0000 Subject: [PATCH 20/28] fix: refuse an encrypted wallet storage A wallet with a password keeps its state inside the ciphertext, which forget_chain can't clear. --- src/wallet_storage.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wallet_storage.rs b/src/wallet_storage.rs index 426ebe3..d8e46ab 100644 --- a/src/wallet_storage.rs +++ b/src/wallet_storage.rs @@ -77,6 +77,12 @@ fn edit_member( /// not a guess. fn forget_chain(text: &str) -> Result { let mut storage: RawObject = serde_json::from_str(text)?; + if storage.contains_key("ciphertext") { + anyhow::bail!( + "the wallet's storage is encrypted with a password, so its state from the old chain \ + can't be cleared: make the wallet again without one" + ); + } storage.insert( "last_synced_block".into(), RawValue::from_string("0".into())?, @@ -357,6 +363,14 @@ pub(crate) mod tests { ); } + #[test] + fn refuses_an_encrypted_storage() { + // A wallet with a password keeps its state inside the ciphertext, out of reach. + let sealed = r#"{"version":1,"kdf":{},"nonce":"aa","ciphertext":"bb"}"#; + let err = forget_chain(sealed).unwrap_err(); + assert!(format!("{err:#}").contains("password"), "{err:#}"); + } + #[test] fn forgetting_a_chain_adds_nothing_and_refuses_a_layout_it_doesnt_know() { let bare = r#"{"key_chain":{"accounts":[]},"last_synced_block":9}"#; From 9d21e8e02ccb69aed29a6ac62d153d5e656fc6af Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 00:04:48 +0000 Subject: [PATCH 21/28] fix: look up account keys only on v0.4 v0.3 pays by id, so a damaged accounts.json no longer blocks fund there. --- src/devnet.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/devnet.rs b/src/devnet.rs index 2f8aeec..11a9371 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -1131,9 +1131,11 @@ impl Devnet { // Fails before any work when there is no faucet yet. self.faucet()?; self.require_running()?; + // v0.3 pays by id: only v0.4 needs the key. let key = match key { Some(key) => Some(key.to_owned()), - None => self.known_key(&to)?, + None if self.settings.line() == LezLine::V04 => self.known_key(&to)?, + None => None, }; if self.settings.line() == LezLine::V04 && key.is_none() From c3059b1a152705168329e392bf97bbe02b72d112 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 00:04:48 +0000 Subject: [PATCH 22/28] fix: plan groups on the project's LEZ line Before the first chain, accounts new and doctor follow the project's [devnet] lez, as up does, so a group made early lands in the line its chain will run. --- src/devnet.rs | 16 ++++++++++++---- src/doctor.rs | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/devnet.rs b/src/devnet.rs index 11a9371..815b695 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -491,7 +491,7 @@ impl Devnet { self.runtime.check_wallet_file(&binary)?; } } - if self.refuses_sessions() { + if self.refuses_sessions(self.settings.line()) { bail!("{SESSIONS_ON_V04}"); } if self.needs_logosctl() && !logosctl_on_path() { @@ -505,9 +505,10 @@ impl Devnet { self.check_hub_ports() } - /// Whether the project asks for sessions on LEZ v0.4, which can't run them yet. - pub fn refuses_sessions(&self) -> bool { - self.settings.line() == LezLine::V04 + /// Whether the project asks for sessions on `line`, when that's LEZ v0.4, which can't run + /// them yet. + pub fn refuses_sessions(&self, line: LezLine) -> bool { + line == LezLine::V04 && self .project .as_ref() @@ -1158,6 +1159,13 @@ impl Devnet { /// Makes account group `name` with `count` accounts (at least: a group never shrinks), /// each funded with `amount`, now when the devnet runs, else when it starts. pub fn accounts_new(&self, name: &str, count: usize, amount: u64) -> Result { + // Before the first chain, the project's `[devnet]` decides which LEZ line the group is + // for, as it decides what `up` starts. + let planned = self.settings_for_up(); + if !self.home.has_chain() && planned.line() != self.settings.line() { + let devnet = Self::with(self.home.clone(), planned, self.project.clone()); + return devnet.accounts_new(name, count, amount); + } groups::check_spec(count, amount)?; self.runtime.prepare(false)?; self.make_group(name, count, amount)?; diff --git a/src/doctor.rs b/src/doctor.rs index ef9b366..996e63b 100644 --- a/src/doctor.rs +++ b/src/doctor.rs @@ -195,7 +195,7 @@ pub fn run(devnet: &Devnet, project_error: Option<&anyhow::Error>) -> Doctor { } } - if devnet.refuses_sessions() { + if devnet.refuses_sessions(settings.line()) { checks.push(fail( "sessions", "the project asks for sessions, which don't run on LEZ v0.4 yet", From ffea75d7f69c94b602b24fffdac7a870e93d6dd4 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 01:00:12 +0000 Subject: [PATCH 23/28] feat!: run LEZ v0.4 only LEZ v0.3 is going away, so logos-devnet drops it: v0.4.0-rc3 is the default and v0.4 tags the only ones it runs, with one code path for the sequencer, config, funding and wallets. A home that ran v0.3 refuses up and says how to go on, and reset moves its wallets, groups and sessions to *-v0.3/ and starts v0.4. v0.9.4 is the last release that runs v0.3. Sessions wait for a lez_core built for v0.4, behind SESSIONS_READY. --- docker/Dockerfile | 15 +- src/chain_config.rs | 287 +++++++++---------------------- src/devnet.rs | 391 ++++++++++++++++++++++-------------------- src/doctor.rs | 13 +- src/groups.rs | 22 ++- src/home.rs | 217 +++++++++++++---------- src/report.rs | 4 +- src/rpc.rs | 34 ++-- src/runtime/docker.rs | 43 ++--- src/runtime/mod.rs | 7 +- src/runtime/native.rs | 84 +++------ src/session.rs | 5 +- src/wallet_storage.rs | 84 +++------ 13 files changed, 523 insertions(+), 683 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 9e268a7..d4b0a2d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,12 +3,11 @@ # A standalone LEZ sequencer and the LEZ wallet, built from an upstream tag. Built from stdin, so # it needs no build context: # -# docker build --build-arg LEZ_TAG=v0.3.1 -t ghcr.io/drptbl/logos-devnet-sequencer:v0.3.1 - < docker/Dockerfile +# docker build --build-arg LEZ_TAG=v0.4.0-rc3 -t ghcr.io/drptbl/logos-devnet-sequencer:v0.4.0-rc3 - < docker/Dockerfile # # `standalone` replaces Bedrock with an in-process mock, and `prove` runs guests in-process, so -# the image needs neither a Bedrock node nor r0vm. For v0.3, RISC0_SKIP_BUILD_KERNELS skips the -# prover kernels the sequencer never runs. From LEZ v0.4 the sequencer links the wallet, whose -# prover needs them, so they're built. +# the image needs neither a Bedrock node nor r0vm. The sequencer links the wallet, whose prover +# needs risc0's CPU kernels, so they're built. FROM rust:1-slim-trixie AS build ARG LEZ_TAG @@ -26,16 +25,14 @@ WORKDIR /lez RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git \ --mount=type=cache,target=/lez/target,sharing=locked \ - case "$LEZ_TAG" in v0.3.*) export RISC0_SKIP_BUILD_KERNELS=1 ;; esac \ - && cargo build --release --features "$FEATURES" -p sequencer_service \ + cargo build --release --features "$FEATURES" -p sequencer_service \ && cargo build --release -p wallet \ && mkdir -p /out \ && cp target/release/sequencer_service target/release/wallet /out/ \ && strip /out/sequencer_service /out/wallet -# Upstream's local config for this tag; the CLI patches it rather than shipping its own. LEZ -# v0.3 keeps it in `configs/debug/`, v0.4 as `networks/local.json`. +# Upstream's local config for this tag; the CLI patches it rather than shipping its own. RUN mkdir -p /out/share \ - && config="$(find . -path ./target -prune -o \( -path '*sequencer/service/configs/debug/sequencer_config.json' -o -path '*sequencer/service/networks/local.json' \) -print | head -1)" \ + && config="$(find . -path ./target -prune -o -path '*sequencer/service/networks/local.json' -print | head -1)" \ && test -n "$config" \ && cp "$config" /out/share/sequencer_config.json diff --git a/src/chain_config.rs b/src/chain_config.rs index e979633..7606406 100644 --- a/src/chain_config.rs +++ b/src/chain_config.rs @@ -1,13 +1,9 @@ //! The sequencer config a devnet runs on: upstream's own local config for the pinned LEZ tag -//! (`configs/debug/sequencer_config.json` on v0.3, `networks/local.json` on v0.4), with our -//! chain home, block interval and faucet. Patching upstream's file rather than shipping our own -//! keeps every field a newer tag adds. +//! (`networks/local.json`), with our chain home, block interval and faucet. Patching upstream's +//! file rather than shipping our own keeps every field a newer tag adds. use anyhow::{Context, Result, bail}; -use serde_json::{Map, Value, json}; - -use crate::account::PublicId; -use crate::home::LezLine; +use serde_json::{Value, json}; /// What a devnet changes in upstream's config. pub struct ChainOptions<'a> { @@ -26,11 +22,10 @@ pub struct ChainOptions<'a> { pub keep_upstream_accounts: bool, } -/// An account funded at genesis. v0.3 names it by id, v0.4 by its public key. +/// An account funded at genesis, which names it by its public key. pub struct Funded { - pub id: PublicId, - /// Its public key, as 64 hex digits: what a v0.4 genesis funds. - pub key: Option, + /// Its public key, as 64 hex digits. + pub key: String, /// Lepta. pub balance: u64, } @@ -49,10 +44,9 @@ pub fn check_max_txs_per_block(max: u32) -> Result<()> { Ok(()) } -/// Returns upstream's config with `opts` applied, in `line`'s schema. Unless the options keep -/// them, the faucet and the given accounts are the only ones funded: upstream's supply accounts -/// have published keys. -pub fn patch(line: LezLine, mut upstream: Value, opts: &ChainOptions) -> Result { +/// Returns upstream's config with `opts` applied. Unless the options keep them, the faucet and +/// the given accounts are the only ones funded: upstream's supply accounts have published keys. +pub fn patch(mut upstream: Value, opts: &ChainOptions) -> Result { let config = upstream .as_object_mut() .context("the upstream sequencer config is not a JSON object")?; @@ -61,65 +55,35 @@ pub fn patch(line: LezLine, mut upstream: Value, opts: &ChainOptions) -> Result< check_max_txs_per_block(opts.max_txs_per_block)?; config.insert("max_num_tx_in_block".into(), json!(opts.max_txs_per_block)); // Both would listen on every interface: metrics on 9000 and gossip on a UDP port. A single - // devnet sequencer needs neither. v0.4 refuses fields it doesn't know, and renamed one. - let metrics = match line { - LezLine::V03 => "metrics_address", - LezLine::V04 => "metrics_listen_address", - }; - config.insert(metrics.into(), Value::Null); + // devnet sequencer needs neither. The config refuses fields it doesn't know. + config.insert("metrics_listen_address".into(), Value::Null); config.insert("gossip".into(), Value::Null); - let funded = std::iter::once(opts.faucet).chain(opts.genesis_accounts); - let posting_timeout = match line { - LezLine::V03 => { - let genesis = config - .entry("genesis") - .or_insert_with(|| json!([])) - .as_array_mut() - .context("the upstream config's `genesis` is not a list")?; - if !opts.keep_upstream_accounts { - genesis.retain(|action| action.get("supply_account").is_none()); - } - for account in funded { - genesis.push(json!({ - "supply_account": { "account_id": account.id.as_str(), "balance": account.balance } - })); - } - config.get("bedrock_config").map(|b| &b["channel_params"]) - } - LezLine::V04 => { - let genesis = config - .get_mut("genesis") - .and_then(Value::as_object_mut) - .context("the upstream config's `genesis` is not an object")?; - let actions = actions(genesis)?; - if !opts.keep_upstream_accounts { - actions.retain(|action| { - action.get("supply_account").is_none() - && action.get("supply_private_account").is_none() - }); - } - for account in funded { - let key = account.key.as_deref().with_context(|| { - format!( - "{} has no public key on record, and a LEZ v0.4 genesis funds by key", - account.id.wallet_form() - ) - })?; - actions.push(json!({ - "supply_account": { - "recipient": { "identified": { "key": key } }, - "balance": account.balance - } - })); + let genesis = config + .get_mut("genesis") + .and_then(Value::as_object_mut) + .context("the upstream config's `genesis` is not an object")?; + let actions = genesis + .entry("actions") + .or_insert_with(|| json!([])) + .as_array_mut() + .context("the upstream config's `genesis.actions` is not a list")?; + if !opts.keep_upstream_accounts { + actions.retain(|action| { + action.get("supply_account").is_none() && action.get("supply_private_account").is_none() + }); + } + for account in std::iter::once(opts.faucet).chain(opts.genesis_accounts) { + actions.push(json!({ + "supply_account": { + "recipient": { "identified": { "key": account.key } }, + "balance": account.balance } - config.get("genesis").map(|g| &g["channel_params"]) - } + })); } - .and_then(|params| params["posting_timeout"].as_u64()); let block_secs = block_time_secs(opts.block_time)?; - if let Some(timeout) = posting_timeout + if let Some(timeout) = genesis["channel_params"]["posting_timeout"].as_u64() && block_secs >= timeout as f64 { bail!( @@ -130,15 +94,6 @@ pub fn patch(line: LezLine, mut upstream: Value, opts: &ChainOptions) -> Result< Ok(upstream) } -/// A v0.4 genesis's `actions`. -fn actions(genesis: &mut Map) -> Result<&mut Vec> { - genesis - .entry("actions") - .or_insert_with(|| json!([])) - .as_array_mut() - .context("the upstream config's `genesis.actions` is not a list") -} - /// Seconds in a `1s` / `500ms` / `2m` block time: the forms the sequencer's humantime config /// takes that a block interval needs. Refuses anything else, and zero. pub fn block_time_secs(text: &str) -> Result { @@ -164,93 +119,9 @@ pub fn block_time_secs(text: &str) -> Result { #[cfg(test)] mod tests { use super::*; - use crate::home::LezLine; - - fn upstream() -> Value { - json!({ - "home": ".", - "block_create_timeout": "15s", - "bedrock_config": { "channel_params": { "posting_timeout": 25 } }, - "genesis": [ - { "supply_account": { "account_id": "Stock", "balance": 10 } }, - { "stake_sequencer": { "sequencer_key": "k" } } - ], - "future_field": 7 - }) - } - - const FAUCET: &str = "HpavNGFYxjyhLsy171aXsvv146yUeXmRWiho22uvT43d"; - - const USER: &str = "6YvesSEDWW25kpi8SSki2c8o5m3uACsigvGnNQ6wMruh"; - - fn patched_with(block_time: &str, max_txs_per_block: u32) -> Result { - let faucet = Funded { - id: PublicId::parse(FAUCET).unwrap(), - key: None, - balance: 1_000, - }; - let users = [Funded { - id: PublicId::parse(USER).unwrap(), - key: None, - balance: 7, - }]; - patch( - LezLine::V03, - upstream(), - &ChainOptions { - home: "/devnet/chain", - block_time, - faucet: &faucet, - max_txs_per_block, - genesis_accounts: &users, - keep_upstream_accounts: false, - }, - ) - } - - fn patched(block_time: &str) -> Result { - patched_with(block_time, 20) - } - - #[test] - fn sets_home_and_block_time_and_turns_listeners_off() { - let out = patched("1s").unwrap(); - assert_eq!(out["home"], "/devnet/chain"); - assert_eq!(out["block_create_timeout"], "1s"); - assert!(out["metrics_address"].is_null()); - assert!(out["gossip"].is_null()); - assert_eq!(out["future_field"], 7, "fields we don't know about stay"); - } - - #[test] - fn funds_only_the_faucet_and_the_named_accounts() { - let out = patched("1s").unwrap(); - let genesis = out["genesis"].as_array().unwrap(); - assert_eq!( - genesis, - &vec![ - json!({ "stake_sequencer": { "sequencer_key": "k" } }), - json!({ "supply_account": { "account_id": FAUCET, "balance": 1000 } }), - json!({ "supply_account": { "account_id": USER, "balance": 7 } }), - ] - ); - } - - #[test] - fn sets_and_bounds_the_transactions_per_block() { - assert_eq!(patched_with("1s", 200).unwrap()["max_num_tx_in_block"], 200); - assert!(patched_with("1s", 0).is_err()); - assert!(patched_with("1s", 1001).is_err()); - } - - #[test] - fn refuses_a_block_time_at_or_over_the_posting_timeout() { - assert!(patched("25s").is_err()); - assert!(patched("500ms").is_ok()); - } /// LEZ v0.4.0-rc3's `networks/local.json`, cut down. - fn upstream_v04() -> Value { + fn upstream() -> Value { json!({ "home": ".", "max_num_tx_in_block": 20, @@ -270,34 +141,39 @@ mod tests { const FAUCET_KEY: &str = "6aa4c365699b89d963ef85a59868b9612b6001f90750b4970662a62776332e81"; - fn patched_v04(user_key: Option<&str>, keep_upstream_accounts: bool) -> Result { - let faucet = Funded { - id: PublicId::parse(FAUCET).unwrap(), - key: Some(FAUCET_KEY.into()), - balance: 1_000, - }; - let users = [Funded { - id: PublicId::parse(USER).unwrap(), - key: user_key.map(str::to_owned), - balance: 7, - }]; - patch( - LezLine::V04, - upstream_v04(), - &ChainOptions { - home: "/devnet/chain", - block_time: "1s", - faucet: &faucet, - max_txs_per_block: 50, - genesis_accounts: &users, - keep_upstream_accounts, - }, - ) + fn options<'a>( + faucet: &'a Funded, + users: &'a [Funded], + max_txs_per_block: u32, + keep_upstream_accounts: bool, + ) -> ChainOptions<'a> { + ChainOptions { + home: "/devnet/chain", + block_time: "1s", + faucet, + max_txs_per_block, + genesis_accounts: users, + keep_upstream_accounts, + } + } + + fn funded(key: &str, balance: u64) -> Funded { + Funded { + key: key.into(), + balance, + } + } + + fn patched(max_txs_per_block: u32, keep_upstream_accounts: bool) -> Result { + let faucet = funded(FAUCET_KEY, 1_000); + let users = [funded("bb", 7)]; + let opts = options(&faucet, &users, max_txs_per_block, keep_upstream_accounts); + patch(upstream(), &opts) } #[test] - fn a_v0_4_config_runs_alone_and_keeps_the_tags_channel() { - let out = patched_v04(Some("bb"), false).unwrap(); + fn runs_alone_and_keeps_the_tags_channel() { + let out = patched(50, false).unwrap(); assert_eq!(out["home"], "/devnet/chain"); assert_eq!(out["block_create_timeout"], "1s"); assert_eq!(out["max_num_tx_in_block"], 50); @@ -310,8 +186,8 @@ mod tests { } #[test] - fn a_v0_4_genesis_funds_by_public_key() { - let out = patched_v04(Some("bb"), false).unwrap(); + fn genesis_funds_by_public_key() { + let out = patched(20, false).unwrap(); let funded = |key: &str, balance: u64| json!({ "supply_account": { "recipient": { "identified": { "key": key } }, "balance": balance } }); assert_eq!( out["genesis"]["actions"].as_array().unwrap(), @@ -321,36 +197,29 @@ mod tests { funded("bb", 7), ] ); - let err = patched_v04(None, false).unwrap_err(); - assert!(format!("{err:#}").contains(USER), "{err:#}"); } #[test] - fn a_v0_4_genesis_can_keep_upstreams_published_accounts() { - let out = patched_v04(Some("bb"), true).unwrap(); + fn genesis_can_keep_upstreams_published_accounts() { + let out = patched(20, true).unwrap(); let actions = out["genesis"]["actions"].as_array().unwrap(); assert_eq!(actions.len(), 5, "{actions:?}"); assert!(actions[1].get("supply_private_account").is_some()); } #[test] - fn a_v0_4_block_time_stays_under_the_posting_timeout() { - let mut upstream = upstream_v04(); + fn block_time_stays_under_the_posting_timeout() { + let mut upstream = upstream(); upstream["genesis"]["channel_params"]["posting_timeout"] = json!(1); - let faucet = Funded { - id: PublicId::parse(FAUCET).unwrap(), - key: Some(FAUCET_KEY.into()), - balance: 1, - }; - let opts = ChainOptions { - home: "/devnet/chain", - block_time: "1s", - faucet: &faucet, - max_txs_per_block: 20, - genesis_accounts: &[], - keep_upstream_accounts: false, - }; - assert!(patch(LezLine::V04, upstream, &opts).is_err()); + let faucet = funded(FAUCET_KEY, 1); + assert!(patch(upstream, &options(&faucet, &[], 20, false)).is_err()); + } + + #[test] + fn sets_and_bounds_the_transactions_per_block() { + assert_eq!(patched(200, false).unwrap()["max_num_tx_in_block"], 200); + assert!(patched(0, false).is_err()); + assert!(patched(1001, false).is_err()); } #[test] diff --git a/src/devnet.rs b/src/devnet.rs index 815b695..04ee37f 100644 --- a/src/devnet.rs +++ b/src/devnet.rs @@ -15,7 +15,7 @@ use crate::chain_config::{self, ChainOptions, Funded}; use crate::envfile::{self, Env}; use crate::fetch; use crate::groups::{self, Group, GroupInfo}; -use crate::home::{Home, LezLine, RuntimeKind, Settings, write_json}; +use crate::home::{DEFAULT_LEZ, Home, RuntimeKind, Settings, V0_3_RELEASE, write_json}; use crate::messaging::{Hub, Wants}; use crate::project::{ProgramSource, ProgramSpec, Project}; use crate::report::{ @@ -32,10 +32,16 @@ const FAUCET_BALANCE: u64 = 1_000_000_000_000_000_000; const FAUCET_LABEL: &str = "faucet"; /// What `fund`, sessions and account groups send when no amount is given. pub const DEFAULT_FUND: u64 = 10_000_000_000; -/// Why sessions don't run on LEZ v0.4 yet. -const SESSIONS_ON_V04: &str = "sessions don't run on LEZ v0.4 yet: the Logos catalog has no \ - lez_core for v0.4, and lez_core 0.5.1 can't drive a v0.4 chain. Drop [sessions] from the \ - project file, or stay on v0.3, whose sessions wait as they were"; +/// Whether sessions run. They wait for a `lez_core` built for LEZ v0.4 in the Logos catalog: the +/// newest, 0.5.1, is built for v0.3 and can't drive a v0.4 chain. Once one ships, pin it in +/// `session::LEZ_CORE_VERSION`, open wallets with its `force_rpc` (it runs a sequencer of its own +/// otherwise), and turn this on. +const SESSIONS_READY: bool = false; + +/// Why sessions don't run yet. +pub(crate) const SESSIONS_WAIT: &str = "sessions don't run yet: they need a lez_core built for LEZ v0.4, \ + and the Logos catalog has only 0.5.1, built for v0.3. Drop [sessions] from the project \ + file for now, or use logos-devnet v0.9.4 with LEZ v0.3"; /// How `up` waits for a starting sequencer's first block. A long chain replays first, logging /// a different line for each block (186k blocks took 34 min), so `up` waits as long as the log @@ -280,7 +286,7 @@ impl Devnet { /// Runs the LEZ wallet on the dev wallet. Its config is rewritten first: the wallet would /// otherwise create a default one pointing at the public testnet. fn wallet(&self, args: Vec) -> Result { - let home = self.wallet_dir(); + let home = self.home.wallet_dir(); self.point_wallet_at(&home, &self.runtime.wallet_sequencer_url())?; self.runtime.wallet(&home, args) } @@ -289,25 +295,7 @@ impl Devnet { /// run: without one the wallet creates a default pointing at the public testnet. fn point_wallet_at(&self, home: &Path, sequencer: &str) -> Result<()> { std::fs::create_dir_all(home)?; - write_json( - &home.join("wallet_config.json"), - &wallet_config(self.settings.line(), sequencer), - ) - } - - /// The dev wallet of the chain's LEZ line. - fn wallet_dir(&self) -> PathBuf { - self.home.wallet_dir(self.settings.line()) - } - - /// The account groups of the chain's LEZ line. - fn groups_dir(&self) -> PathBuf { - self.home.groups_dir(self.settings.line()) - } - - /// The sessions of the chain's LEZ line. - fn sessions_dir(&self) -> PathBuf { - self.home.sessions_dir(self.settings.line()) + write_json(&home.join("wallet_config.json"), &wallet_config(sequencer)) } fn faucet(&self) -> Result<&PublicId> { @@ -336,10 +324,34 @@ impl Devnet { /// Starts the devnet with `opts` applied, on a new chain when `wipe`. Everything that can /// fail runs before the running sequencer is stopped, the settings saved or the chain - /// deleted, so a bad option leaves the devnet as it was. + /// deleted, so a bad option leaves the devnet as it was. A home that ran LEZ v0.3 is the + /// exception: `reset` moves its wallets aside (see `move_v0_3_aside`) before the steps that + /// need the new ones, and a `reset` run again after a failure doesn't move them twice. fn launch(self, opts: &UpOptions, wipe: bool) -> Result { + // A tag asked for, by flag or project file, is checked before anything else says + // `reset` would apply it. + let asked = opts + .lez + .as_deref() + .or_else(|| self.project.as_ref().and_then(|p| p.devnet.lez.as_deref())); + if let Some(tag) = asked { + crate::home::check_lez(tag)?; + } let running = self.runtime.running(); - let settings = opts.apply(self.with_project_settings(opts, running && !wipe)?); + let mut settings = opts.apply(self.with_project_settings(opts, running && !wipe)?); + let moves_v0_3 = self.home.runs_v0_3(&self.settings.lez); + if moves_v0_3 { + if !wipe { + bail!( + "this home runs LEZ v0.3. `logos-devnet reset` starts it on LEZ v0.4, with \ + its v0.3 wallets, account groups and sessions moved aside, to \ + wallet-v0.3/, accounts-v0.3/ and sessions-v0.3/. {V0_3_RELEASE}" + ); + } + if asked.is_none() { + settings.lez = DEFAULT_LEZ.into(); + } + } crate::home::check_lez(&settings.lez)?; chain_config::block_time_secs(&settings.block_time)?; chain_config::check_max_txs_per_block(settings.max_txs_per_block)?; @@ -377,6 +389,9 @@ impl Devnet { } next.runtime.prepare(opts.rebuild)?; + if moves_v0_3 { + self.move_v0_3_aside()?; + } let faucet = next.dev_faucet()?; if continuing && funds_another_faucet(self.settings.faucet.as_ref(), &faucet) { bail!( @@ -461,6 +476,32 @@ impl Devnet { Ok(wanted) } + /// Moves a LEZ v0.3 home's wallets, account groups and sessions aside (see + /// `Home::move_v0_3_aside`), with each session's daemon stopped first. + fn move_v0_3_aside(&self) -> Result<()> { + // A daemon left running would keep a moved directory open, out of reach. + for session in session::list(&self.home.sessions_dir())? { + let ctl = session.logosctl(); + ctl.stop() + .with_context(|| format!("stopping session {}", session.name))?; + if ctl.answers_within(SESSION_CHECK_TIMEOUT) { + bail!( + "session {}'s daemon still answers after a stop: stop it with `logosctl \ + daemon stop` and its LOGOSCTL_CONFIG_DIR, then `reset` again", + session.name + ); + } + } + let moved = self.home.move_v0_3_aside()?; + if !moved.is_empty() { + eprintln!( + "This home ran LEZ v0.3: its {} are kept as they were, for logos-devnet v0.9.4.", + moved.join(", ") + ); + } + Ok(()) + } + /// Where `program`'s binary is on this machine: its path, or its release, downloaded into /// the home once and checked against its SHA-256. fn program_binary(&self, program: &ProgramSpec) -> Result { @@ -491,8 +532,8 @@ impl Devnet { self.runtime.check_wallet_file(&binary)?; } } - if self.refuses_sessions(self.settings.line()) { - bail!("{SESSIONS_ON_V04}"); + if self.refuses_sessions() { + bail!("{SESSIONS_WAIT}"); } if self.needs_logosctl() && !logosctl_on_path() { bail!( @@ -505,10 +546,9 @@ impl Devnet { self.check_hub_ports() } - /// Whether the project asks for sessions on `line`, when that's LEZ v0.4, which can't run - /// them yet. - pub fn refuses_sessions(&self, line: LezLine) -> bool { - line == LezLine::V04 + /// Whether the project asks for sessions, which don't run yet (see `SESSIONS_READY`). + pub fn refuses_sessions(&self) -> bool { + !SESSIONS_READY && self .project .as_ref() @@ -547,7 +587,7 @@ impl Devnet { /// height. Keys and accounts stay. Every group is tried. fn forget_group_chains(&self) -> Result<()> { let mut failed = Vec::new(); - for group in groups::list(&self.groups_dir())? { + for group in groups::list(&self.home.groups_dir())? { if let Err(e) = group.forget_old_chain() { eprintln!("account group {}: {e:#}", group.name); failed.push(group.name); @@ -572,7 +612,7 @@ impl Devnet { failed.push(format!("session {}", session.name)); } } - for group in groups::list(&self.groups_dir())? { + for group in groups::list(&self.home.groups_dir())? { if let Err(e) = group.mark_new_chain() { eprintln!("account group {}: {e:#}", group.name); failed.push(format!("account group {}", group.name)); @@ -625,7 +665,7 @@ impl Devnet { } if let Some(project) = &self.project { for (name, spec) in &project.sessions { - let session = Session::new(&self.sessions_dir(), name)?; + let session = Session::new(&self.home.sessions_dir(), name)?; if session.exists() { match self.add_session_modules(&session, &spec.modules) { Ok(added) if !added.is_empty() => { @@ -655,7 +695,7 @@ impl Devnet { /// Group `name` with at least `count` accounts, each to be funded with `amount`. Missing /// keys are made in one wallet batch. A group never shrinks: its keys stay. fn make_group(&self, name: &str, count: usize, amount: u64) -> Result { - let group = Group::new(&self.groups_dir(), name)?; + let group = Group::new(&self.home.groups_dir(), name)?; if !group.wallet_dir().exists() { groups::check_group_name(name)?; } @@ -733,7 +773,7 @@ impl Devnet { /// "Never funded" is read from the chain, so spent accounts aren't topped up. fn fund_groups(&self, only: Option<&str>) -> Result<()> { let rpc = self.rpc(); - for group in groups::list(&self.groups_dir())? { + for group in groups::list(&self.home.groups_dir())? { if only.is_some_and(|name| name != group.name) { continue; } @@ -755,7 +795,11 @@ impl Devnet { group.name ); for account in unfunded { - self.send(&account.id, account.checked_key()?, u128::from(info.amount))?; + self.send( + &account.id, + Some(account.checked_key()?), + u128::from(info.amount), + )?; } } Ok(()) @@ -764,12 +808,11 @@ impl Devnet { /// Every account group's accounts with their genesis balance. fn genesis_accounts(&self) -> Result> { let mut accounts = Vec::new(); - for group in groups::list(&self.groups_dir())? { + for group in groups::list(&self.home.groups_dir())? { let info = group.info()?; for account in &info.accounts { accounts.push(Funded { - key: account.checked_key()?.map(str::to_owned), - id: account.id.clone(), + key: account.checked_key()?.to_owned(), balance: info.amount, }); } @@ -876,7 +919,7 @@ impl Devnet { /// The sessions, or none (with a note) when their directory can't be read. fn sessions(&self) -> Vec { - session::list(&self.sessions_dir()).unwrap_or_else(|e| { + session::list(&self.home.sessions_dir()).unwrap_or_else(|e| { eprintln!("sessions: {e:#}"); Vec::new() }) @@ -887,14 +930,14 @@ impl Devnet { std::fs::create_dir_all(session.wallet_dir())?; write_json( &session.wallet_config(), - &wallet_config(self.settings.line(), &self.settings.sequencer_url()), + &wallet_config(&self.settings.sequencer_url()), ) } /// Sends `amount` lepta from the faucet to `to`, whose public key is `key` when known, and /// returns its new balance. fn send(&self, to: &PublicId, key: Option<&str>, amount: u128) -> Result { - let args = transfer_args(self.settings.line(), self.faucet()?, to, key, amount); + let args = transfer_args(self.faucet()?, to, key, amount); self.wallet(args.into_iter().map(WalletArg::from).collect())?; self.rpc().balance(to) } @@ -911,20 +954,23 @@ impl Devnet { /// The public key of `id` when logos-devnet holds it: a group account's, or one in the dev /// wallet, such as the faucet. Read where the key lives, so it can't drift from it. fn known_key(&self, id: &PublicId) -> Result> { - for group in groups::list(&self.groups_dir())? { + for group in groups::list(&self.home.groups_dir())? { if let Some(account) = group.info()?.accounts.iter().find(|a| &a.id == id) { - return Ok(account.checked_key()?.map(str::to_owned)); + return Ok(Some(account.checked_key()?.to_owned())); } } - let storage = self.wallet_dir().join(crate::wallet_storage::STORAGE_FILE); + let storage = self + .home + .wallet_dir() + .join(crate::wallet_storage::STORAGE_FILE); crate::wallet_storage::public_key(&storage, id) } - /// Sets a new LEZ v0.4 chain up from `config`: `setup` writes its channel signing key and - /// funding key file beside a copy of the config, which `up` then keeps up to date. A chain - /// set up before, and every v0.3 chain, has nothing to do. + /// Sets a new chain up from `config`: `setup` writes its channel signing key and funding key + /// file beside a copy of the config, which `up` then keeps up to date. A chain set up before + /// has nothing to do. fn set_chain_up(&self, config: &Value) -> Result<()> { - if self.settings.line() == LezLine::V03 || self.home.chain_set_up() { + if self.home.chain_set_up() { return Ok(()); } // `setup` refuses a home that has a config, e.g. from one that stopped halfway. @@ -940,12 +986,17 @@ impl Devnet { let genesis_accounts = self.genesis_accounts()?; let faucet = self.faucet()?; let faucet = Funded { - key: self.known_key(faucet)?, - id: faucet.clone(), + key: self.known_key(faucet)?.with_context(|| { + format!( + "the dev wallet holds no key for the faucet {}: move {} aside, and `up` \ + makes a new faucet, with new program ids", + faucet.wallet_form(), + self.home.wallet_dir().display() + ) + })?, balance: FAUCET_BALANCE, }; chain_config::patch( - self.settings.line(), self.runtime.upstream_config()?, &ChainOptions { home: &self.runtime.chain_home(), @@ -984,7 +1035,7 @@ impl Devnet { messaging: self.hub().addresses(), sessions: BTreeMap::new(), }; - for group in groups::list(&self.groups_dir())? { + for group in groups::list(&self.home.groups_dir())? { env.groups.insert(group.name.clone(), group.manifest()); } // A session still being made has no account yet: it joins the next env file. @@ -1132,18 +1183,13 @@ impl Devnet { // Fails before any work when there is no faucet yet. self.faucet()?; self.require_running()?; - // v0.3 pays by id: only v0.4 needs the key. let key = match key { Some(key) => Some(key.to_owned()), - None if self.settings.line() == LezLine::V04 => self.known_key(&to)?, - None => None, + None => self.known_key(&to)?, }; - if self.settings.line() == LezLine::V04 - && key.is_none() - && !self.rpc().account_in_use(&to)? - { + if key.is_none() && !self.rpc().account_in_use(&to)? { bail!( - "{} has never been used, and LEZ v0.4 pays such an account only by its public \ + "{} has never been used, and LEZ pays such an account only by its public \ key: pass it with `--key `, as `wallet account new public` printed it or \ `wallet account get --keys` prints it", to.wallet_form() @@ -1159,13 +1205,6 @@ impl Devnet { /// Makes account group `name` with `count` accounts (at least: a group never shrinks), /// each funded with `amount`, now when the devnet runs, else when it starts. pub fn accounts_new(&self, name: &str, count: usize, amount: u64) -> Result { - // Before the first chain, the project's `[devnet]` decides which LEZ line the group is - // for, as it decides what `up` starts. - let planned = self.settings_for_up(); - if !self.home.has_chain() && planned.line() != self.settings.line() { - let devnet = Self::with(self.home.clone(), planned, self.project.clone()); - return devnet.accounts_new(name, count, amount); - } groups::check_spec(count, amount)?; self.runtime.prepare(false)?; self.make_group(name, count, amount)?; @@ -1189,7 +1228,7 @@ impl Devnet { } fn group_summaries(&self) -> Result> { - groups::list(&self.groups_dir())? + groups::list(&self.home.groups_dir())? .into_iter() .map(|group| { let info = group.info()?; @@ -1209,12 +1248,12 @@ impl Devnet { /// from the catalog, a devnet wallet opened in it, and a public account funded with /// `amount`. A failed attempt leaves nothing behind. pub fn session_new(&self, name: &str, extra: &[String], amount: u128) -> Result { - let session = Session::new(&self.sessions_dir(), name)?; + let session = Session::new(&self.home.sessions_dir(), name)?; if session.exists() { bail!("session {name} exists. `logos-devnet session rm {name}` first"); } - if self.settings.line() == LezLine::V04 { - bail!("{SESSIONS_ON_V04}"); + if !SESSIONS_READY { + bail!("{SESSIONS_WAIT}"); } let modules = session::modules_with(extra)?; // Fails before any work when there is no faucet yet. @@ -1339,7 +1378,7 @@ impl Devnet { pub fn session_list(&self) -> Result { let chain_up = self.runtime.running(); - let rows = session::list(&self.sessions_dir())? + let rows = session::list(&self.home.sessions_dir())? .into_iter() .map(|session| { let running = session.logosctl().answers_within(SESSION_CHECK_TIMEOUT); @@ -1427,7 +1466,7 @@ impl Devnet { } fn existing_session(&self, name: &str) -> Result { - let session = Session::new(&self.sessions_dir(), name)?; + let session = Session::new(&self.home.sessions_dir(), name)?; if !session.exists() { bail!("no session {name}. `logos-devnet session ls` lists them"); } @@ -1569,12 +1608,11 @@ impl Devnet { let id = self.account_id(account)?; let rpc = self.rpc(); let state = rpc.account(&id)?; - // Each program's bytes: `shards` on LEZ v0.3, `actor_states` on v0.4. - let shards: BTreeMap> = state["data"]["shards"] + // Each program's bytes. + let states: BTreeMap> = state["data"]["actor_states"] .as_object() - .or_else(|| state["data"]["actor_states"].as_object()) - .map(|shards| { - shards + .map(|states| { + states .iter() .map(|(program, bytes)| { let bytes = bytes.as_array().into_iter().flatten(); @@ -1584,11 +1622,11 @@ impl Devnet { .collect() }) .unwrap_or_default(); - let data = shards + let data = states .iter() .map(|(p, bytes)| (p.clone(), bytes.len())) .collect(); - let data_hex = shards + let data_hex = states .iter() .map(|(p, bytes)| { ( @@ -1712,10 +1750,7 @@ impl Devnet { } } std::fs::create_dir_all(dir)?; - write_json( - &path, - &wallet_config(self.settings.line(), &self.settings.sequencer_url()), - )?; + write_json(&path, &wallet_config(&self.settings.sequencer_url()))?; Ok(WalletConfig { path }) } } @@ -1949,43 +1984,28 @@ fn remove_if_present(path: &Path, remove: fn(&Path) -> std::io::Result<()>) -> R } } -/// A wallet config in the shape `lez_core` 0.5.1 writes. It reads `sequencer.sequencer_addr`; -/// the top-level `sequencer_addr` and `sequencers` are set too, so a build that reads those -/// finds the devnet as well. -fn wallet_config(line: LezLine, sequencer: &str) -> Value { - let mut config = json!({ - "multi_sequencer_client_config": { "calibration_limit": 3, "distribution_limit": 1 }, +/// The LEZ wallet's config, pointing at `sequencer`. It sets no `gas_limit`: the wallet +/// measures each transaction's gas within its default budget (2M at rc3), which leaves room for +/// a 96 KiB program segment. +fn wallet_config(sequencer: &str) -> Value { + json!({ "seq_block_poll_max_amount": 100, "seq_poll_max_retries": 10, "seq_poll_timeout": WALLET_POLL_TIMEOUT, "seq_tx_poll_max_blocks": 15, - "sequencer": { "sequencer_addr": sequencer }, - "sequencer_addr": sequencer, - "sequencers": [{ "sequencer_addr": sequencer }] - }); - // v0.3 declares this much gas on each transaction. v0.4 measures it within the - // `gas_limit` budget, whose default (2M at rc3) leaves room for a 96 KiB program segment. - if line == LezLine::V03 { - config["gas_limit"] = json!(200_000); - } - config + "sequencer": { "sequencer_addr": sequencer } + }) } -/// The wallet's arguments that send `amount` lepta from `from` to `to`. LEZ v0.4 takes an -/// account it has never seen only when the payment names its public key (`key`), and then -/// refuses `--to` beside it. -fn transfer_args( - line: LezLine, - from: &PublicId, - to: &PublicId, - key: Option<&str>, - amount: u128, -) -> Vec { +/// The wallet's arguments that send `amount` lepta from `from` to `to`. LEZ takes an account +/// it has never seen only when the payment names its public key (`key`), and then refuses `--to` +/// beside it. +fn transfer_args(from: &PublicId, to: &PublicId, key: Option<&str>, amount: u128) -> Vec { let mut args: Vec = vec!["auth-transfer".into(), "send".into(), "--from".into()]; args.push(from.wallet_form()); - match (line, key) { - (LezLine::V04, Some(key)) => args.extend(["--to-pk".into(), key.to_owned()]), - _ => args.extend(["--to".into(), to.wallet_form()]), + match key { + Some(key) => args.extend(["--to-pk".into(), key.to_owned()]), + None => args.extend(["--to".into(), to.wallet_form()]), } args.extend(["--amount".into(), amount.to_string()]); args @@ -2173,14 +2193,14 @@ 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}"); - let alice = devnet.sessions_dir().join("alice"); + 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.sessions_dir().join("bob")).unwrap(); + std::fs::create_dir_all(devnet.home.sessions_dir().join("bob")).unwrap(); let err = devnet .session_restart(&["alice".into(), "bob".into()]) .unwrap_err(); @@ -2269,7 +2289,7 @@ mod tests { let devnet = devnet_in(&dir.path().join("home")); assert!(devnet.sessions_not_running().is_empty()); for name in ["bob", "alice"] { - std::fs::create_dir_all(devnet.sessions_dir().join(name)).unwrap(); + std::fs::create_dir_all(devnet.home.sessions_dir().join(name)).unwrap(); } assert_eq!(devnet.sessions_not_running(), ["alice", "bob"]); // After `down`, a stopped daemon is no news. @@ -2282,7 +2302,7 @@ mod tests { let devnet = devnet_in(&dir.path().join("home")); assert!(devnet.daemon_logs().is_empty()); for name in ["bob", "alice"] { - std::fs::create_dir_all(devnet.sessions_dir().join(name)).unwrap(); + std::fs::create_dir_all(devnet.home.sessions_dir().join(name)).unwrap(); } std::fs::create_dir_all(devnet.home.messaging_dir()).unwrap(); let logs = devnet.daemon_logs(); @@ -2388,7 +2408,7 @@ mod tests { assert!(err.to_string().contains("no hub"), "{err}"); let err = devnet.logs(false, Some("alice"), false).unwrap_err(); assert!(err.to_string().contains("no session alice"), "{err}"); - std::fs::create_dir_all(devnet.sessions_dir().join("alice")).unwrap(); + std::fs::create_dir_all(devnet.home.sessions_dir().join("alice")).unwrap(); let err = devnet.logs(false, Some("alice"), false).unwrap_err(); assert!(err.to_string().contains("hasn't started"), "{err}"); } @@ -2563,7 +2583,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); // No project file: the session was made with `session new`. - std::fs::create_dir_all(home.sessions_dir(LezLine::V03).join("alice")).unwrap(); + std::fs::create_dir_all(home.sessions_dir().join("alice")).unwrap(); let devnet = Devnet::open(home, None).unwrap(); let err = devnet.check_needs(|| false).unwrap_err(); assert!(format!("{err:#}").contains("logosctl"), "{err:#}"); @@ -2610,37 +2630,24 @@ mod tests { } #[test] - fn wallet_configs_point_every_address_field_at_the_devnet() { - let config = wallet_config(LezLine::V03, "http://127.0.0.1:3040"); + fn wallet_configs_point_at_the_devnet() { + let config = wallet_config("http://127.0.0.1:3040"); assert_eq!( config["sequencer"]["sequencer_addr"], "http://127.0.0.1:3040" ); - assert_eq!(config["sequencer_addr"], "http://127.0.0.1:3040"); - assert_eq!( - config["sequencers"][0]["sequencer_addr"], - "http://127.0.0.1:3040" - ); - assert_eq!(config["gas_limit"], 200_000); assert_eq!(config["seq_poll_timeout"], "2s"); - // A v0.4 wallet budgets each transaction up to the block's cap when it sets none. - let config = wallet_config(LezLine::V04, "http://127.0.0.1:3040"); + // The wallet measures each transaction's gas within its own default budget. assert!(config.get("gas_limit").is_none()); - assert_eq!(config["sequencer_addr"], "http://127.0.0.1:3040"); } #[test] - fn pays_an_account_by_its_key_on_v0_4() { + fn pays_an_account_by_its_key_when_known() { let faucet = PublicId::parse(ID).unwrap(); let to = PublicId::parse("6YvesSEDWW25kpi8SSki2c8o5m3uACsigvGnNQ6wMruh").unwrap(); - let args = |line, key| transfer_args(line, &faucet, &to, key, 5); let to_id = format!("Public/{}", to.as_str()); - assert!( - args(LezLine::V03, Some("ab")).contains(&to_id), - "v0.3 pays by id" - ); - // v0.4 admits an account it has never seen only when the payment names its key. - let by_key = args(LezLine::V04, Some("ab")); + // LEZ admits an account it has never seen only when the payment names its key. + let by_key = transfer_args(&faucet, &to, Some("ab"), 5); assert!( by_key.windows(2).any(|w| w == ["--to-pk", "ab"]), "{by_key:?}" @@ -2649,25 +2656,17 @@ mod tests { !by_key.contains(&"--to".to_owned()), "--to and --to-pk conflict" ); - assert!(args(LezLine::V04, None).contains(&to_id)); + assert!(transfer_args(&faucet, &to, None, 5).contains(&to_id)); } #[test] - fn refuses_sessions_on_lez_v0_4() { + fn refuses_sessions_until_a_lez_core_for_v0_4_ships() { let dir = tempfile::tempdir().unwrap(); - let file = "home = \"home\"\n[devnet]\nlez = \"v0.4.0-rc3\"\n[sessions.alice]\n"; - let devnet = devnet_with_file(dir.path(), file); - let next = Devnet::with( - devnet.home.clone(), - devnet.settings_for_up(), - devnet.project.clone(), - ); - let err = next.check_needs(|| true).unwrap_err(); + let devnet = devnet_with_file(dir.path(), "home = \"home\"\n[sessions.alice]\n"); + assert!(devnet.refuses_sessions()); + let err = devnet.check_needs(|| true).unwrap_err(); assert!(err.to_string().contains("lez_core"), "{err}"); - let mut v04 = devnet.settings.clone(); - v04.lez = "v0.4.0-rc3".into(); - let bare = Devnet::with(devnet.home.clone(), v04, None); - let err = bare.session_new("bob", &[], 1).unwrap_err(); + let err = devnet.session_new("bob", &[], 1).unwrap_err(); assert!(err.to_string().contains("lez_core"), "{err}"); } @@ -2763,7 +2762,7 @@ mod tests { ("admins", "not json"), ("users", crate::wallet_storage::tests::SYNCED_STORAGE), ] { - let group = Group::new(&home.groups_dir(crate::home::LezLine::V03), name).unwrap(); + let group = Group::new(&home.groups_dir(), name).unwrap(); std::fs::create_dir_all(group.wallet_dir()).unwrap(); std::fs::write(group.wallet_storage(), storage).unwrap(); group.mark_new_chain().unwrap(); @@ -2789,7 +2788,7 @@ mod tests { fn up_reports_what_it_deployed_and_updated() { let id = PublicId::parse(ID).unwrap(); let mut status = Status { - lez: "v0.3.1".into(), + lez: "v0.4.0-rc3".into(), runtime: "docker".into(), sequencer: report::Sequencer { url: "http://127.0.0.1:3040".into(), @@ -2873,27 +2872,41 @@ mod tests { assert!(devnet.check_chain_takes(&dev).is_ok()); } + #[test] + fn a_v0_3_home_moves_on_only_by_reset() { + let dir = tempfile::tempdir().unwrap(); + let home = Home::locate(Some(dir.path().into())).unwrap(); + let v0_3 = Settings { + lez: "v0.3.1".into(), + ..Settings::default() + }; + home.save_settings(&v0_3).unwrap(); + for lez in [None, Some("v0.4.0-rc3".to_owned())] { + let opts = UpOptions { + lez, + ..UpOptions::default() + }; + let err = Devnet::open(home.clone(), None) + .unwrap() + .up(&opts) + .unwrap_err() + .to_string(); + assert!(err.contains("reset") && err.contains("v0.9.4"), "{err}"); + } + assert_eq!(home.load_settings().unwrap(), v0_3, "nothing changed"); + } + #[test] fn a_chain_keeps_its_own_lez_tag_without_settings() { - // A v0.4 chain whose settings.json was lost reads as the default v0.3.1: its own record - // must stop a v0.3 config being written over it. + // A chain whose settings.json was lost reads as the default tag: its own record must + // stop another tag's config being written over it. let dir = tempfile::tempdir().unwrap(); let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); std::fs::create_dir_all(home.chain_dir()).unwrap(); - home.record_chain_lez("v0.4.0-rc3").unwrap(); + home.record_chain_lez("v0.4.7").unwrap(); let devnet = Devnet::open(home, None).unwrap(); let err = devnet.check_chain_takes(&Settings::default()).unwrap_err(); - assert!(err.to_string().contains("runs LEZ v0.4.0-rc3"), "{err}"); - } - - #[test] - fn doctor_refuses_sessions_on_the_line_the_project_asks_for() { - let dir = tempfile::tempdir().unwrap(); - let file = "home = \"home\"\n[devnet]\nlez = \"v0.4.0-rc3\"\n[sessions.alice]\n"; - let devnet = devnet_with_file(dir.path(), file); - // No chain yet: the settings are still the default v0.3.1. - assert!(devnet.refuses_sessions(devnet.settings_for_up().line())); - assert!(!devnet.refuses_sessions(LezLine::V03)); + assert!(err.to_string().contains("runs LEZ v0.4.7"), "{err}"); } #[test] @@ -3118,7 +3131,10 @@ mod tests { let written = devnet.write_project_wallet_config(&target).unwrap(); let config: Value = serde_json::from_str(&std::fs::read_to_string(&written.path).unwrap()).unwrap(); - assert_eq!(config["sequencer_addr"], "http://127.0.0.1:3040"); + assert_eq!( + config["sequencer"]["sequencer_addr"], + "http://127.0.0.1:3040" + ); assert!(devnet.write_project_wallet_config(&target).is_err()); } @@ -3139,18 +3155,24 @@ mod tests { } #[test] - fn up_refuses_a_lez_tag_outside_v0_3_and_v0_4_before_saving_anything() { + fn up_refuses_a_lez_tag_outside_v0_4_before_saving_anything() { let dir = tempfile::tempdir().unwrap(); let home = Home::locate(Some(dir.path().into())).unwrap(); - let opts = UpOptions { - lez: Some("v0.5.0".into()), - ..UpOptions::default() + let up = |lez: &str| { + let opts = UpOptions { + lez: Some(lez.into()), + ..UpOptions::default() + }; + Devnet::open(home.clone(), None) + .unwrap() + .up(&opts) + .unwrap_err() + .to_string() }; - let err = Devnet::open(home.clone(), None) - .unwrap() - .up(&opts) - .unwrap_err(); - assert!(err.to_string().contains("--lez v0.3.1"), "{err}"); + let err = up("v0.5.0"); + assert!(err.contains(&format!("--lez {DEFAULT_LEZ}")), "{err}"); + let err = up("v0.3.1"); + assert!(err.contains("v0.9.4"), "{err}"); assert!(!home.settings_file().exists(), "nothing saved"); } @@ -3159,15 +3181,16 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let home = Home::locate(Some(dir.path().into())).unwrap(); std::fs::create_dir_all(home.chain_dir().join("rocksdb-0101")).unwrap(); + home.record_chain_lez(DEFAULT_LEZ).unwrap(); let opts = UpOptions { - lez: Some("v0.3.9".into()), + lez: Some("v0.4.9".into()), ..UpOptions::default() }; let err = Devnet::open(home.clone(), None) .unwrap() .up(&opts) .unwrap_err(); - assert!(err.to_string().contains("reset --lez v0.3.9"), "{err}"); + assert!(err.to_string().contains("reset --lez v0.4.9"), "{err}"); assert!(!home.settings_file().exists(), "nothing saved"); } diff --git a/src/doctor.rs b/src/doctor.rs index 996e63b..ccfd662 100644 --- a/src/doctor.rs +++ b/src/doctor.rs @@ -195,12 +195,13 @@ pub fn run(devnet: &Devnet, project_error: Option<&anyhow::Error>) -> Doctor { } } - if devnet.refuses_sessions(settings.line()) { - checks.push(fail( - "sessions", - "the project asks for sessions, which don't run on LEZ v0.4 yet", - "drop [sessions] from the project file, or stay on v0.3", - )); + if devnet.refuses_sessions() { + checks.push(Check { + name: "sessions".into(), + ok: false, + detail: crate::devnet::SESSIONS_WAIT.into(), + fix: None, + }); } if devnet.wants_hub() { diff --git a/src/groups.rs b/src/groups.rs index 34d3298..ea5de77 100644 --- a/src/groups.rs +++ b/src/groups.rs @@ -65,24 +65,22 @@ pub struct GroupAccount { pub id: PublicId, /// Hex, the form `lez_core` takes. pub hex: String, - /// Its public key, in hex: what a LEZ v0.4 genesis funds, and `send --to-pk` pays. Groups - /// made before v0.10.0 have none. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub key: Option, + /// Its public key, in hex: what genesis funds, and `send --to-pk` pays. + pub key: String, } impl GroupAccount { /// Its public key, once checked to name this account: genesis and payments by key would - /// otherwise fund another. `None` for an account from before keys were kept. - pub fn checked_key(&self) -> Result> { - match &self.key { - Some(key) if PublicId::of_key(key)? != self.id => anyhow::bail!( + /// otherwise fund another. + pub fn checked_key(&self) -> Result<&str> { + if PublicId::of_key(&self.key)? != self.id { + anyhow::bail!( "{} has a public key in accounts.json that names another account: delete its \ group, and `up` makes it again", self.id.wallet_form() - ), - key => Ok(key.as_deref()), + ); } + Ok(&self.key) } } @@ -156,7 +154,7 @@ impl Group { index: start + i, hex: id.hex(), id, - key: Some(key), + key, }), ); info @@ -190,7 +188,7 @@ mod tests { let key = crate::account::public_key_of(&secret).unwrap(); let id = PublicId::of_key(&key).unwrap(); let info = Group::extended(GroupInfo::default(), vec![(id, key.clone())]); - assert_eq!(info.accounts[0].checked_key().unwrap(), Some(key.as_str())); + assert_eq!(info.accounts[0].checked_key().unwrap(), key); let wrong = Group::extended( GroupInfo::default(), vec![(PublicId::parse(A).unwrap(), key)], diff --git a/src/home.rs b/src/home.rs index f967715..bfb5948 100644 --- a/src/home.rs +++ b/src/home.rs @@ -6,7 +6,6 @@ //! env export lines for projects (see envfile) //! chain/ the sequencer's home: its config, database and keys. `reset` deletes it. //! wallet/ the dev wallet: the faucet and each program's header key. Kept across resets. -//! LEZ v0.4's is `wallet-v0.4/`, and its account groups `accounts-v0.4/` //! compose.yaml the Docker runtime's compose file //! native/ the native runtime's checkout, build, log and pid file //! sessions/ throwaway logosctl sessions with devnet wallets (see session) @@ -26,49 +25,45 @@ use serde_json::Value; use crate::account::PublicId; -/// The LEZ release `lez_core` 0.5.1 is built on, which the public testnet runs. Bump with the -/// testnet; the image workflow builds this tag when it changes. -pub const DEFAULT_LEZ: &str = "v0.3.1"; +/// The LEZ release the devnet runs unless asked for another v0.4 tag. Bump with LEZ's releases; +/// the image workflow builds this tag when it changes. +pub const DEFAULT_LEZ: &str = "v0.4.0-rc3"; const IMAGE_REPO: &str = "ghcr.io/drptbl/logos-devnet-sequencer"; const DEFAULT_PORT: u16 = 3040; const DEFAULT_BLOCK_TIME: &str = "1s"; -/// Upstream's debug config allows 20 transactions per block. +/// Upstream's local config allows 20 transactions per block. pub const DEFAULT_MAX_TXS_PER_BLOCK: u32 = 20; /// The sequencer's log filter (`RUST_LOG`): its own progress, without its actor framework's. pub const DEFAULT_LOG_FILTER: &str = "info,kameo=warn"; -/// The LEZ release line a tag belongs to. v0.4 changes how the sequencer starts, its config, -/// the wallet's storage and how accounts are funded, so each line has its own code path. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum LezLine { - V03, - V04, +/// A LEZ tag logos-devnet runs: one of the v0.4 line, e.g. `v0.4.0-rc3`. +pub fn check_lez(tag: &str) -> Result<()> { + if is_v0_3(tag) { + anyhow::bail!("{tag} is a LEZ v0.3 tag. {V0_3_RELEASE}"); + } + if !numbered(tag, "v0.4.") { + anyhow::bail!( + "logos-devnet runs LEZ v0.4 tags, and {tag} isn't one: use `--lez {DEFAULT_LEZ}`" + ); + } + Ok(()) } -impl LezLine { - /// The line of `tag`, e.g. `v0.3.1` or `v0.4.0-rc3`. - pub fn of(tag: &str) -> Result { - let numbered = |prefix: &str| { - tag.strip_prefix(prefix) - .and_then(|patch| patch.split(['-', '.']).next()) - .is_some_and(|n| !n.is_empty() && n.bytes().all(|b| b.is_ascii_digit())) - }; - if numbered("v0.3.") { - Ok(Self::V03) - } else if numbered("v0.4.") { - Ok(Self::V04) - } else { - anyhow::bail!( - "logos-devnet runs LEZ v0.3 and v0.4 tags, and {tag} isn't one: use \ - `--lez {DEFAULT_LEZ}`, or a v0.4 tag such as `v0.4.0-rc3`" - ) - } - } +/// Where LEZ v0.3 lives on. +pub const V0_3_RELEASE: &str = "logos-devnet runs LEZ v0.4 since v0.10.0, and v0.9.4 is the last \ + release that runs v0.3: `cargo install --locked logos-devnet --version 0.9.4`, or \ + https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4"; + +/// Whether `tag` is a LEZ v0.3 tag, which homes from before v0.10.0 ran. +pub fn is_v0_3(tag: &str) -> bool { + numbered(tag, "v0.3.") } -/// A LEZ tag logos-devnet runs: one of the v0.3 or v0.4 line. -pub fn check_lez(tag: &str) -> Result<()> { - LezLine::of(tag).map(drop) +/// Whether `tag` is `prefix` and a patch number, with any suffix, e.g. `v0.4.` and `0-rc3`. +fn numbered(tag: &str, prefix: &str) -> bool { + tag.strip_prefix(prefix) + .and_then(|patch| patch.split(['-', '.']).next()) + .is_some_and(|n| !n.is_empty() && n.bytes().all(|b| b.is_ascii_digit())) } /// A log filter the sequencer takes: `RUST_LOG` syntax, e.g. `debug` or @@ -133,12 +128,6 @@ fn default_log_filter() -> String { } impl Settings { - /// The LEZ line the settings' tag belongs to. `up` checks the tag before it saves one, so - /// a tag from no line, in a hand-edited file, reads as v0.3. - pub fn line(&self) -> LezLine { - LezLine::of(&self.lez).unwrap_or(LezLine::V03) - } - pub fn image(&self) -> String { format!("{IMAGE_REPO}:{}", self.lez) } @@ -273,13 +262,8 @@ impl Home { let file = self.chain_dir().join("lez"); std::fs::write(&file, tag).with_context(|| format!("writing {}", file.display())) } - /// The dev wallet: the faucet and each program's header key. A v0.4 wallet can't read - /// v0.3 storage, so each LEZ line has its own, and its own program ids. - pub fn wallet_dir(&self, line: LezLine) -> PathBuf { - self.root.join(match line { - LezLine::V03 => "wallet", - LezLine::V04 => "wallet-v0.4", - }) + pub fn wallet_dir(&self) -> PathBuf { + self.root.join("wallet") } pub fn compose_file(&self) -> PathBuf { self.root.join("compose.yaml") @@ -287,20 +271,57 @@ impl Home { pub fn native_dir(&self) -> PathBuf { self.root.join("native") } - /// Sessions, one set per LEZ line like the dev wallet: a v0.3 session's wallet and - /// `lez_core` can't work on v0.4, and stay as they were for a return to v0.3. - pub fn sessions_dir(&self, line: LezLine) -> PathBuf { - self.root.join(match line { - LezLine::V03 => "sessions", - LezLine::V04 => "sessions-v0.4", - }) - } - /// Account groups, each with a wallet: one set per LEZ line, like the dev wallet. - pub fn groups_dir(&self, line: LezLine) -> PathBuf { - self.root.join(match line { - LezLine::V03 => "accounts", - LezLine::V04 => "accounts-v0.4", - }) + pub fn sessions_dir(&self) -> PathBuf { + self.root.join("sessions") + } + + /// Whether the chain here ran LEZ v0.3: its own record says so, or it has none and either + /// the settings (`settings_lez`) say so or it was never set up the way v0.4 chains are. + pub fn runs_v0_3(&self, settings_lez: &str) -> bool { + match self.chain_lez() { + Some(tag) => is_v0_3(&tag), + None => is_v0_3(settings_lez) || (self.has_chain() && !self.chain_set_up()), + } + } + + /// Moves a LEZ v0.3 home's wallets aside, to `-v0.3/`, so a v0.4 chain starts its own: + /// a v0.4 wallet can't read v0.3 storage. Nothing is deleted or overwritten, and a home moved + /// once isn't moved again, so a `reset` that fails later can run again. Returns the + /// directories moved. + pub fn move_v0_3_aside(&self) -> Result> { + let done = self.root.join("moved-v0.3"); + if done.exists() { + return Ok(Vec::new()); + } + let dirs = ["wallet", "accounts", "sessions"] + .map(|dir| (self.root.join(dir), self.root.join(format!("{dir}-v0.3")))); + for (from, to) in &dirs { + if from.exists() && to.exists() { + anyhow::bail!( + "{} and {} both exist: move one of them elsewhere, then `reset` again", + from.display(), + to.display() + ); + } + } + let mut moved = Vec::new(); + for (from, to) in &dirs { + if from.exists() { + std::fs::rename(from, to) + .with_context(|| format!("moving {} to {}", from.display(), to.display()))?; + moved.push( + to.file_name() + .unwrap_or_default() + .to_string_lossy() + .into_owned(), + ); + } + } + std::fs::write(&done, "").with_context(|| format!("writing {}", done.display()))?; + Ok(moved) + } + pub fn groups_dir(&self) -> PathBuf { + self.root.join("accounts") } /// Program binaries downloaded from a URL, named by their SHA-256. pub fn downloads_dir(&self) -> PathBuf { @@ -427,17 +448,18 @@ mod tests { use super::*; #[test] - fn runs_lez_v0_3_and_v0_4_tags() { - for tag in ["v0.3.1", "v0.3.2", "v0.3.10", "v0.3.2-rc1"] { - assert_eq!(LezLine::of(tag).unwrap(), LezLine::V03, "{tag}"); - } + fn runs_lez_v0_4_tags_and_points_v0_3_at_its_last_release() { for tag in ["v0.4.0-rc3", "v0.4.0", "v0.4.12"] { - assert_eq!(LezLine::of(tag).unwrap(), LezLine::V04, "{tag}"); + assert!(check_lez(tag).is_ok(), "{tag}"); + } + for tag in ["v0.3.1", "v0.3.2-rc1"] { + let err = check_lez(tag).unwrap_err().to_string(); + assert!(err.contains("v0.9.4"), "{err}"); } - for tag in ["v0.5.0", "v0.3", "v0.4.", "v0.3.x", "0.3.1", "main"] { + for tag in ["v0.5.0", "v0.4", "v0.4.", "v0.4.x", "0.4.0", "main"] { assert!(check_lez(tag).is_err(), "{tag}"); } - assert_eq!(LezLine::of(DEFAULT_LEZ).unwrap(), LezLine::V03); + assert!(check_lez(DEFAULT_LEZ).is_ok()); } #[test] @@ -453,28 +475,51 @@ mod tests { } #[test] - fn each_lez_line_keeps_its_own_wallets() { + fn moves_a_v0_3_homes_wallets_aside_once() { let dir = tempfile::tempdir().unwrap(); let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); - // A v0.4 wallet can't read v0.3 storage, so a v0.4 chain starts its own. - assert_eq!(home.wallet_dir(LezLine::V03), home.root().join("wallet")); - assert_eq!(home.groups_dir(LezLine::V03), home.root().join("accounts")); - assert_eq!( - home.wallet_dir(LezLine::V04), - home.root().join("wallet-v0.4") - ); - assert_eq!( - home.groups_dir(LezLine::V04), - home.root().join("accounts-v0.4") - ); - assert_eq!( - home.sessions_dir(LezLine::V03), - home.root().join("sessions") - ); + for d in ["wallet", "accounts", "sessions"] { + std::fs::create_dir_all(home.root().join(d)).unwrap(); + std::fs::write(home.root().join(d).join("data"), "v0.3").unwrap(); + } assert_eq!( - home.sessions_dir(LezLine::V04), - home.root().join("sessions-v0.4") + home.move_v0_3_aside().unwrap(), + ["wallet-v0.3", "accounts-v0.3", "sessions-v0.3"] ); + let kept = home.root().join("accounts-v0.3/data"); + assert_eq!(std::fs::read_to_string(&kept).unwrap(), "v0.3"); + // A `reset` that failed after the move runs again: v0.4's own groups stay where they are. + std::fs::create_dir_all(home.groups_dir()).unwrap(); + assert!(home.move_v0_3_aside().unwrap().is_empty()); + assert!(home.groups_dir().exists()); + assert_eq!(std::fs::read_to_string(kept).unwrap(), "v0.3"); + } + + #[test] + fn refuses_to_move_over_an_earlier_move() { + let dir = tempfile::tempdir().unwrap(); + let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); + for d in ["wallet", "wallet-v0.3"] { + std::fs::create_dir_all(home.root().join(d)).unwrap(); + } + let err = home.move_v0_3_aside().unwrap_err().to_string(); + assert!(err.contains("both exist"), "{err}"); + assert!(home.wallet_dir().exists()); + } + + #[test] + fn tells_a_v0_3_chain_from_a_v0_4_one() { + let dir = tempfile::tempdir().unwrap(); + let home = Home::locate(Some(dir.path().to_path_buf())).unwrap(); + assert!(!home.runs_v0_3(DEFAULT_LEZ)); + assert!(home.runs_v0_3("v0.3.1"), "the settings say so"); + // A chain with neither a record nor v0.4's setup, its settings lost. + std::fs::create_dir_all(home.chain_dir().join("rocksdb-0101")).unwrap(); + assert!(home.runs_v0_3(DEFAULT_LEZ)); + std::fs::write(home.chain_dir().join("bedrock_funding_public_key"), "f").unwrap(); + assert!(!home.runs_v0_3(DEFAULT_LEZ)); + home.record_chain_lez("v0.3.1").unwrap(); + assert!(home.runs_v0_3(DEFAULT_LEZ), "its own record wins"); } #[test] @@ -627,7 +672,7 @@ mod tests { fn names_the_image_by_lez_tag() { assert_eq!( Settings::default().image(), - "ghcr.io/drptbl/logos-devnet-sequencer:v0.3.1" + "ghcr.io/drptbl/logos-devnet-sequencer:v0.4.0-rc3" ); assert_eq!(Settings::default().sequencer_url(), "http://127.0.0.1:3040"); } diff --git a/src/report.rs b/src/report.rs index 6609653..80992bc 100644 --- a/src/report.rs +++ b/src/report.rs @@ -404,7 +404,7 @@ mod tests { #[test] fn status_fields_are_stable() { let status = Status { - lez: "v0.3.1".into(), + lez: "v0.4.0-rc3".into(), runtime: "docker".into(), sequencer: Sequencer { url: "http://127.0.0.1:3040".into(), @@ -476,7 +476,7 @@ mod tests { #[test] fn a_runtime_that_didnt_answer_leaves_the_sequencer_unknown() { let status = Status { - lez: "v0.3.1".into(), + lez: "v0.4.0-rc3".into(), runtime: "docker".into(), sequencer: Sequencer { url: "http://127.0.0.1:3040".into(), diff --git a/src/rpc.rs b/src/rpc.rs index 9dde875..67ef1ef 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -71,8 +71,8 @@ impl Rpc { .with_context(|| format!("getTransaction returned {value}")) } - /// An account's state: its `nonce` and its `data` by program id (`shards` on LEZ v0.3, - /// `actor_states` on v0.4), or null on v0.4 for an account never used. + /// An account's state: its `nonce` and its `data.actor_states` by program id, or null for an + /// account never used. pub fn account(&self, account: &PublicId) -> Result { self.call("getAccount", json!([account.as_str()])) } @@ -89,15 +89,12 @@ fn result_of(reply: Value, method: &str) -> Result { } /// Whether `getAccount`'s answer is an account in use: it sent something, or a program keeps -/// data in it. LEZ v0.3 keeps that data under `shards`, v0.4 under `actor_states`, and v0.4 -/// answers null for an account never used. +/// data in it, its balance included. It answers null for an account never used. pub(crate) fn in_use(account: &Value) -> bool { let nonce = account["nonce"].as_u64().unwrap_or(0); - let has_data = ["shards", "actor_states"].iter().any(|key| { - account["data"][key] - .as_object() - .is_some_and(|data| !data.is_empty()) - }); + let has_data = account["data"]["actor_states"] + .as_object() + .is_some_and(|data| !data.is_empty()); nonce > 0 || has_data } @@ -143,19 +140,12 @@ mod tests { #[test] fn tells_a_deployed_header_from_a_fresh_account() { - // As the sequencer answered getAccount for a header and an unused account. - let header = json!({ "nonce": 1, "data": { "shards": { "JAQ5": [29, 100] } } }); - let fresh = json!({ "nonce": 0, "data": { "shards": {} } }); - assert!(in_use(&header)); + // As the sequencer answers getAccount for a header, a funded account and unused ones. + let header = json!({ "nonce": 1, "data": { "actor_states": { "JAQ5": [29, 100] } } }); + let funded = json!({ "nonce": 0, "data": { "actor_states": { "P": [1] } } }); + let fresh = json!({ "nonce": 0, "data": { "actor_states": {} } }); + assert!(in_use(&header) && in_use(&funded)); assert!(!in_use(&fresh)); - // LEZ v0.4: `getAccount` answers null for an account never used, and keeps program data - // under `actor_states`. - assert!(!in_use(&Value::Null)); - assert!(!in_use( - &json!({ "nonce": 0, "data": { "actor_states": {} } }) - )); - assert!(in_use( - &json!({ "nonce": 0, "data": { "actor_states": { "P": [1] } } }) - )); + assert!(!in_use(&Value::Null), "an account never used"); } } diff --git a/src/runtime/docker.rs b/src/runtime/docker.rs index 678a002..c6b6f41 100644 --- a/src/runtime/docker.rs +++ b/src/runtime/docker.rs @@ -14,7 +14,7 @@ use super::{ Runtime, TimedOut, WalletArg, all_output_of, batch_script, redact_recovery_phrase, redacted, run_attached, sequencer_env, split_batch, stdout_of, stdout_within, }; -use crate::home::{Home, LezLine, Settings, write_json}; +use crate::home::{Home, Settings, write_json}; /// The image's build recipe. Built from stdin, it needs no context: it clones LEZ itself. pub const DOCKERFILE: &str = include_str!("../../docker/Dockerfile"); @@ -74,7 +74,6 @@ impl Docker { chain_dir: &self.home.chain_dir().to_string_lossy(), dev_mode: self.settings.dev_mode, log_filter: &self.settings.log_filter, - line: self.settings.line(), }); // JSON is YAML, and serde quotes every path correctly. write_json(&self.home.compose_file(), &spec) @@ -394,26 +393,17 @@ struct ComposeInputs<'a> { chain_dir: &'a str, dev_mode: bool, log_filter: &'a str, - line: LezLine, } /// The compose file. The RPC is published on loopback only: it has no caller auth. fn compose_spec(i: &ComposeInputs) -> Value { - let command = match i.line { - LezLine::V03 => json!([ - "sequencer_service", - format!("{CHAIN_MOUNT}/sequencer_config.json"), - "--port", - CONTAINER_PORT.to_string() - ]), - LezLine::V04 => json!([ - "sequencer_service", - "start", - CHAIN_MOUNT, - "--rpc-listen-address", - format!("0.0.0.0:{CONTAINER_PORT}") - ]), - }; + let command = json!([ + "sequencer_service", + "start", + CHAIN_MOUNT, + "--rpc-listen-address", + format!("0.0.0.0:{CONTAINER_PORT}") + ]); json!({ "name": i.project, "services": { @@ -439,8 +429,8 @@ fn compose_spec(i: &ComposeInputs) -> Value { "user": i.user, "profiles": ["tools"], "entrypoint": ["wallet"], - // From v0.4 the wallet asks for a password on the terminal unless this is set, - // and an empty one keeps its storage unencrypted. + // The wallet asks for a password on the terminal unless this is set, and an + // empty one keeps its storage unencrypted. "environment": { "LEE_WALLET_HOME_DIR": WALLET_MOUNT, "LEE_WALLET_PASSWORD": "" } } } @@ -454,22 +444,18 @@ mod tests { fn inputs() -> ComposeInputs<'static> { ComposeInputs { project: "logos-devnet", - image: "ghcr.io/drptbl/logos-devnet-sequencer:v0.3.1", + image: "ghcr.io/drptbl/logos-devnet-sequencer:v0.4.0-rc3", port: 3040, user: "501:20", chain_dir: "/Users/me/My Devnet/chain", dev_mode: false, log_filter: "info,kameo=warn", - line: LezLine::V03, } } #[test] - fn a_v0_4_sequencer_starts_from_its_home() { - let spec = compose_spec(&ComposeInputs { - line: LezLine::V04, - ..inputs() - }); + fn the_sequencer_starts_from_its_home() { + let spec = compose_spec(&inputs()); assert_eq!( spec["services"]["sequencer"]["command"], json!([ @@ -480,7 +466,7 @@ mod tests { "0.0.0.0:3040" ]) ); - // A v0.4 wallet asks for a password on the terminal unless this is set; empty is none. + // The wallet asks for a password on the terminal unless this is set; empty is none. assert_eq!( spec["services"]["wallet"]["environment"]["LEE_WALLET_PASSWORD"], "" @@ -579,7 +565,6 @@ mod tests { "target": "/devnet/chain" }]) ); - assert_eq!(seq["command"][1], "/devnet/chain/sequencer_config.json"); let wallet = &spec["services"]["wallet"]; assert_eq!(wallet["user"], "501:20"); assert_eq!( diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 5b28fa5..c48169e 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -66,9 +66,8 @@ pub trait Runtime { /// Starts the sequencer on the config in the chain directory. Returns once it is launched, /// not once it serves. fn start(&self) -> Result<()>; - /// Sets a new LEZ v0.4 chain's home up from the config at `Home::setup_template` (see - /// `setup_args`): its config, channel signing key and funding key file. v0.3 chains have - /// nothing to set up. + /// Sets a new chain's home up from the config at `Home::setup_template` (see `setup_args`): + /// its config, channel signing key and funding key file. fn setup_chain(&self) -> Result<()>; /// Stops the sequencer if it runs. fn stop(&self) -> Result<()>; @@ -102,7 +101,7 @@ pub trait Runtime { /// sequencer has no Bedrock node, so nothing ever pays with it. pub const FUNDING_KEY: &str = "2e03b2eff5a45478e7e79668d2a146cf2c5c7925bce927f2b1c67f2ab4fc0d26"; -/// `sequencer_service`'s arguments that set a v0.4 chain `home` up from `template`, with the +/// `sequencer_service`'s arguments that set a chain `home` up from `template`, with the /// template's genesis, so the first `start` creates the channel. pub(crate) fn setup_args(home: &str, template: &str) -> Vec { [ diff --git a/src/runtime/native.rs b/src/runtime/native.rs index 289abdd..73ed45e 100644 --- a/src/runtime/native.rs +++ b/src/runtime/native.rs @@ -17,7 +17,7 @@ use super::{ redact_recovery_phrase, redacted, run_attached, run_building, sequencer_env, split_batch, stdout_of, }; -use crate::home::{Home, LezLine, Settings}; +use crate::home::{Home, Settings}; pub struct Native { home: Home, @@ -114,21 +114,15 @@ impl Runtime for Native { .args(["build", "--release", "-p", package]); cmd }; - // Two builds, so `prove` stays out of the wallet binary. v0.3 skips the prover kernels - // the sequencer never runs; from v0.4 it links the wallet, whose prover needs them. - let mut sequencer = cargo("sequencer_service"); - if self.settings.line() == LezLine::V03 { - sequencer.env("RISC0_SKIP_BUILD_KERNELS", "1"); - } - run_building(sequencer.args(["--features", SEQUENCER_FEATURES]))?; + // Two builds, so `prove` stays out of the wallet binary. The sequencer links the wallet, + // whose prover needs risc0's CPU kernels, so they're built. + run_building(cargo("sequencer_service").args(["--features", SEQUENCER_FEATURES]))?; run_building(&mut cargo("wallet")) } fn upstream_config(&self) -> Result { - let path = find_upstream_config(&self.src()).context( - "the LEZ checkout has no sequencer/service/configs/debug/sequencer_config.json \ - or sequencer/service/networks/local.json", - )?; + let path = find_upstream_config(&self.src()) + .context("the LEZ checkout has no sequencer/service/networks/local.json")?; let text = std::fs::read_to_string(&path)?; serde_json::from_str(&text).with_context(|| format!("{} is not JSON", path.display())) } @@ -155,17 +149,10 @@ impl Runtime for Native { .append(true) .open(self.log_file())?; let mut cmd = Command::new(self.bin("sequencer_service")); - match self.settings.line() { - LezLine::V03 => cmd - .arg(self.home.chain_config()) - .args(["--listen-address", "127.0.0.1", "--port"]) - .arg(self.settings.port.to_string()), - LezLine::V04 => cmd - .arg("start") - .arg(self.home.chain_dir()) - .arg("--rpc-listen-address") - .arg(format!("127.0.0.1:{}", self.settings.port)), - }; + cmd.arg("start") + .arg(self.home.chain_dir()) + .arg("--rpc-listen-address") + .arg(format!("127.0.0.1:{}", self.settings.port)); let child = without_sequencer_vars(&mut cmd) .current_dir(self.home.chain_dir()) .envs(sequencer_env( @@ -257,8 +244,8 @@ impl Runtime for Native { } } -/// `cmd` without the `SEQUENCER_*` variables this process has: a v0.4 sequencer reads each of -/// its flags from one, and a stray one would change the devnet. +/// `cmd` without the `SEQUENCER_*` variables this process has: the sequencer reads each of its +/// flags from one, and a stray one would change the devnet. fn without_sequencer_vars(cmd: &mut Command) -> &mut Command { for (var, _) in std::env::vars_os() { if var.to_string_lossy().starts_with("SEQUENCER_") { @@ -276,19 +263,14 @@ fn runs(command: &str, bin: &Path) -> bool { .is_some_and(|rest| rest.is_empty() || rest.starts_with(' ')) } -/// Upstream's debug sequencer config, wherever this tag keeps it. +/// Upstream's local sequencer config, `sequencer/service/networks/local.json`, wherever in the +/// checkout this tag keeps it. fn find_upstream_config(dir: &Path) -> Option { let mut stack = vec![(dir.to_path_buf(), 0)]; while let Some((dir, depth)) = stack.pop() { - // v0.3's debug config, or v0.4's local one. - for (parent, name) in [ - ("sequencer/service/configs/debug", "sequencer_config.json"), - ("sequencer/service/networks", "local.json"), - ] { - let file = dir.join(name); - if dir.ends_with(parent) && file.exists() { - return Some(file); - } + let file = dir.join("local.json"); + if dir.ends_with("sequencer/service/networks") && file.exists() { + return Some(file); } if depth >= 6 { continue; @@ -309,19 +291,19 @@ mod tests { #[test] fn recognises_only_the_sequencer_binary_itself() { - let bin = Path::new("/h/native/v0.3.1/target/release/sequencer_service"); + let bin = Path::new("/h/native/v0.4.0-rc3/target/release/sequencer_service"); assert!(runs( - "/h/native/v0.3.1/target/release/sequencer_service /h/chain/c.json --port 3040", + "/h/native/v0.4.0-rc3/target/release/sequencer_service /h/chain/c.json --port 3040", bin )); assert!(runs( - "/h/native/v0.3.1/target/release/sequencer_service", + "/h/native/v0.4.0-rc3/target/release/sequencer_service", bin )); for other in [ - "lldb /h/native/v0.3.1/target/release/sequencer_service", - "vim /h/native/v0.3.1/target/release/sequencer_service.rs", - "/h/native/v0.3.1/target/release/sequencer_service_old --port 1", + "lldb /h/native/v0.4.0-rc3/target/release/sequencer_service", + "vim /h/native/v0.4.0-rc3/target/release/sequencer_service.rs", + "/h/native/v0.4.0-rc3/target/release/sequencer_service_old --port 1", ] { assert!(!runs(other, bin), "{other}"); } @@ -342,19 +324,7 @@ mod tests { } #[test] - fn finds_the_debug_config_in_either_layout() { - for layout in ["lez/sequencer/service", "sequencer/service"] { - let dir = tempfile::tempdir().unwrap(); - let debug = dir.path().join(layout).join("configs/debug"); - std::fs::create_dir_all(&debug).unwrap(); - std::fs::write(debug.join("sequencer_config.json"), "{}").unwrap(); - let found = find_upstream_config(dir.path()).unwrap(); - assert_eq!(found, debug.join("sequencer_config.json"), "{layout}"); - } - } - - #[test] - fn finds_the_v0_4_local_config() { + fn finds_the_local_config() { let dir = tempfile::tempdir().unwrap(); let networks = dir.path().join("lez/sequencer/service/networks"); std::fs::create_dir_all(&networks).unwrap(); @@ -369,9 +339,9 @@ mod tests { #[test] fn ignores_build_output() { let dir = tempfile::tempdir().unwrap(); - let debug = dir.path().join("target/sequencer/service/configs/debug"); - std::fs::create_dir_all(&debug).unwrap(); - std::fs::write(debug.join("sequencer_config.json"), "{}").unwrap(); + let networks = dir.path().join("target/sequencer/service/networks"); + std::fs::create_dir_all(&networks).unwrap(); + std::fs::write(networks.join("local.json"), "{}").unwrap(); assert!(find_upstream_config(dir.path()).is_none()); } } diff --git a/src/session.rs b/src/session.rs index d32eee1..9491036 100644 --- a/src/session.rs +++ b/src/session.rs @@ -25,8 +25,9 @@ use crate::runtime::{stdout_of, stdout_within}; use crate::wallet_storage; const LEZ_CORE: &str = "lez_core"; -/// The `lez_core` built on LEZ v0.3, the line logos-devnet runs. A later one may be built on -/// LEZ v0.4, whose fees, transactions and built-in programs a v0.3 chain doesn't take. +/// The `lez_core` sessions install. 0.5.1 is built on LEZ v0.3, which logos-devnet no longer +/// runs, so sessions wait (see `devnet::SESSIONS_READY`): this becomes the first `lez_core` +/// built on LEZ v0.4 that the Logos catalog publishes. const LEZ_CORE_VERSION: &str = "0.5.1"; /// How long `stop` waits for a daemon to exit. const STOP_TIMEOUT: Duration = Duration::from_secs(30); diff --git a/src/wallet_storage.rs b/src/wallet_storage.rs index d8e46ab..961dfe0 100644 --- a/src/wallet_storage.rs +++ b/src/wallet_storage.rs @@ -37,20 +37,11 @@ pub fn clear_new_chain(owner: &Path) -> Result<()> { type Raw = Box; type RawObject = BTreeMap; -/// The LEZ wallet's state of a fresh account, what every account holds on a new chain, in the -/// shape of `was`: v0.4 keeps program data under `actor_states` and refuses v0.3's `shards`. -fn fresh_account(was: &Raw) -> Result { - let data: Option = serde_json::from_str::(was.get())? - .get("data") - .map(|data| serde_json::from_str(data.get())) - .transpose()?; - let key = match data { - Some(data) if data.contains_key("actor_states") => "actor_states", - _ => "shards", - }; - Ok(RawValue::from_string(format!( - r#"{{"nonce":0,"data":{{"{key}":{{}}}}}}"# - ))?) +/// The LEZ wallet's state of a fresh account: what every account holds on a new chain. +fn fresh_account() -> Result { + Ok(RawValue::from_string( + r#"{"nonce":0,"data":{"actor_states":{}}}"#.into(), + )?) } /// `raw`, an object, with `change` applied to its members. @@ -87,7 +78,7 @@ fn forget_chain(text: &str) -> Result { "last_synced_block".into(), RawValue::from_string("0".into())?, ); - // v0.4 also records the block its sync started from. + // The block its sync started from, too. if storage.contains_key("synced_from_block") { storage.insert( "synced_from_block".into(), @@ -116,9 +107,8 @@ fn forget_chain(text: &str) -> Result { let mut entries: RawObject = serde_json::from_str(shared.get())?; for entry in entries.values_mut() { edit_object(entry, |entry| { - if let Some(account) = entry.get("account") { - let fresh = fresh_account(account)?; - entry.insert("account".into(), fresh); + if entry.contains_key("account") { + entry.insert("account".into(), fresh_account()?); } Ok(()) })?; @@ -137,7 +127,7 @@ fn forget_private_states(value: &mut Raw) -> Result<()> { let (keys, states): (Raw, Vec<(Raw, Raw)>) = serde_json::from_str(value.get())?; let states = states .into_iter() - .map(|(kind, account)| Ok((kind, fresh_account(&account)?))) + .map(|(kind, _)| Ok((kind, fresh_account()?))) .collect::>>()?; *value = serde_json::value::to_raw_value(&(keys, states))?; Ok(()) @@ -159,7 +149,7 @@ pub fn forget_chain_in(storage: &Path) -> Result<()> { })?; replace_file(storage, forgotten.as_bytes()) .with_context(|| format!("replacing {}", storage.display()))?; - // v0.4 caches the nullifiers it saw spent next to the storage: the old chain's. + // The wallet caches the nullifiers it saw spent next to the storage: the old chain's. let nullifiers = storage.with_extension("nullifiers"); match std::fs::remove_file(&nullifiers) { Err(e) if e.kind() != std::io::ErrorKind::NotFound => { @@ -235,17 +225,17 @@ pub(crate) mod tests { use super::*; use serde_json::Value; - /// A session's `storage.json` after a chain ran, as the LEZ wallet writes it: synced to - /// block 42, a private account and a shared one holding notes, and an account imported from - /// genesis data whose nonce only fits a u128. + /// A wallet's `storage.json` after a chain ran, in the layout LEZ v0.4.0-rc3's wallet + /// writes: synced to block 42 from block 40, a private account and a shared one holding + /// notes, and an account imported from genesis data whose nonce only fits a u128. pub(crate) const SYNCED_STORAGE: &str = r#"{ "key_chain": { "accounts": [ { "Public": { "account_id": "P", "chain_index": "/0", "data": { "k": [1, 2] } } }, { "Private": { "account_id": "Q", "chain_index": "/0", "data": { "value": [ { "keys": 2 }, [ - [ { "Regular": "111" }, { "nonce": 7, "data": { "shards": { "T": [1, 2] } } } ], - [ { "Regular": "222" }, { "nonce": 3, "data": { "shards": {} } } ] + [ "Regular", { "nonce": 7, "data": { "actor_states": { "T": [1, 2] } } } ], + [ "Regular", { "nonce": 3, "data": { "actor_states": {} } } ] ] ], "ccc": [0], "cci": 0 } } }, { "ImportedPrivate": { "account": { "nonce": 340282366920938463463374607431768211455 } } } @@ -254,10 +244,11 @@ pub(crate) mod tests { "shared_private_accounts": { "S": { "group_label": "g", "identifier": "1", "pda_seed": null, "authority_program_id": null, - "account": { "nonce": 5, "data": { "shards": { "T": [9] } } } } + "account": { "nonce": 5, "data": { "actor_states": { "T": [9] } } } } } }, "last_synced_block": 42, + "synced_from_block": 40, "labels": { "main": { "Public": "P" } } }"#; @@ -270,11 +261,12 @@ pub(crate) mod tests { "{text}" ); let storage: Value = serde_json::from_str(&text).unwrap(); - let fresh = serde_json::json!({ "nonce": 0, "data": { "shards": {} } }); + let fresh = serde_json::json!({ "nonce": 0, "data": { "actor_states": {} } }); assert_eq!(storage["last_synced_block"], 0); + assert_eq!(storage["synced_from_block"], 0); let private = &storage["key_chain"]["accounts"][1]["Private"]["data"]["value"]; assert_eq!(private[0], serde_json::json!({ "keys": 2 }), "keys stay"); - assert_eq!(private[1][0][0], serde_json::json!({ "Regular": "111" })); + assert_eq!(private[1][0][0], "Regular"); assert_eq!(private[1][0][1], fresh); assert_eq!(private[1][1][1], fresh); let shared = &storage["key_chain"]["shared_private_accounts"]["S"]; @@ -283,47 +275,17 @@ pub(crate) mod tests { // Everything else is as it was. let mut expected: Value = serde_json::from_str(SYNCED_STORAGE).unwrap(); expected["last_synced_block"] = 0.into(); + expected["synced_from_block"] = 0.into(); expected["key_chain"]["accounts"][1] = storage["key_chain"]["accounts"][1].clone(); expected["key_chain"]["shared_private_accounts"]["S"]["account"] = fresh; assert_eq!(storage, expected); } - /// A v0.4 wallet's `storage.json` after a chain ran, in the layout LEZ v0.4.0-rc3's wallet - /// writes: the private state keeps program data under `actor_states`, and the wallet - /// records where its sync started. - const SYNCED_STORAGE_V04: &str = r#"{ - "key_chain": { - "accounts": [ - { "Private": { "account_id": "Q", "chain_index": "/0", "data": { - "value": [ { "keys": 2 }, [ - [ "Regular", { "nonce": 7, "data": { "actor_states": { "T": [1, 2] } } } ] - ] ] } } } - ], - "shared_private_accounts": {} - }, - "last_synced_block": 42, - "synced_from_block": 40 -}"#; - - #[test] - fn forgets_a_v0_4_chain_in_its_own_shape() { - let storage: Value = - serde_json::from_str(&forget_chain(SYNCED_STORAGE_V04).unwrap()).unwrap(); - assert_eq!(storage["last_synced_block"], 0); - assert_eq!(storage["synced_from_block"], 0); - let state = &storage["key_chain"]["accounts"][0]["Private"]["data"]["value"][1][0]; - // v0.4 refuses `shards`: a fresh account has to be in the shape it read. - assert_eq!( - state, - &serde_json::json!(["Regular", { "nonce": 0, "data": { "actor_states": {} } }]) - ); - } - #[test] - fn drops_the_spent_nullifiers_a_v0_4_wallet_cached() { + fn drops_the_spent_nullifiers_the_wallet_cached() { let dir = tempfile::tempdir().unwrap(); let storage = dir.path().join(STORAGE_FILE); - std::fs::write(&storage, SYNCED_STORAGE_V04).unwrap(); + std::fs::write(&storage, SYNCED_STORAGE).unwrap(); let nullifiers = dir.path().join("storage.nullifiers"); std::fs::write(&nullifiers, "old chain").unwrap(); forget_chain_in(&storage).unwrap(); From 4a7621ee3fd9315c05d7e22b35f7e92e6a33a37e Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 01:00:12 +0000 Subject: [PATCH 24/28] ci: switch off the sessions job until v0.4 lez_core --- .github/workflows/ci.yml | 4 +++- .github/workflows/image.yml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1acfad6..0f15789 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,8 +81,10 @@ jobs: logos-devnet --config .github/ci/logos-devnet.toml doctor # The action with a session: it installs logosctl, which runners don't have, and the session - # comes up with a funded wallet. + # comes up with a funded wallet. Off until sessions run again: they wait for a lez_core built + # for LEZ v0.4 in the Logos catalog (see SESSIONS_READY in src/devnet.rs). action-sessions: + if: false runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 8b475e5..7933070 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -13,7 +13,7 @@ on: workflow_dispatch: inputs: lez: - description: LEZ release tag to build, e.g. v0.3.2. Empty builds the CLI's default. + description: LEZ release tag to build, e.g. v0.4.0-rc3. Empty builds the CLI's default. required: false permissions: From 51b46603d89c4d9ea0ba0baf1312300ea07f424a Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 01:00:12 +0000 Subject: [PATCH 25/28] docs: cover LEZ v0.4 only, point v0.3 at v0.9.4 --- README.md | 40 ++++++++++++++++----------------- examples/README.md | 2 ++ examples/hello-world/README.md | 2 ++ examples/messaging/README.md | 2 ++ examples/sessions/README.md | 2 ++ examples/storage/README.md | 2 ++ skills/logos-devnet/SKILL.md | 13 ++++++----- skills/logos-devnet/lez_core.md | 2 ++ skills/logos-devnet/modules.md | 2 ++ 9 files changed, 41 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 101ebde..0949629 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ A local LEZ chain for Logos development. One command starts a sequencer on your 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. +It runs LEZ v0.4, currently `v0.4.0-rc3`. For LEZ v0.3, use [v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4), the last release that runs it: `cargo install --locked logos-devnet --version 0.9.4`. Sessions wait for a `lez_core` built for v0.4, see [Sessions](#sessions). + ## Install ```bash @@ -37,12 +39,12 @@ source ~/.logos-devnet/env # LOGOS_DEVNET_SEQUENCER, LOG | Command | What it does | | --- | --- | -| `up` | Starts the devnet, or resumes it, and makes it match your `logos-devnet.toml`. Takes `--docker` or `--native`, `--lez ` (a v0.3 or v0.4 tag, see [LEZ v0.4](#lez-v04)), `--port`, `--block-time`, `--max-txs-per-block`, `--dev-mode` and `--log-filter`, and remembers them. `--rebuild` builds the image or binaries again. | +| `up` | Starts the devnet, or resumes it, and makes it match your `logos-devnet.toml`. Takes `--docker` or `--native`, `--lez ` (a v0.4 tag), `--port`, `--block-time`, `--max-txs-per-block`, `--dev-mode` and `--log-filter`, and remembers them. `--rebuild` builds the image or binaries again. | | `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, 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 [amount] [--key ]` | Sends lepta from the faucet to a public account, 10B by default. On LEZ v0.4, an account that was never used takes its public key too. | +| `fund [amount] [--key ]` | Sends lepta from the faucet to a public account, 10B by default. An account that was never used is paid by its public key: `--key`, unless it's one of the devnet's own. | | `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. | | `env` | Prints the env file. | @@ -149,7 +151,9 @@ For a wallet, give it its own directory. `wallet-config` refuses a directory tha ## Sessions -A session is a throwaway `logosctl` session wired to the devnet, for an app or an agent that talks to Logos through `logosctl`. You need `logosctl` on your `PATH`. Sessions run on LEZ v0.3 only for now: see [LEZ v0.4](#lez-v04). +> **Sessions wait for a `lez_core` built for LEZ v0.4.** The Logos catalog's newest, 0.5.1, is built for v0.3 and can't drive a v0.4 chain, so `up` refuses `[sessions]` and `session new` refuses to make one. This section, the [Messaging](#messaging) and [Storage](#storage) ones, and their examples describe how sessions work with [v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4) on LEZ v0.3. They'll be updated when a v0.4 `lez_core` ships. + +A session is a throwaway `logosctl` session wired to the devnet, for an app or an agent that talks to Logos through `logosctl`. You need `logosctl` on your `PATH`. ```bash logos-devnet session new alice # lez_core and a funded wallet @@ -170,7 +174,7 @@ Each session runs its own daemon in `~/.logos-devnet/sessions/`, with `lez Sessions follow the chain. `down` stops their daemons. `up` starts them again, loads their modules and opens their wallets, also after a `--port` change. `reset` funds each account again with what it was created with, and makes each wallet forget the old chain: its sync position and the state of its private accounts. Its keys and accounts stay. `session rm` deletes a session and its wallet. -The catalog's `lez_core` 0.5.1 is built on LEZ `v0.3.1`, the default `--lez` tag, so sessions match it. They install that version even once the catalog has a newer one, which may be built for LEZ v0.4. +Sessions install `lez_core` 0.5.1, built on LEZ v0.3, even once the catalog has a newer one: that's what waits for a v0.4 build. ## Messaging @@ -213,7 +217,7 @@ Sessions need nothing passed in: logos-devnet configures their storage before it ## What runs -LEZ's own `sequencer_service` runs, built with two features. `standalone` replaces Bedrock, the L1, with an in-process mock that accepts every block. `prove` runs programs in-process, so you don't need `r0vm`. The default is `v0.3.1`, what the public testnet runs. `--lez` picks another `v0.3` tag or a `v0.4` one, and a chain only runs one tag: `reset --lez ` to switch. +LEZ's own `sequencer_service` runs, built with two features. `standalone` replaces Bedrock, the L1, with an in-process mock that accepts every block. `prove` runs programs in-process, so you don't need `r0vm`. The default is `v0.4.0-rc3`: v0.4.0 isn't tagged yet. `--lez` picks another v0.4 tag, and a chain only runs one tag: `reset --lez ` to switch. A new chain is set up with `sequencer_service setup`, as LEZ's own local recipe does, then started from its home. Programs must be built for LEZ v0.4. | | devnet | testnet | | --- | --- | --- | @@ -223,22 +227,17 @@ LEZ's own `sequencer_service` runs, built with two features. `standalone` replac | Block timestamp | your clock | the sequencer's clock | | L1 finality, indexer | none | yes | -Fees are the testnet's. On v0.3 every call holds `gas_limit × base fee` up front, plus a little for its size, so about 1.6M lepta at a `gas_limit` of 200,000. v0.4 measures each call's gas instead. The faucet makes that irrelevant. +Fees are the testnet's: the wallet measures each call's gas and pays the base fee on it. The faucet makes that irrelevant. + +Genesis funds each account by its public key, which `accounts.json` records for every group account. Paying an account that was never used needs its public key too: `fund --key `, with the key `wallet account new public` printed. The devnet's own accounts, its groups' and the dev wallet's, are paid by theirs. `upstream_accounts = true` under `[devnet]` also keeps LEZ's own genesis accounts funded, whose keys LEZ publishes for its examples and tools. Private calls still prove on your machine, so they take as long as on the testnet: a shielded transfer from a session took 118 s on an Apple M-series laptop. Dev mode skips that. -## LEZ v0.4 +## Coming from LEZ v0.3 -`reset --lez v0.4.0-rc3`, or `lez = "v0.4.0-rc3"` under `[devnet]`, runs LEZ v0.4. It's a release candidate: v0.4.0 isn't tagged yet, and the testnet still runs v0.3. On v0.4: +logos-devnet runs LEZ v0.4 since v0.10.0. [v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4) is the last release that runs v0.3, and a project file with `lez = "v0.3.1"` needs it. -- The first `up` builds the sequencer image for that tag, which takes a while: no image is published for v0.4 yet. -- The chain is set up with `sequencer_service setup`, as LEZ's own local recipe does, then started from its home. -- A v0.4 wallet can't read v0.3 storage, so v0.4 has its own dev wallet and account groups, in `wallet-v0.4/` and `accounts-v0.4/`, and so its own program ids. Switching back with `reset --lez v0.3.1` finds the v0.3 ones as they were. -- Programs must be built for v0.4: a v0.3 binary doesn't run there. -- Genesis funds accounts by their public key, which `accounts.json` records for each account. -- An account that was never used is paid only by its public key: `fund --key `. The devnet's own accounts, its groups' and the dev wallet's, are paid by theirs without it. -- Sessions aren't supported yet: the Logos catalog has no `lez_core` for v0.4, and 0.5.1 can't drive a v0.4 chain. `up` refuses `[sessions]` on v0.4, and v0.3's sessions wait in `sessions/` as they were. -- `upstream_accounts = true` under `[devnet]` keeps LEZ's own genesis accounts funded, whose keys LEZ publishes for its examples and tools. +A home that ran v0.3, `~/.logos-devnet` included, keeps its chain until you move it on: `up` stops and says so. `logos-devnet reset` then starts a v0.4 chain there, with the v0.3 dev wallet, account groups and sessions moved aside to `wallet-v0.3/`, `accounts-v0.3/` and `sessions-v0.3/`, untouched. A v0.4 wallet can't read v0.3 storage, so the new chain gets a new faucet and new program ids, and groups are made again. ## Dev mode @@ -257,11 +256,12 @@ Everything is in `~/.logos-devnet` (or `LOGOS_DEVNET_HOME`): | `settings.json` | LEZ tag, runtime, port, block time, transactions per block, dev mode, log filter, faucet | | `env` | the env file | | `chain/` | the sequencer's config, database and keys, and whether the chain runs in dev mode. `reset` deletes it. | -| `wallet/` | the dev wallet: the faucet and each program's header key. Kept across resets. `wallet-v0.4/` is LEZ v0.4's | +| `wallet/` | the dev wallet: the faucet and each program's header key. Kept across resets. | | `compose.yaml` | the Docker runtime's compose file | | `native/` | the native runtime's LEZ checkout, build, log and pid file | -| `sessions/` | one directory per session: its `logosctl` home, its daemon's `HOME` with its storage, wallet and `session.json`. `sessions-v0.4/` is LEZ v0.4's | -| `accounts/` | one directory per account group: its wallet and `accounts.json`. `accounts-v0.4/` holds LEZ v0.4's | +| `sessions/` | one directory per session: its `logosctl` home, its daemon's `HOME` with its storage, wallet and `session.json` | +| `accounts/` | one directory per account group: its wallet and `accounts.json` | +| `*-v0.3/` | a home's LEZ v0.3 dev wallet, groups and sessions, moved aside by the `reset` that took it to v0.4 | | `programs.json` | the binary hash each program was deployed from | | `downloads/` | program binaries the project file names by URL, by SHA-256, and in `packages/` the module packages every daemon installs from, downloaded once and checked against the catalog's SHA-256. Every home uses the one in `~/.logos-devnet`, so a project's own home or a worktree's doesn't download them again. One left in another home from before v0.9.0 can be deleted | | `messaging/` | the hub, for `[messaging]` and `[storage]`: its `logosctl` home, its daemon's `HOME`, message store, ports and node keys in `hub.json` | @@ -308,7 +308,7 @@ Inputs: `version` (default: the release tag you use the action at, or, pinned to `ghcr.io/drptbl/logos-devnet-sequencer:` holds the sequencer and the LEZ `wallet` for `linux/amd64` and `linux/arm64`. `up` pulls it, and builds it locally from [`docker/Dockerfile`](docker/Dockerfile) when no image is published for your tag. To build it yourself: ```bash -docker build --build-arg LEZ_TAG=v0.3.1 -t ghcr.io/drptbl/logos-devnet-sequencer:v0.3.1 - < docker/Dockerfile +docker build --build-arg LEZ_TAG=v0.4.0-rc3 -t ghcr.io/drptbl/logos-devnet-sequencer:v0.4.0-rc3 - < docker/Dockerfile ``` ## License diff --git a/examples/README.md b/examples/README.md index 55f1529..c7a709f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,5 +1,7 @@ # Examples +`hello-world`, `sessions`, `messaging` and `storage` run with [logos-devnet v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4) and LEZ v0.3 for now: sessions wait for a `lez_core` built for LEZ v0.4, and LEZ's tutorial for a v0.4 tag. They'll be updated when those ship. + | Example | | | --- | --- | | [`hello-world`](hello-world) | LEZ's tutorial on a devnet: build a program, deploy it and call it, paid by a funded test account | diff --git a/examples/hello-world/README.md b/examples/hello-world/README.md index 08c6c93..3362d11 100644 --- a/examples/hello-world/README.md +++ b/examples/hello-world/README.md @@ -1,5 +1,7 @@ # Hello world +> **This example follows LEZ's v0.3 tutorial.** logos-devnet runs LEZ v0.4 since v0.10.0. Until LEZ tags a v0.4 release with a working tutorial, run this example with [logos-devnet v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4). It will be updated then. + LEZ's own program deployment tutorial on a devnet: you build its `hello_world` program, then deploy it and call it, paid by a funded test account. Once everything is built, a run takes about 15 s. `logos-devnet.toml` here gives the example a devnet of its own on a free port, next to a shared one on 3040, with a group of two funded accounts. The first pays for the deploy and the call, and the second gets the greeting. diff --git a/examples/messaging/README.md b/examples/messaging/README.md index c1dc09e..d3ee7cb 100644 --- a/examples/messaging/README.md +++ b/examples/messaging/README.md @@ -1,5 +1,7 @@ # Messaging +> **This example waits for a `lez_core` built for LEZ v0.4.** logos-devnet runs LEZ v0.4 since v0.10.0, and the Logos catalog's `lez_core` 0.5.1 is built for v0.3, so sessions don't run yet. Until a v0.4 one ships, run this example with [logos-devnet v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4) and LEZ v0.3. It will be updated then. + Two `logosctl` sessions, Alice and Bob, send a message and find each other's service through the devnet's messaging hub. Nothing goes through the public fleet: every node listens on `127.0.0.1`. `logos-devnet.toml` here gives the example a devnet of its own on a free port, the hub, and two sessions with `delivery_module` and `libp2p_module` installed. diff --git a/examples/sessions/README.md b/examples/sessions/README.md index 1bb20ec..a82cd6e 100644 --- a/examples/sessions/README.md +++ b/examples/sessions/README.md @@ -1,5 +1,7 @@ # Sessions +> **This example waits for a `lez_core` built for LEZ v0.4.** logos-devnet runs LEZ v0.4 since v0.10.0, and the Logos catalog's `lez_core` 0.5.1 is built for v0.3, so sessions don't run yet. Until a v0.4 one ships, run this example with [logos-devnet v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4) and LEZ v0.3. It will be updated then. + Two `logosctl` sessions, Alice and Bob, each with a funded wallet open in `lez_core`, the way an app or an agent talks to Logos. Alice pays Bob, then shields some of her funds into a private account. The devnet runs in dev mode, so the shielded transfer's proof takes a second instead of minutes. `logos-devnet.toml` here gives the example a devnet of its own on a free port, next to a shared one on 3040. `port = 0` takes a free port on the first `up` and keeps it, and `logos-devnet env` shows it. diff --git a/examples/storage/README.md b/examples/storage/README.md index 95fe5a0..2eba01b 100644 --- a/examples/storage/README.md +++ b/examples/storage/README.md @@ -1,5 +1,7 @@ # Storage +> **This example waits for a `lez_core` built for LEZ v0.4.** logos-devnet runs LEZ v0.4 since v0.10.0, and the Logos catalog's `lez_core` 0.5.1 is built for v0.3, so sessions don't run yet. Until a v0.4 one ships, run this example with [logos-devnet v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4) and LEZ v0.3. It will be updated then. + Two `logosctl` sessions, Alice and Bob, share a file through Logos Storage. Alice uploads it, and Bob downloads it by its CID. Nothing goes through the public storage network: every node listens on `127.0.0.1`. `logos-devnet.toml` here gives the example a devnet of its own on a free port, two sessions, and `[storage]`, which runs a storage node in the hub that both sessions' nodes bootstrap from. Each session's daemon starts its storage node on its own, so there's nothing to create. diff --git a/skills/logos-devnet/SKILL.md b/skills/logos-devnet/SKILL.md index 93bd0fb..50dfa1a 100644 --- a/skills/logos-devnet/SKILL.md +++ b/skills/logos-devnet/SKILL.md @@ -52,14 +52,14 @@ Pass `--json` to every command: on success stdout holds one JSON document, and n ## Choices - **Home.** Without `home`, every project on the machine shares `~/.logos-devnet` on port 3040, and `up` refuses settings that disagree with what other projects run there. Tests, worktrees and parallel agents get `home = ".logos-devnet"` and `[devnet] port = 0`, a free port of their own. -- **LEZ line.** v0.3 (default `v0.3.1`) is what the testnet runs. `lez = "v0.4.0-rc3"` runs the v0.4 release candidate: programs built for v0.4, its own dev wallet and program ids, funding by public key (`accounts.json` records each account's `key`), and no sessions yet. `upstream_accounts = true` keeps LEZ's own published genesis accounts funded for its examples. +- **LEZ.** logos-devnet runs LEZ v0.4 (default `v0.4.0-rc3`); programs must be built for it. For LEZ v0.3, use logos-devnet v0.9.4. A home that ran v0.3: `reset` moves its v0.3 wallets aside and starts v0.4. Genesis and payments name accounts by public key, which `accounts.json` records as each account's `key`. `upstream_accounts = true` keeps LEZ's own published genesis accounts funded for its examples. - **Dev mode.** `dev_mode = true` makes private calls prove in about 1 s instead of about 2 min, with fake proofs. A chain keeps its dev mode for life: switching it takes `reset`. Use a chain without dev mode to check that real proofs verify. - **Programs.** A program can be a path, or a release: `{ url = "...", sha256 = "..." }`, downloaded once and deployed only if its SHA-256 matches. Programs deploy immutable, which undisclosed private calls require. While iterating on one, give it `{ path = "...", mutable = true }`: a rebuild then updates it in place with the same id on the next `up`. Its mutability is fixed per chain, so changing it takes `reset`. `.logos-devnet/programs.json` records each deployed program's binary SHA-256 and mutability: compare it with `shasum -a 256 ` to show which build runs. -- **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. On v0.3 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; on v0.4 an account never used takes `--key ` too, unless it's one of the devnet's own. +- **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. `logos-devnet fund Public/ [lepta]` tops one account up; an account never used takes `--key ` too, unless it's one of the devnet's own. - **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 each 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. +- **Sessions** don't run yet: they wait for a `lez_core` built for LEZ v0.4 in the Logos catalog, and `up` refuses `[sessions]` until then (the session notes below, and lez_core.md and modules.md, describe them on logos-devnet v0.9.4 with LEZ v0.3). Sessions need `logosctl` on `PATH`. `logos-devnet session restart ...` gives each 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 @@ -75,9 +75,10 @@ Each refusal changes nothing. `up` prefixes a program's refusal with `program is deployed mutable, asked for immutable` (or the reverse) | Put `mutable` back as deployed, or `reset`. | | `this chain runs in dev mode` / `this chain checks proofs` | Match the chain's dev mode, or `reset --dev-mode` / `reset --dev-mode false`. | | `this chain runs LEZ ` | `reset --lez `. | -| `logos-devnet runs LEZ v0.3 and v0.4 tags` | Use a v0.3 tag, e.g. `--lez v0.3.1`, or a v0.4 one, e.g. `v0.4.0-rc3`. | -| `sessions don't run on LEZ v0.4 yet` | Drop `[sessions]` and `session rm` any session, or stay on v0.3: no `lez_core` for v0.4 is published. | -| ` has never been used, and LEZ v0.4 pays such an account only by its public key` | `fund --key `, with the key `wallet account new public` printed. | +| `logos-devnet runs LEZ v0.4 tags` / `is a LEZ v0.3 tag` | Use a v0.4 tag, e.g. `v0.4.0-rc3`, or logos-devnet v0.9.4 for LEZ v0.3. | +| `this home runs LEZ v0.3` | `reset` moves its v0.3 wallets aside and starts v0.4, or use logos-devnet v0.9.4 for it. | +| `sessions don't run yet` | Drop `[sessions]` for now: no `lez_core` for LEZ v0.4 is published. | +| ` has never been used, and LEZ pays such an account only by its public key` | `fund --key `, with the key `wallet account new public` printed. | | `the shared devnet runs with ..., but asks for ...` | Other projects use that devnet. Give this project its own `home` and port. | | `port on 127.0.0.1 is taken` | `up --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]`. | diff --git a/skills/logos-devnet/lez_core.md b/skills/logos-devnet/lez_core.md index cb0ae90..076eecc 100644 --- a/skills/logos-devnet/lez_core.md +++ b/skills/logos-devnet/lez_core.md @@ -1,5 +1,7 @@ # lez_core through logosctl +> These calls run in sessions, which wait for a `lez_core` built for LEZ v0.4: they describe sessions on logos-devnet v0.9.4 with LEZ v0.3, and will be updated when one ships. + What `lez_core`, the LEZ module in a `logosctl` session, expects. A session's env (`source <(logos-devnet session env )`) points `logosctl` at its daemon, where the wallet is open. - Account ids are hex. A session's `LOGOS_DEVNET_ACCOUNT_HEX` is its account in that form, a group's `accounts.json` has each account's `hex`, and `logos-devnet account ` prints any id in both forms. diff --git a/skills/logos-devnet/modules.md b/skills/logos-devnet/modules.md index a63a15a..f487631 100644 --- a/skills/logos-devnet/modules.md +++ b/skills/logos-devnet/modules.md @@ -1,5 +1,7 @@ # Messaging, discovery and storage through logosctl +> These calls run in sessions, which wait for a `lez_core` built for LEZ v0.4: they describe sessions on logos-devnet v0.9.4 with LEZ v0.3, and will be updated when one ships. + 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`. From 55ed06c85ab79ce830e7fe56ead43578dad67984 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 15:23:55 +0000 Subject: [PATCH 26/28] feat: name the LEZ tag in --version --- src/main.rs | 11 ++++++++--- tests/cli.rs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 25c0b81..4cf8926 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use anyhow::Result; -use clap::{Parser, Subcommand}; +use clap::{CommandFactory, FromArgMatches, Parser, Subcommand}; mod account; mod binary; @@ -24,7 +24,7 @@ mod storage; mod wallet_storage; use devnet::{DEFAULT_FUND, Devnet, UpOptions}; -use home::Home; +use home::{DEFAULT_LEZ, Home}; use project::Project; use report::emit; @@ -206,7 +206,12 @@ impl Command { } fn main() -> Result<()> { - let cli = Cli::parse(); + // The LEZ release it runs comes with the version, so which logos-devnet goes with which LEZ + // is one command away. + let version: &'static str = + Box::leak(format!("{} (LEZ {})", env!("CARGO_PKG_VERSION"), DEFAULT_LEZ).into_boxed_str()); + let matches = Cli::command().version(version).get_matches(); + let cli = Cli::from_arg_matches(&matches).unwrap_or_else(|e| e.exit()); let json = cli.json; let project_file = match cli.config { Some(path) => Some(path), diff --git a/tests/cli.rs b/tests/cli.rs index d90beeb..d1922f9 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -19,3 +19,23 @@ fn up_says_docker_is_unreachable_instead_of_building() { assert!(stderr.contains("no Docker daemon answers"), "{stderr}"); assert!(!stderr.contains("Building"), "{stderr}"); } + +#[test] +fn the_version_names_the_lez_release_it_runs() { + let out = Command::new(env!("CARGO_BIN_EXE_logos-devnet")) + .arg("--version") + .output() + .unwrap(); + let stdout = String::from_utf8_lossy(&out.stdout); + let home = + std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/src/home.rs")).unwrap(); + let lez = home + .lines() + .find_map(|l| l.strip_prefix("pub const DEFAULT_LEZ: &str = \"")) + .and_then(|l| l.strip_suffix("\";")) + .unwrap(); + assert_eq!( + stdout.trim(), + format!("logos-devnet {} (LEZ {lez})", env!("CARGO_PKG_VERSION")) + ); +} From 1c539f7bb261d6e4551a25a08acf18935ea47973 Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 15:24:20 +0000 Subject: [PATCH 27/28] ci: open release notes with the LEZ tag --- .github/workflows/release.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index be30912..7bef514 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -109,8 +109,16 @@ jobs: echo "tag $TAG moved to $tagged after $GITHUB_SHA was checked" >&2 exit 1 fi + # The notes open with the LEZ release this one runs, read from the tagged source. + lez=$(gh api "repos/$GITHUB_REPOSITORY/contents/src/home.rs?ref=$TAG" --jq .content \ + | base64 -d | sed -n 's/^pub const DEFAULT_LEZ: &str = "\(.*\)";$/\1/p') + if [[ ! "$lez" =~ ^v[0-9]+(\.[0-9]+)*(-[A-Za-z0-9.]+)?$ ]]; then + echo "no LEZ tag in src/home.rs at $TAG: '$lez'" >&2 + exit 1 + fi gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --verify-tag \ - --title "$TAG" --generate-notes dist/* + --title "$TAG" --generate-notes dist/* \ + --notes "Runs LEZ $lez. See [which version](https://github.com/$GITHUB_REPOSITORY#which-version) for every release's LEZ." crates-io: needs: github-release From 4e3a109c3249d41ca0f57489f5bf4b25b4518c7c Mon Sep 17 00:00:00 2001 From: Jakub Mucha Date: Sat, 21 Nov 2026 15:24:34 +0000 Subject: [PATCH 28/28] docs: map logos-devnet releases to LEZ lines --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0949629..3934f20 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A local LEZ chain for Logos development. One command starts a sequencer on your 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. -It runs LEZ v0.4, currently `v0.4.0-rc3`. For LEZ v0.3, use [v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4), the last release that runs it: `cargo install --locked logos-devnet --version 0.9.4`. Sessions wait for a `lez_core` built for v0.4, see [Sessions](#sessions). +It runs LEZ v0.4, currently `v0.4.0-rc3`. For LEZ v0.3, use [v0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4), the last release that runs it: `cargo install --locked logos-devnet --version 0.9.4`. [Which version](#which-version) lists every release's LEZ. Sessions wait for a `lez_core` built for v0.4, see [Sessions](#sessions). ## Install @@ -26,6 +26,17 @@ Put `~/.local/bin` on your `PATH` if it isn't. `cargo install --locked --git htt It runs on macOS and Linux, and needs Docker (OrbStack, Docker Desktop or Colima). There's no Windows build. With `--native` you need git, a Rust toolchain and LEZ's build dependencies instead: clang, pkg-config and OpenSSL (`brew install pkg-config openssl` on macOS), plus `libpcsclite-dev` on Linux. The first native build takes a few minutes. +## Which version + +Each logos-devnet release runs one LEZ line, and a new LEZ line gets a new minor release: pick the newest release in the row for the LEZ you build on. + +| logos-devnet | LEZ | Default `--lez` | +| --- | --- | --- | +| 0.10.x | v0.4 | `v0.4.0-rc3` | +| 0.1.0 to [0.9.4](https://github.com/drptbl/logos-devnet/releases/tag/v0.9.4) | v0.3 | `v0.3.1` | + +`logos-devnet --version` names the LEZ tag it runs, e.g. `logos-devnet 0.10.0 (LEZ v0.4.0-rc3)`, and each release's notes open with it. + ## Use it ```bash