Skip to content

Commit 76c2277

Browse files
committed
mkconfig accept +20s, run.rs accepts single quoted multi-words
1 parent b75a0b3 commit 76c2277

File tree

6 files changed

+54
-36
lines changed

6 files changed

+54
-36
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

justfile

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,19 @@ test-dyn-comm: build_release_until build-test-utils
210210
--parent-chain-id 31337 \
211211
--parent-ibox-contract 0xa0f3a1a4e2b2bcb7b48c8527c28098f207572ec1 \
212212
--key-manager-contract 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35 \
213-
--timestamp `just now-plus-20s` \
213+
--timestamp +18s \
214214
--stamp-dir /tmp \
215215
--output test-configs/c1" \
216216
--run "6:sleep 8" \
217217
--run "7:target/release/register \
218218
-a threshold-enc-key \
219-
-m attend__SPACE__year__SPACE__erase__SPACE__basket__SPACE__blind__SPACE__adapt__SPACE__stove__SPACE__broccoli__SPACE__isolate__SPACE__unveil__SPACE__acquire__SPACE__category \
219+
-m 'attend year erase basket blind adapt stove broccoli isolate unveil acquire category' \
220220
-u http://localhost:8545 \
221221
-k 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35 \
222222
-c test-configs/c0/committee.toml" \
223223
--run "8:target/release/register \
224224
-a new-committee \
225-
-m attend__SPACE__year__SPACE__erase__SPACE__basket__SPACE__blind__SPACE__adapt__SPACE__stove__SPACE__broccoli__SPACE__isolate__SPACE__unveil__SPACE__acquire__SPACE__category \
225+
-m 'attend year erase basket blind adapt stove broccoli isolate unveil acquire category' \
226226
-u http://localhost:8545 \
227227
-k 0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35 \
228228
-c test-configs/c1/committee.toml" \
@@ -235,8 +235,3 @@ test-dyn-comm: build_release_until build-test-utils
235235
--committee-id 1 \
236236
--until 800 \
237237
--required-decrypt-rounds 3 && rm -rf test-configs/c1
238-
239-
# portable calculation of now() + 20s in "%Y-%m-%dT%H:%M:%SZ" format
240-
[private]
241-
now-plus-20s:
242-
@python3 -c 'from datetime import datetime, timedelta, timezone; print((datetime.now(timezone.utc)+timedelta(seconds=20)).strftime("%Y-%m-%dT%H:%M:%SZ"))'

test-utils/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ anyhow = { workspace = true }
2828
clap = { workspace = true }
2929
futures = { workspace = true }
3030
rustix = { workspace = true }
31-
shell-words = "1.1"
3231
tokio = { workspace = true }
3332
tracing = { workspace = true }
3433
# optional

test-utils/src/binaries/run.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::future::pending;
22
use std::ops::{Deref, DerefMut};
3+
use std::process::ExitStatus;
34
use std::time::Duration;
4-
use std::{ffi::OsStr, process::ExitStatus};
55

66
use anyhow::{Result, anyhow, bail};
77
use clap::Parser;
@@ -51,16 +51,15 @@ async fn main() -> Result<()> {
5151

5252
for commandline in commands {
5353
if args.verbose {
54-
let joined = commandline.args.join(" ");
5554
if commandline.sync {
56-
eprintln!("running command: {joined}");
55+
eprintln!("running command: {}", commandline.args)
5756
} else {
58-
eprintln!("spawning command: {joined}");
57+
eprintln!("spawning command: {}", commandline.args)
5958
}
6059
}
6160

62-
let mut pg = ProcessGroup::spawn(&commandline.args)?;
6361
if commandline.sync {
62+
let mut pg = ProcessGroup::spawn(commandline.args.split_whitespace())?;
6463
let status = select! {
6564
s = pg.wait() => s?,
6665
_ = term.recv() => return Ok(()),
@@ -70,8 +69,8 @@ async fn main() -> Result<()> {
7069
bail!("{:?} failed with {:?}", commandline.args, status.code());
7170
}
7271
} else {
72+
let mut pg = ProcessGroup::spawn(commandline.args.split_whitespace())?;
7373
helpers.spawn(async move {
74-
let mut pg = ProcessGroup::spawn(&commandline.args)?;
7574
let status = pg.wait().await?;
7675
Ok(status)
7776
});
@@ -112,20 +111,15 @@ async fn main() -> Result<()> {
112111
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
113112
struct Commandline {
114113
prio: u8,
115-
args: Vec<String>,
114+
args: String,
116115
sync: bool,
117116
}
118117

119118
fn parse_command_line(s: &str) -> Result<Commandline> {
120119
let (p, a) = s.split_once(':').unwrap_or(("0", s));
121-
// Replace __SPACE__ with actual spaces, then split like shell would
122-
let parts = shell_words::split(a)?
123-
.into_iter()
124-
.map(|arg| arg.replace("__SPACE__", " "))
125-
.collect();
126120
Ok(Commandline {
127121
prio: p.parse()?,
128-
args: parts,
122+
args: a.to_string(),
129123
sync: true,
130124
})
131125
}
@@ -137,14 +131,33 @@ impl ProcessGroup {
137131
fn spawn<I, S>(it: I) -> Result<Self>
138132
where
139133
I: IntoIterator<Item = S>,
140-
S: AsRef<OsStr>,
134+
S: Into<String> + AsRef<str>,
141135
{
142136
let mut args = it.into_iter();
143137
let exe = args
144138
.next()
145139
.ok_or_else(|| anyhow!("invalid command-line args"))?;
146-
let mut cmd = Command::new(exe);
147-
cmd.args(args);
140+
let mut cmd = Command::new(exe.as_ref());
141+
let mut buf: Option<Vec<String>> = None;
142+
for a in args {
143+
if let Some(b) = &mut buf {
144+
let mut a = a.into();
145+
if a.ends_with("'") {
146+
a.pop();
147+
b.push(a);
148+
cmd.arg(b.join(" "));
149+
buf = None
150+
} else {
151+
b.push(a);
152+
}
153+
} else if a.as_ref().starts_with("'") {
154+
let mut a = a.into();
155+
a.remove(0);
156+
buf = Some(vec![a]);
157+
} else {
158+
cmd.arg(a.as_ref());
159+
}
160+
}
148161
cmd.process_group(0);
149162
let child = cmd.spawn()?;
150163
let id = child.id().ok_or_else(|| anyhow!("child already exited"))?;

timeboost-config/src/binaries/mkconfig.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ use std::io::Write;
33
use std::net::IpAddr;
44
use std::num::NonZeroU8;
55
use std::path::PathBuf;
6+
use std::str::FromStr;
67

78
use alloy::eips::BlockNumberOrTag;
89
use anyhow::{Result, bail};
910
use ark_std::rand::SeedableRng as _;
1011
use clap::{Parser, ValueEnum};
1112
use cliquenet::Address;
13+
use jiff::{SignedDuration, Timestamp};
1214
use multisig::x25519;
1315
use secp256k1::rand::SeedableRng as _;
1416
use timeboost_config::{ChainConfig, ParentChain};
@@ -38,7 +40,7 @@ struct Args {
3840
/// The timestamp format corresponds to RFC 3339, section 5.6, for example:
3941
/// 1970-01-01T18:00:00Z.
4042
#[clap(long)]
41-
timestamp: jiff::Timestamp,
43+
timestamp: TimestampOrOffset,
4244

4345
/// The sailfish network address. Decrypter, certifier, and internal address are derived:
4446
/// sharing the same IP as the sailfish IP, and a different (but fixed) port number.
@@ -108,6 +110,23 @@ struct Args {
108110
output: PathBuf,
109111
}
110112

113+
#[derive(Debug, Clone)]
114+
struct TimestampOrOffset(Timestamp);
115+
116+
impl FromStr for TimestampOrOffset {
117+
type Err = String;
118+
119+
fn from_str(s: &str) -> Result<Self, Self::Err> {
120+
if let Ok(ts) = Timestamp::from_str(s) {
121+
Ok(Self(ts))
122+
} else if let Ok(dur) = s.parse::<SignedDuration>() {
123+
Ok(Self(Timestamp::now() + dur))
124+
} else {
125+
Err("Expected RFC3339 timestamp or [+/-]duration".into())
126+
}
127+
}
128+
}
129+
111130
/// How should addresses be updated?
112131
#[derive(Clone, Copy, Debug, Default, ValueEnum)]
113132
enum Mode {
@@ -216,7 +235,7 @@ impl Args {
216235
}
217236

218237
let committee_config = CommitteeConfig {
219-
effective_timestamp: self.timestamp,
238+
effective_timestamp: self.timestamp.0,
220239
members,
221240
};
222241
committee_config_file.write_all(toml::to_string_pretty(&committee_config)?.as_bytes())?;

timeboost-contract/src/binaries/register.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ struct Args {
4242
}
4343

4444
/// Specific register action
45-
#[derive(Clone, Copy, Debug, Default, ValueEnum)]
45+
#[derive(Clone, Copy, Debug, ValueEnum)]
4646
enum Action {
4747
/// register the next committee
48-
#[default]
4948
NewCommittee,
5049
/// register the threshold encryption key (when ready)
5150
ThresholdEncKey,

0 commit comments

Comments
 (0)