Skip to content

Commit

Permalink
refactor, drop binary executables from repository
Browse files Browse the repository at this point in the history
  • Loading branch information
nybbs2003 committed Oct 27, 2023
1 parent 9f9c9fa commit 38330ae
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 262 deletions.
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hk.zdl.crpto</groupId>
<groupId>hk.zdl.crypto</groupId>
<artifactId>tura-miner</artifactId>
<version>1.1.0-SNAPSHOT</version>
<name>tura-miner</name>
Expand All @@ -10,12 +10,12 @@
<inceptionYear>2022</inceptionYear>
<url>${project.scm.url}</url>
<scm>
<url>https://gitee.com/nybbs2003/tura-miner</url>
<connection>https://gitee.com/nybbs2003/tura-miner.git</connection>
<url>https://github.com/TuraBlockchain/peth-multi-miners</url>
<connection>https://github.com/TuraBlockchain/peth-multi-miners.git</connection>
</scm>
<issueManagement>
<system>GitHub Issues</system>
<url>https://gitee.com/nybbs2003/tura-miner/issues</url>
<url>https://github.com/TuraBlockchain/peth-multi-miners/issues</url>
</issueManagement>
<licenses>
<license>
Expand Down Expand Up @@ -364,9 +364,9 @@
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>3.2.5</version>
<groupId>hk.zdl.crypto</groupId>
<artifactId>tura-binary</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.jfinal.core.Controller;
import com.jfinal.core.Path;

import hk.zdl.crypto.pearlet.plot.PlotProgressListener;
import hk.zdl.crypto.pearlet.plot.PlotUtil;
import hk.zdl.crypto.tura.miner.MinerProcessManager;
import hk.zdl.crypto.tura.miner.util.PlotProgressListener;
import hk.zdl.crypto.tura.miner.util.Util;

@Path(value = "/api/v1/plot")
public class PlotController extends Controller {
Expand Down Expand Up @@ -70,7 +70,7 @@ public void add() throws Exception {
}
var prog = new PlotProgress(id, path);
prog.restart = jobj.optBoolean("restart");
var entry = new Entry(() -> Util.plot(plotter_bin.toPath(), Paths.get(path), false, id, sn, nounces, prog), prog);
var entry = new Entry(() -> PlotUtil.plot(plotter_bin.toPath(), Paths.get(path), false, id, sn, nounces, prog), prog);
queue.offer(entry);
plot_progress.add(prog);
renderText("plot plan added!");
Expand Down
151 changes: 0 additions & 151 deletions src/main/java/hk/zdl/crypto/tura/miner/util/LocalMiner.java

This file was deleted.

This file was deleted.

91 changes: 0 additions & 91 deletions src/main/java/hk/zdl/crypto/tura/miner/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import java.net.URL;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Base64;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -179,93 +175,6 @@ public static final Callable<String> pingServer(String url) {
};
}

public static final Process plot(Path plot_bin, Path target, boolean benchmark, BigInteger id, long start_nonce, long nonces, PlotProgressListener listener)
throws IOException, InterruptedException {
if (!Files.exists(plot_bin.toAbsolutePath())) {
plot_bin = findPath(plot_bin);
}
if (!plot_bin.toFile().exists()) {
throw new FileNotFoundException(plot_bin.toString());
} else if (!plot_bin.toFile().isFile()) {
throw new FileNotFoundException("not a file: " + plot_bin.toString());
} else if (!plot_bin.toFile().canRead()) {
throw new IOException("cannot read: " + plot_bin.toString());
} else if (!plot_bin.toFile().canExecute()) {
throw new IOException("not executable: " + plot_bin.toString());
}
if (!target.toFile().exists()) {
throw new FileNotFoundException(target.toString());
} else if (!target.toFile().isDirectory()) {
throw new IOException("not dir: " + target.toString());
}
var l = new LinkedList<String>();
if (SystemInfo.isAARCH64) {
var proc = new ProcessBuilder("docker", "run", "--privileged", "--rm", "tonistiigi/binfmt", "--install", "linux/amd64").start();
int i = proc.waitFor();
if (i != 0) {
var err_info = IOUtils.readLines(proc.getErrorStream(), Charset.defaultCharset()).stream().reduce("", (a, b) -> a + "\n" + b).trim();
throw new IOException(err_info);
}
l.addAll(Arrays.asList("docker", "run", "--platform", "linux/amd64", "--mount", "type=bind,source=" + plot_bin.toAbsolutePath().toString() + ",target=/app/signum-plotter", "--mount",
"type=bind,source=" + target.toAbsolutePath().toString() + ",target=" + target.toAbsolutePath().toString(), "ubuntu", "/app/signum-plotter"));
} else {
l.add(plot_bin.toAbsolutePath().toString());
}
if (benchmark) {
l.add("-b");
}
l.addAll(Arrays.asList("--id", id.toString(), "--sn", Long.toString(start_nonce), "--n", Long.toString(nonces), "-m", "2GiB", "-p", target.toAbsolutePath().toString()));
var proc = new ProcessBuilder(l).start();
var reader = proc.inputReader(Charset.defaultCharset());
String line = null;
while (true) {
line = reader.readLine();
if (line == null) {
break;
} else {
line = line.trim();
}
if (line.isEmpty() || line.equals("[2A")) {
continue;
} else if (line.startsWith("Error: ")) {
reader.close();
throw new IOException(line.substring("Error: ".length()));
} else if (line.equals("Starting plotting...")) {
continue;
} else {
if (line.isEmpty() || line.equals("[2A")) {
continue;
} else {
if (line.contains("鈹傗")) {
byte[] bArr = line.getBytes("GBK");
line = new String(bArr, "UTF-8");
line = line.replace("�?", "│");
}
}
if (line.startsWith("Hashing:") || line.startsWith("Writing:")) {
var type = line.startsWith("H") ? PlotProgressListener.Type.HASH : PlotProgressListener.Type.WRIT;
line = line.substring(line.lastIndexOf('│') + 1);
float progress = Float.parseFloat(line.substring(0, line.indexOf('%')).trim());
line = line.substring(line.indexOf('%') + 1).trim();
String rate, eta = "";
if (line.endsWith("B/s")) {
rate = line;
} else {
rate = line.substring(0, line.lastIndexOf(" ")).trim().replace(" ", "");
eta = line.substring(line.lastIndexOf(" ")).trim();
}
listener.onProgress(type, progress, rate, eta);
}
}

}
return proc;
}

private static final Path findPath(Path p) throws IOException {
return IOUtils.readLines(new ProcessBuilder().command("which", p.toString()).start().getInputStream(), "UTF-8").stream().map(Paths::get).findFirst().get();
}

public static final Preferences getUserSettings() {
return Preferences.userNodeForPackage(Util.class);
}
Expand Down
Binary file not shown.
Binary file removed src/main/resources/miner/signum-miner-aarch64-linux
Binary file not shown.
Binary file not shown.
Binary file removed src/main/resources/miner/signum-miner-x86_64-linux
Binary file not shown.
Binary file removed src/main/resources/miner/signum-miner.exe
Binary file not shown.
Binary file removed src/main/resources/plotter/signum-plotter
Binary file not shown.
Binary file not shown.
Binary file removed src/main/resources/plotter/signum-plotter.exe
Binary file not shown.

0 comments on commit 38330ae

Please sign in to comment.