Skip to content

Commit 18726ab

Browse files
committed
fix multi-output outputs file naming (& ui icons), parametrize & reduce PoW of Stone from 3 to 2 (since now proving in general already involves more recursive steps
1 parent 8e222e1 commit 18726ab

File tree

9 files changed

+83
-58
lines changed

9 files changed

+83
-58
lines changed

app_cli/src/lib.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use common::{
1616
use craftlib::{
1717
constants::{
1818
AXE_BLUEPRINT, AXE_MINING_MAX, AXE_WORK, DUST_BLUEPRINT, DUST_MINING_MAX, DUST_WORK,
19-
GEM_BLUEPRINT, STONE_BLUEPRINT, STONE_MINING_MAX, WOOD_BLUEPRINT, WOOD_MINING_MAX,
20-
WOOD_WORK, WOODEN_AXE_BLUEPRINT, WOODEN_AXE_MINING_MAX, WOODEN_AXE_WORK,
19+
GEM_BLUEPRINT, STONE_BLUEPRINT, STONE_MINING_MAX, STONE_WORK_COST, WOOD_BLUEPRINT,
20+
WOOD_MINING_MAX, WOOD_WORK, WOODEN_AXE_BLUEPRINT, WOODEN_AXE_MINING_MAX, WOODEN_AXE_WORK,
2121
},
2222
item::{CraftBuilder, MiningRecipe},
2323
powpod::PowPod,
@@ -375,7 +375,7 @@ impl Helper {
375375
pub fn craft_item(
376376
params: &Params,
377377
recipe: Recipe,
378-
output: &Path,
378+
outputs: &[PathBuf],
379379
inputs: &[PathBuf],
380380
) -> anyhow::Result<Vec<PathBuf>> {
381381
let vd_set = DEFAULT_VD_SET.clone();
@@ -397,7 +397,7 @@ pub fn craft_item(
397397
let pow_pod = PowPod::new(
398398
params,
399399
vd_set.clone(),
400-
3, // num_iters
400+
STONE_WORK_COST, // num_iters
401401
RawValue::from(ingredients_def.dict(params)?.commitment()),
402402
)?;
403403
log::info!("[TIME] PowPod proving time: {:?}", start.elapsed());
@@ -491,7 +491,7 @@ pub fn craft_item(
491491
// create output dir (if there is a parent dir), in case it does not exist
492492
// yet, so that later when creating the file we don't get an error if the
493493
// directory does not exist
494-
if let Some(dir) = output.parent() {
494+
if let Some(dir) = outputs[0].parent() {
495495
std::fs::create_dir_all(dir)?;
496496
}
497497

@@ -513,14 +513,8 @@ pub fn craft_item(
513513

514514
let filenames: Vec<PathBuf> = item_def
515515
.iter()
516-
.map(|ItemDef { index, batch: _ }| {
517-
let suffix = if pods.len() > 1 {
518-
format!("_{}", index.name())
519-
} else {
520-
"".to_string()
521-
};
522-
format! {"{}{suffix}", output.display()}.into()
523-
})
516+
.enumerate()
517+
.map(|(i, _)| format! {"{}", outputs[i].display()}.into())
524518
.collect();
525519

526520
for (filename, (def, pod)) in

app_cli/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ enum Commands {
2828
Craft {
2929
#[arg(long, value_name = "RECIPE")]
3030
recipe: String,
31-
#[arg(long, value_name = "FILE")]
32-
output: PathBuf,
31+
#[arg(long = "input", value_name = "FILE")]
32+
outputs: Vec<PathBuf>,
3333
#[arg(long = "input", value_name = "FILE")]
3434
inputs: Vec<PathBuf>,
3535
},
@@ -59,11 +59,11 @@ async fn main() -> anyhow::Result<()> {
5959
match cli.command {
6060
Some(Commands::Craft {
6161
recipe,
62-
output,
62+
outputs,
6363
inputs,
6464
}) => {
6565
let recipe = Recipe::from_str(&recipe)?;
66-
craft_item(&params, recipe, &output, &inputs)?;
66+
craft_item(&params, recipe, &outputs, &inputs)?;
6767
}
6868
Some(Commands::Commit { input }) => {
6969
commit_item(&params, &cfg, &input).await?;

app_gui/src/crafting.rs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ pub struct Crafting {
549549
pub selected_action: Option<&'static str>,
550550
// Input index to item index
551551
pub input_items: HashMap<usize, usize>,
552-
pub output_filename: String,
552+
pub outputs_filename: Vec<String>,
553553
pub craft_result: Option<Result<Vec<PathBuf>>>,
554554
pub commit_result: Option<Result<PathBuf>>,
555555
}
@@ -737,11 +737,20 @@ impl App {
737737

738738
self.crafting.selected_action = selected_action;
739739

740-
// NOTE: If we don't show filenames in the left panel, then we shouldn't ask for a
741-
// filename either.
742-
if self.crafting.output_filename.is_empty() {
743-
self.crafting.output_filename =
744-
format!("{:?}_{}", process, self.items.len() + self.used_items.len());
740+
// prepare the outputs names that will be used to store the outputs files
741+
let process_outputs = process.data().outputs;
742+
if self.crafting.outputs_filename.is_empty() {
743+
self.crafting.outputs_filename = process_outputs
744+
.iter()
745+
.enumerate()
746+
.map(|(i, process_output)| {
747+
format!(
748+
"{}_{}",
749+
process_output,
750+
self.items.len() + self.used_items.len() + i
751+
)
752+
})
753+
.collect();
745754
}
746755

747756
ui.add_space(8.0);
@@ -771,11 +780,15 @@ impl App {
771780
});
772781

773782
if button_craft_clicked {
774-
if self.crafting.output_filename.is_empty() {
783+
if self.crafting.outputs_filename.is_empty() {
775784
self.crafting.craft_result = Some(Err(anyhow!("Please enter a filename.")));
776785
} else {
777-
let output =
778-
Path::new(&self.cfg.pods_path).join(&self.crafting.output_filename);
786+
let outputs_paths = self
787+
.crafting
788+
.outputs_filename
789+
.iter()
790+
.map(|output| Path::new(&self.cfg.pods_path).join(output))
791+
.collect();
779792
let input_paths = (0..inputs.len())
780793
.map(|i| {
781794
self.crafting
@@ -798,7 +811,7 @@ impl App {
798811
params: self.params.clone(),
799812
pods_path: self.cfg.pods_path.clone(),
800813
recipe,
801-
output,
814+
outputs: outputs_paths,
802815
input_paths,
803816
})
804817
.unwrap();
@@ -809,7 +822,7 @@ impl App {
809822
}
810823

811824
if button_commit_clicked {
812-
if self.crafting.output_filename.is_empty() {
825+
if self.crafting.outputs_filename.is_empty() {
813826
self.crafting.commit_result = Some(Err(anyhow!("Please enter a filename.")));
814827
} else if self.crafting.craft_result.is_none()
815828
|| self.crafting.craft_result.as_ref().unwrap().is_err()
@@ -837,11 +850,15 @@ impl App {
837850
}
838851

839852
if button_craft_and_commit_clicked {
840-
if self.crafting.output_filename.is_empty() {
853+
if self.crafting.outputs_filename.is_empty() {
841854
self.crafting.commit_result = Some(Err(anyhow!("Please enter a filename.")));
842855
} else {
843-
let output =
844-
Path::new(&self.cfg.pods_path).join(&self.crafting.output_filename);
856+
let outputs_paths = self
857+
.crafting
858+
.outputs_filename
859+
.iter()
860+
.map(|output| Path::new(&self.cfg.pods_path).join(output))
861+
.collect();
845862
let input_paths = (0..inputs.len())
846863
.map(|i| {
847864
self.crafting
@@ -865,7 +882,7 @@ impl App {
865882
cfg: self.cfg.clone(),
866883
pods_path: self.cfg.pods_path.clone(),
867884
recipe,
868-
output,
885+
outputs: outputs_paths,
869886
input_paths,
870887
})
871888
.unwrap();

app_gui/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl eframe::App for App {
6868
log::error!("{e:?}");
6969
}
7070
// Reset filename
71-
self.crafting.output_filename = "".to_string();
71+
self.crafting.outputs_filename = vec![];
7272
self.crafting.commit_result = Some(r);
7373
}
7474
Response::CraftAndCommit(r) => {
@@ -82,7 +82,7 @@ impl eframe::App for App {
8282
self.refresh_items().unwrap();
8383
self.crafting.input_items = HashMap::new();
8484
// Reset filename
85-
self.crafting.output_filename = "".to_string();
85+
self.crafting.outputs_filename = vec![];
8686
self.crafting.craft_result = None;
8787
self.crafting.commit_result = r.map(|entries| Ok(entries[0].clone())).ok();
8888
}

app_gui/src/task_system.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum Request {
1919
params: Params,
2020
pods_path: String,
2121
recipe: Recipe,
22-
output: PathBuf,
22+
outputs: Vec<PathBuf>,
2323
input_paths: Vec<PathBuf>,
2424
},
2525
Commit {
@@ -32,7 +32,7 @@ pub enum Request {
3232
cfg: Config,
3333
pods_path: String,
3434
recipe: Recipe,
35-
output: PathBuf,
35+
outputs: Vec<PathBuf>,
3636
input_paths: Vec<PathBuf>,
3737
},
3838
Exit,
@@ -55,24 +55,31 @@ pub fn handle_req(task_status: &RwLock<TaskStatus>, req: Request) -> Response {
5555
params,
5656
pods_path,
5757
recipe,
58-
output,
58+
outputs,
5959
input_paths,
60-
} => craft(task_status, &params, pods_path, recipe, output, input_paths),
60+
} => craft(
61+
task_status,
62+
&params,
63+
pods_path,
64+
recipe,
65+
outputs,
66+
input_paths,
67+
),
6168
Request::Commit { params, cfg, input } => commit(task_status, &params, cfg, input),
6269
Request::CraftAndCommit {
6370
params,
6471
cfg,
6572
pods_path,
6673
recipe,
67-
output,
74+
outputs,
6875
input_paths,
6976
} => {
7077
let craft_res = craft(
7178
task_status,
7279
&params,
7380
pods_path,
7481
recipe,
75-
output.clone(),
82+
outputs,
7683
input_paths,
7784
);
7885
match craft_res {
@@ -98,13 +105,13 @@ fn craft(
98105
params: &Params,
99106
pods_path: String,
100107
recipe: Recipe,
101-
output: PathBuf,
108+
outputs: Vec<PathBuf>,
102109
input_paths: Vec<PathBuf>,
103110
) -> Response {
104111
set_busy_task(task_status, "Crafting");
105112

106113
let start = std::time::Instant::now();
107-
let r = craft_item(params, recipe, &output, &input_paths);
114+
let r = craft_item(params, recipe, &outputs, &input_paths);
108115
log::info!("[TIME] total Craft Item time: {:?}", start.elapsed());
109116

110117
// move the files of the used inputs into the `used` subdir

craftlib/src/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use pod2::middleware::{EMPTY_VALUE, RawValue};
33
pub const STONE_BLUEPRINT: &str = "stone";
44
pub const STONE_MINING_MAX: u64 = 0x0020_0000_0000_0000;
55
pub const STONE_WORK: RawValue = EMPTY_VALUE;
6+
pub const STONE_WORK_COST: usize = 2;
67

78
pub const WOOD_BLUEPRINT: &str = "wood";
89
pub const WOOD_MINING_MAX: u64 = 0x0020_0000_0000_0000;

craftlib/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ mod tests {
474474
let pow_pod = PowPod::new(
475475
&params,
476476
vd_set.clone(),
477-
3, // num_iters
477+
crate::constants::STONE_WORK_COST, // num_iters
478478
RawValue::from(ingredients_def.dict(&params)?.commitment()),
479479
)?;
480480
let main_pow_pod = MainPod {

craftlib/src/predicates.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use commitlib::predicates::CommitPredicates;
44
use pod2::middleware::{CustomPredicateRef, Params};
55
use pod2utils::PredicateDefs;
66

7+
use crate::constants::STONE_WORK_COST;
8+
79
pub struct ItemPredicates {
810
pub defs: PredicateDefs,
911

@@ -18,33 +20,34 @@ impl ItemPredicates {
1820
// 8 arguments per predicate, at most 5 of which are public
1921
// 5 statements per predicate
2022
let batch_defs = [
21-
r#"
23+
&format!(
24+
r#"
2225
use intro Pow(count, input, output) from 0x3493488bc23af15ac5fabe38c3cb6c4b66adb57e3898adf201ae50cc57183f65 // powpod vd hash
2326
2427
// Example of a mined item with no inputs or sequential work.
2528
// Stone requires working in a stone mine (blueprint="stone") and
2629
// 10 leading 0s.
2730
IsStone(item, private: ingredients, inputs, key, work) = AND(
2831
ItemDef(item, ingredients, inputs, key, work)
29-
Equal(inputs, {})
32+
Equal(inputs, {{}})
3033
DictContains(ingredients, "blueprint", "stone")
31-
Pow(3, ingredients, work)
34+
Pow({STONE_WORK_COST}, ingredients, work)
3235
)
3336
3437
// Example of a mined item which is more common but takes more work to
3538
// extract.
3639
IsWood(item, private: ingredients, inputs, key, work) = AND(
3740
ItemDef(item, ingredients, inputs, key, work)
38-
Equal(inputs, {})
41+
Equal(inputs, {{}})
3942
DictContains(ingredients, "blueprint", "wood")
40-
Equal(work, {})
43+
Equal(work, {{}})
4144
// TODO input POD: SequentialWork(ingredients, work, 5)
4245
// TODO input POD: HashInRange(0, 1<<5, ingredients)
4346
)
4447
4548
AxeInputs(inputs, private: s1, wood, stone) = AND(
4649
// 2 ingredients
47-
SetInsert(s1, {}, wood)
50+
SetInsert(s1, {{}}, wood)
4851
SetInsert(inputs, s1, stone)
4952
5053
// prove the ingredients are correct.
@@ -57,11 +60,12 @@ impl ItemPredicates {
5760
IsAxe(item, private: ingredients, inputs, key, work) = AND(
5861
ItemDef(item, ingredients, inputs, key, work)
5962
DictContains(ingredients, "blueprint", "axe")
60-
Equal(work, {})
63+
Equal(work, {{}})
6164
6265
AxeInputs(inputs)
6366
)
64-
"#,
67+
"#
68+
),
6569
r#"
6670
6771
// Wooden Axe:
@@ -214,7 +218,7 @@ mod tests {
214218
let pow_pod = PowPod::new(
215219
&params,
216220
vd_set.clone(),
217-
3,
221+
STONE_WORK_COST,
218222
RawValue::from(ingredients_def.dict(&params)?.commitment()),
219223
)?;
220224
let main_pow_pod = MainPod {

shell.nix

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
let
44
dlopenLibraries = with pkgs; [
55
libxkbcommon
6-
libxkbcommon.dev
6+
# libxkbcommon.dev
77

8+
#vulkan-loader
89
wayland
9-
wayland.dev
10+
# wayland.dev
1011
wayland-protocols
11-
emacs
12+
sway
1213
mesa
1314
mesa-gl-headers
1415
egl-wayland
@@ -17,9 +18,10 @@ let
1718
in pkgs.mkShell {
1819
nativeBuildInputs = with pkgs; [
1920
rustup
20-
mesa
21-
mesa-gl-headers
21+
gcc
22+
pkg-config
2223
];
2324

24-
env.RUSTFLAGS = "-C link-arg=-Wl,-rpath,${pkgs.lib.makeLibraryPath dlopenLibraries}";
25+
env.RUSTFLAGS = "-C linker=clang -C link-arg=-Wl,-rpath,${pkgs.lib.makeLibraryPath dlopenLibraries}";
26+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath dlopenLibraries;
2527
}

0 commit comments

Comments
 (0)