Skip to content

Commit

Permalink
Tmp2wjb (Chia-Network#24)
Browse files Browse the repository at this point in the history
* specify location of secondary tmp folder
  • Loading branch information
wjblanke authored May 6, 2020
1 parent 46f6680 commit e0795c3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions python-bindings/chiapos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ PYBIND11_MODULE(chiapos, m) {

py::class_<DiskPlotter>(m, "DiskPlotter")
.def(py::init<>())
.def("create_plot_disk", [](DiskPlotter &dp, const std::string tmp_dir, const std::string final_dir,
.def("create_plot_disk", [](DiskPlotter &dp, const std::string tmp_dir,
const std::string tmp2_dir,
const std::string final_dir,
const std::string filename, uint8_t k,
const py::bytes &memo, const py::bytes &id) {
std::string memo_str(memo);
const uint8_t* memo_ptr = reinterpret_cast<const uint8_t*>(memo_str.data());
std::string id_str(id);
const uint8_t* id_ptr = reinterpret_cast<const uint8_t*>(id_str.data());
dp.CreatePlotDisk(tmp_dir, final_dir, filename, k, memo_ptr, len(memo), id_ptr, len(id));
dp.CreatePlotDisk(tmp_dir, tmp2_dir, final_dir, filename, k, memo_ptr, len(memo), id_ptr, len(id));
});

py::class_<DiskProver>(m, "DiskProver")
Expand Down
2 changes: 1 addition & 1 deletion src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) {
HexToBytes(id, id_bytes);

DiskPlotter plotter = DiskPlotter();
plotter.CreatePlotDisk(tempdir, finaldir, filename, k, memo_bytes, memo.size() / 2, id_bytes, 32);
plotter.CreatePlotDisk(tempdir, tempdir, finaldir, filename, k, memo_bytes, memo.size() / 2, id_bytes, 32);
} else if (operation == "prove") {
if (argc < 3) {
HelpAndQuit(options);
Expand Down
12 changes: 9 additions & 3 deletions src/plotter_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DiskPlotter {
// This method creates a plot on disk with the filename. A temporary file, "plotting" + filename,
// is created and will be larger than the final plot file. This file is deleted at the end of
// the process.
void CreatePlotDisk(std::string tmp_dirname, std::string final_dirname, std::string filename,
void CreatePlotDisk(std::string tmp_dirname, std::string tmp2_dirname, std::string final_dirname, std::string filename,
uint8_t k, const uint8_t* memo,
uint32_t memo_len, const uint8_t* id, uint32_t id_len) {
if (k < kMinPlotSize || k > kMaxPlotSize) {
Expand All @@ -87,14 +87,14 @@ class DiskPlotter {
throw err_string;
}

std::cout << std::endl << "Starting plotting progress into temporary dir " << tmp_dirname << "." << std::endl;
std::cout << std::endl << "Starting plotting progress into temporary dirs: " << tmp_dirname << " and " << tmp2_dirname << std::endl;
std::cout << "Memo: " << Util::HexStr(memo, memo_len) << std::endl;
std::cout << "ID: " << Util::HexStr(id, id_len) << std::endl;
std::cout << "Plot size is: " << static_cast<int>(k) << std::endl;

// Cross platform way to concatenate paths, gulrak library.
fs::path tmp_1_filename = fs::path(tmp_dirname) / fs::path(filename + ".tmp");
fs::path tmp_2_filename = fs::path(tmp_dirname) / fs::path(filename + ".2.tmp");
fs::path tmp_2_filename = fs::path(tmp2_dirname) / fs::path(filename + ".2.tmp");
fs::path final_filename = fs::path(final_dirname) / fs::path(filename);

// Check if the paths exist
Expand All @@ -104,6 +104,12 @@ class DiskPlotter {
throw err_string;
}

if (!fs::exists(tmp2_dirname)) {
std::string err_string = "Directory " + tmp2_dirname + " does not exist";
std::cerr << err_string << std::endl;
throw err_string;
}

if (!fs::exists(final_dirname)) {
std::string err_string = "Directory " + final_dirname + " does not exist";
std::cerr << err_string << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void PlotAndTestProofOfSpace(std::string filename, uint32_t iterations, uint8_t
uint32_t expected_success) {
DiskPlotter plotter = DiskPlotter();
uint8_t memo[5] = {1, 2, 3, 4, 5};
plotter.CreatePlotDisk(".", ".", filename, k, memo, 5, plot_id, 32);
plotter.CreatePlotDisk(".", ".", ".", filename, k, memo, 5, plot_id, 32);
TestProofOfSpace(filename, iterations, k, plot_id, expected_success);
REQUIRE(remove(filename.c_str()) == 0);
}
Expand All @@ -389,7 +389,7 @@ TEST_CASE("Invalid plot") {
DiskPlotter plotter = DiskPlotter();
uint8_t memo[5] = {1, 2, 3, 4, 5};
uint8_t k = 22;
plotter.CreatePlotDisk(".", ".", filename, k, memo, 5, plot_id_1, 32);
plotter.CreatePlotDisk(".", ".", ".", filename, k, memo, 5, plot_id_1, 32);
DiskProver prover(filename);
uint8_t* proof_data = new uint8_t[8 * k];
uint8_t challenge[32];
Expand Down
2 changes: 1 addition & 1 deletion tests/test_python_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_k_21(self):
10, 11, 129, 139, 171, 15, 23])

pl = DiskPlotter()
pl.create_plot_disk(".", ".", "myplot.dat", 21, bytes([1, 2, 3, 4, 5]), plot_seed)
pl.create_plot_disk(".", ".", ".", "myplot.dat", 21, bytes([1, 2, 3, 4, 5]), plot_seed)
pl = None

pr = DiskProver(str(Path("myplot.dat")))
Expand Down

0 comments on commit e0795c3

Please sign in to comment.