Skip to content

Commit 8d88fef

Browse files
authored
Merge pull request #5 from stotiks/path-to-redemption
Path to redemption
2 parents 8aab570 + e635138 commit 8d88fef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2558
-34898
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "lib/bls-signatures"]
22
path = lib/bls-signatures
33
url = https://github.com/Chia-Network/bls-signatures.git
4+
[submodule "lib/BLAKE3"]
5+
path = lib/BLAKE3
6+
url = https://github.com/BLAKE3-team/BLAKE3.git

CMakeLists.txt

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,56 @@ else()
1212
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
1313
endif()
1414

15+
set(BLAKE3_PATH lib/BLAKE3/c)
16+
set(FSE_PATH lib/FSE/lib)
17+
1518
include_directories(
1619
lib
1720
include
18-
lib/bls-signatures/src/
21+
lib/bls-signatures/src
22+
${BLAKE3_PATH}
23+
${CMAKE_BINARY_DIR}/_deps/relic-src/include
24+
${CMAKE_BINARY_DIR}/_deps/relic-build/include
1925
)
2026

2127
IF (WIN32)
2228
set(BLAKE3_SRC
23-
lib/b3/blake3.c
24-
lib/b3/blake3_portable.c
25-
lib/b3/blake3_dispatch.c
26-
lib/b3/blake3_avx2.c
27-
lib/b3/blake3_avx512.c
28-
lib/b3/blake3_sse41.c
29+
${BLAKE3_PATH}/blake3.c
30+
${BLAKE3_PATH}/blake3_portable.c
31+
${BLAKE3_PATH}/blake3_dispatch.c
32+
${BLAKE3_PATH}/blake3_avx2.c
33+
${BLAKE3_PATH}/blake3_avx512.c
34+
${BLAKE3_PATH}/blake3_sse2.c
35+
${BLAKE3_PATH}/blake3_sse41.c
2936
)
3037
ELSEIF(OSX_NATIVE_ARCHITECTURE STREQUAL "arm64")
3138
set(BLAKE3_SRC
32-
lib/b3/blake3.c
33-
lib/b3/blake3_portable.c
34-
lib/b3/blake3_dispatch.c
39+
${BLAKE3_PATH}/blake3.c
40+
${BLAKE3_PATH}/blake3_portable.c
41+
${BLAKE3_PATH}/blake3_dispatch.c
3542
)
3643
ELSE()
3744
set(BLAKE3_SRC
38-
lib/b3/blake3.c
39-
lib/b3/blake3_portable.c
40-
lib/b3/blake3_dispatch.c
41-
lib/b3/blake3_avx2_x86-64_unix.S
42-
lib/b3/blake3_avx512_x86-64_unix.S
43-
lib/b3/blake3_sse41_x86-64_unix.S
45+
${BLAKE3_PATH}/blake3.c
46+
${BLAKE3_PATH}/blake3_portable.c
47+
${BLAKE3_PATH}/blake3_dispatch.c
48+
${BLAKE3_PATH}/blake3_avx2_x86-64_unix.S
49+
${BLAKE3_PATH}/blake3_avx512_x86-64_unix.S
50+
${BLAKE3_PATH}/blake3_sse41_x86-64_unix.S
51+
${BLAKE3_PATH}/blake3_sse2_x86-64_unix.S
4452
)
4553
ENDIF()
4654

47-
set(FSE_LIB lib/FSE/lib)
48-
set(FSE_FILES
49-
${FSE_LIB}/fse_compress.c
50-
${FSE_LIB}/fse_decompress.c
51-
${FSE_LIB}/entropy_common.c
52-
${FSE_LIB}/hist.c
55+
set(FSE_SRC
56+
${FSE_PATH}/fse_compress.c
57+
${FSE_PATH}/fse_decompress.c
58+
${FSE_PATH}/entropy_common.c
59+
${FSE_PATH}/hist.c
5360
)
5461

5562
add_library(blake3 STATIC ${BLAKE3_SRC})
5663

57-
add_library(fse STATIC ${FSE_FILES})
64+
add_library(fse STATIC ${FSE_SRC})
5865

5966
add_library(chia_plotter STATIC
6067
lib/chacha8.c
@@ -66,6 +73,7 @@ else()
6673
target_link_libraries(chia_plotter blake3 fse Threads::Threads)
6774
endif()
6875

76+
add_executable(test_copy test/test_copy.cpp)
6977
add_executable(test_disk_sort test/test_disk_sort.cpp)
7078

7179
add_executable(test_phase_1 test/test_phase_1.cpp)
@@ -82,6 +90,7 @@ if (MSVC)
8290
add_library(uint128 STATIC uint128_t/uint128_t.cpp)
8391
target_include_directories(uint128 PUBLIC uint128_t)
8492

93+
target_link_libraries(test_copy chia_plotter)
8594
target_link_libraries(test_disk_sort chia_plotter uint128)
8695
target_link_libraries(test_phase_1 chia_plotter uint128)
8796
target_link_libraries(test_phase_2 chia_plotter uint128)
@@ -94,15 +103,16 @@ if (MSVC)
94103

95104
else()
96105

97-
target_link_libraries(test_disk_sort chia_plotter)
98-
99-
target_link_libraries(test_phase_1 chia_plotter)
100-
target_link_libraries(test_phase_2 chia_plotter)
101-
target_link_libraries(test_phase_3 chia_plotter)
102-
target_link_libraries(test_phase_4 chia_plotter)
103-
104-
target_link_libraries(check_phase_1 chia_plotter)
105-
106-
target_link_libraries(chia_plot chia_plotter bls)
106+
target_link_libraries(test_copy chia_plotter)
107+
target_link_libraries(test_disk_sort chia_plotter)
108+
109+
target_link_libraries(test_phase_1 chia_plotter)
110+
target_link_libraries(test_phase_2 chia_plotter)
111+
target_link_libraries(test_phase_3 chia_plotter)
112+
target_link_libraries(test_phase_4 chia_plotter)
113+
114+
target_link_libraries(check_phase_1 chia_plotter)
115+
116+
target_link_libraries(chia_plot chia_plotter bls)
107117

108118
endif()

README.md

Lines changed: 70 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,29 @@ simply by increasing the number of "cores", ie. threads.
99
## Usage
1010

1111
```
12-
chia_plot <pool_key> <farmer_key> [tmp_dir] [tmp_dir2] [num_threads] [log_num_buckets]
13-
14-
For <pool_key> and <farmer_key> see output of `chia keys show`.
15-
<tmp_dir> needs about 200G space, it will handle about 25% of all writes. (Examples: './', '/mnt/tmp/')
16-
<tmp_dir2> needs about 110G space and ideally is a RAM drive, it will handle about 75% of all writes.
17-
If <tmp_dir> is not specified it defaults to current directory.
18-
If <tmp_dir2> is not specified it defaults to <tmp_dir>.
19-
[num_threads] defaults to 4, it's recommended to use number of physical cores.
20-
[log_num_buckets] defaults to 7 (2^7 = 128)
12+
For <poolkey> and <farmerkey> see output of `chia keys show`.
13+
<tmpdir> needs about 220 GiB space, it will handle about 25% of all writes. (Examples: './', '/mnt/tmp/')
14+
<tmpdir2> needs about 110 GiB space and ideally is a RAM drive, it will handle about 75% of all writes.
15+
16+
Usage:
17+
chia_plot [OPTION...]
18+
19+
-n, --count arg Number of plots to create (default = 1, -1 = infinite)
20+
-r, --threads arg Number of threads (default = 4)
21+
-u, --buckets arg Number of buckets (default = 128)
22+
-t, --tmpdir arg Temporary directory, needs ~220 GiB (default = $PWD)
23+
-2, --tmpdir2 arg Temporary directory 2, needs ~110 GiB [RAM] (default = <tmpdir>)
24+
-d, --finaldir arg Final directory (default = <tmpdir>)
25+
-p, --poolkey arg Pool Public Key (48 bytes)
26+
-f, --farmerkey arg Farmer Public Key (48 bytes)
27+
--help Print help
2128
```
2229

23-
Make sure to crank up `<num_threads>` if you have plenty of cores, the default is 4.
30+
Make sure to crank up `<threads>` if you have plenty of cores, the default is 4.
2431
Depending on the phase more threads will be launched, the setting is just a multiplier.
2532

26-
RAM usage depends on `<num_threads>` and `<log_num_buckets>`.
27-
With default `<log_num_buckets>` and 4 threads it's ~2GB total, with 16 threads it's ~6GB total.
33+
RAM usage depends on `<threads>` and `<buckets>`.
34+
With default `<buckets>` and 4 threads it's ~2GB total, with 16 threads it's ~6GB total.
2835

2936
## How to Support
3037

@@ -34,67 +41,69 @@ I developed this on my own time, even though I already filled all my HDDs (~50 T
3441

3542
## Results
3643

37-
On a dual Xeon(R) [email protected] R720 with 256GB RAM and a 3x800GB SATA SSD RAID0, using a 110G tmpfs for `<tmp_dir2>`:
44+
On a dual Xeon(R) [email protected] R720 with 256GB RAM and a 3x800GB SATA SSD RAID0, using a 110G tmpfs for `<tmpdir2>`:
3845

3946
```
4047
Number of Threads: 16
4148
Number of Sort Buckets: 2^7 (128)
42-
Working Directory: ./
43-
Working Directory 2: ./ram/
44-
[P1] Table 1 took 21.0467 sec
45-
[P1] Table 2 took 152.6 sec, found 4295044959 matches
46-
[P1] Lost 77279 matches due to 32-bit overflow.
47-
[P1] Table 3 took 181.169 sec, found 4295030463 matches
48-
[P1] Lost 62514 matches due to 32-bit overflow.
49-
[P1] Table 4 took 223.303 sec, found 4295044715 matches
50-
[P1] Lost 76928 matches due to 32-bit overflow.
51-
[P1] Table 5 took 232.129 sec, found 4294967739 matches
52-
[P1] Lost 235 matches due to 32-bit overflow.
53-
[P1] Table 6 took 221.468 sec, found 4294932892 matches
54-
[P1] Table 7 took 182.597 sec, found 4294838936 matches
55-
Phase 1 took 1214.37 sec
56-
[P2] max_table_size = 4295044959
57-
[P2] Table 7 scan took 16.9198 sec
58-
[P2] Table 7 rewrite took 44.796 sec, dropped 0 entries (0 %)
59-
[P2] Table 6 scan took 47.5287 sec
60-
[P2] Table 6 rewrite took 81.2195 sec, dropped 581301544 entries (13.5346 %)
61-
[P2] Table 5 scan took 46.6094 sec
62-
[P2] Table 5 rewrite took 77.9914 sec, dropped 761979000 entries (17.7412 %)
63-
[P2] Table 4 scan took 52.427 sec
64-
[P2] Table 4 rewrite took 75.7487 sec, dropped 828872625 entries (19.2983 %)
65-
[P2] Table 3 scan took 54.0839 sec
66-
[P2] Table 3 rewrite took 74.9016 sec, dropped 855088153 entries (19.9088 %)
67-
[P2] Table 2 scan took 49.692 sec
68-
[P2] Table 2 rewrite took 73.0273 sec, dropped 865610902 entries (20.1537 %)
69-
Phase 2 took 721.638 sec
49+
Working Directory: /mnt/tmp3/chia/tmp/
50+
Working Directory 2: /mnt/tmp3/chia/tmp/ram/
51+
[P1] Table 1 took 18.2322 sec
52+
[P1] Table 2 took 152.806 sec, found 4294955136 matches
53+
[P1] Table 3 took 181.893 sec, found 4295004058 matches
54+
[P1] Lost 36189 matches due to 32-bit overflow.
55+
[P1] Table 4 took 207.631 sec, found 4295076024 matches
56+
[P1] Lost 108422 matches due to 32-bit overflow.
57+
[P1] Table 5 took 210.324 sec, found 4295073698 matches
58+
[P1] Lost 106662 matches due to 32-bit overflow.
59+
[P1] Table 6 took 205.312 sec, found 4294986463 matches
60+
[P1] Lost 19157 matches due to 32-bit overflow.
61+
[P1] Table 7 took 166.982 sec, found 4294910985 matches
62+
Phase 1 took 1143.2 sec
63+
[P2] max_table_size = 4295076024
64+
[P2] Table 7 scan took 16.6775 sec
65+
[P2] Table 7 rewrite took 40.4863 sec, dropped 0 entries (0 %)
66+
[P2] Table 6 scan took 47.6553 sec
67+
[P2] Table 6 rewrite took 66.2653 sec, dropped 581270438 entries (13.5337 %)
68+
[P2] Table 5 scan took 45.4674 sec
69+
[P2] Table 5 rewrite took 67.3295 sec, dropped 762045018 entries (17.7423 %)
70+
[P2] Table 4 scan took 44.4048 sec
71+
[P2] Table 4 rewrite took 62.1307 sec, dropped 828943971 entries (19.2999 %)
72+
[P2] Table 3 scan took 45.1361 sec
73+
[P2] Table 3 rewrite took 61.2604 sec, dropped 855078559 entries (19.9087 %)
74+
[P2] Table 2 scan took 46.5209 sec
75+
[P2] Table 2 rewrite took 61.3043 sec, dropped 865523252 entries (20.1521 %)
76+
Phase 2 took 635.101 sec
7077
Wrote plot header with 268 bytes
71-
[P3-1] Table 2 took 76.0894 sec, wrote 3429434057 right entries
72-
[P3-2] Table 2 took 75.1076 sec, wrote 3429434057 left entries, 3429434057 final
73-
[P3-1] Table 3 took 78.0162 sec, wrote 3439942310 right entries
74-
[P3-2] Table 3 took 73.0284 sec, wrote 3439942310 left entries, 3439942310 final
75-
[P3-1] Table 4 took 133.769 sec, wrote 3466172090 right entries
76-
[P3-2] Table 4 took 76.1504 sec, wrote 3466172090 left entries, 3466172090 final
77-
[P3-1] Table 5 took 127.125 sec, wrote 3532988739 right entries
78-
[P3-2] Table 5 took 77.7182 sec, wrote 3532988739 left entries, 3532988739 final
79-
[P3-1] Table 6 took 134.779 sec, wrote 3713631348 right entries
80-
[P3-2] Table 6 took 81.9068 sec, wrote 3713631348 left entries, 3713631348 final
81-
[P3-1] Table 7 took 69.066 sec, wrote 4294838936 right entries
82-
[P3-2] Table 7 took 94.0157 sec, wrote 4294838936 left entries, 4294838936 final
83-
Phase 3 took 1104.11 sec, wrote 21877007480 entries to final plot
78+
[P3-1] Table 2 took 80.6498 sec, wrote 3429431884 right entries
79+
[P3-2] Table 2 took 74.787 sec, wrote 3429431884 left entries, 3429431884 final
80+
[P3-1] Table 3 took 70.8236 sec, wrote 3439925499 right entries
81+
[P3-2] Table 3 took 77.8787 sec, wrote 3439925499 left entries, 3439925499 final
82+
[P3-1] Table 4 took 71.894 sec, wrote 3466132053 right entries
83+
[P3-2] Table 4 took 76.3172 sec, wrote 3466132053 left entries, 3466132053 final
84+
[P3-1] Table 5 took 72.6806 sec, wrote 3533028680 right entries
85+
[P3-2] Table 5 took 81.5741 sec, wrote 3533028680 left entries, 3533028680 final
86+
[P3-1] Table 6 took 77.1653 sec, wrote 3713716025 right entries
87+
[P3-2] Table 6 took 85.9674 sec, wrote 3713716025 left entries, 3713716025 final
88+
[P3-1] Table 7 took 75.5146 sec, wrote 4294910985 right entries
89+
[P3-2] Table 7 took 93.9135 sec, wrote 4294910985 left entries, 4294910985 final
90+
Phase 3 took 946.026 sec, wrote 21877145126 entries to final plot
8491
[P4] Starting to write C1 and C3 tables
8592
[P4] Finished writing C1 and C3 tables
8693
[P4] Writing C2 table
8794
[P4] Finished writing C2 table
88-
Phase 4 took 89.0748 sec, final plot size is 108834390977 bytes
89-
Total plot creation time was 3129.28 sec
95+
Phase 4 took 79.6722 sec, final plot size is 108835267927 bytes
96+
Total plot creation time was 2804.06 sec
9097
```
9198

9299
## How to Verify
93100

94101
To make sure the plots are valid you can use the `ProofOfSpace` tool from `chiapos`:
95102

96103
```
97-
ProofOfSpace check -f plot-k32-???.plot [num_iterations]
104+
git clone https://github.com/Chia-Network/chiapos.git
105+
cd chiapos && mkdir build && cd build && cmake .. && make -j8
106+
./ProofOfSpace check -f plot-k32-???.plot [num_iterations]
98107
```
99108

100109
## Future Plans
@@ -113,7 +122,11 @@ keeping most of the load off the CPUs.
113122

114123
## Install
115124

125+
Ubuntu 20.04
116126
```
127+
sudo apt install -y libsodium-dev libgmp3-dev cmake g++ git
128+
git clone https://github.com/madMAx43v3r/chia-plotter.git
129+
cd chia-plotter
117130
git submodule update --init
118131
./make_devel.sh
119132
```

include/chia/ThreadPool.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,16 @@ class ThreadPool : public Processor<T> {
101101
private:
102102
void wrapper(thread_t* state, thread_t* prev, T& input)
103103
{
104+
uint64_t job = -1;
105+
{
106+
std::lock_guard<std::mutex> lock(state->mutex);
107+
job = state->job;
108+
}
104109
S out;
105110
execute(input, out, state->local);
106111
{
107112
std::unique_lock<std::mutex> lock(prev->mutex);
108-
while(prev->job < state->job) {
113+
while(prev->job < job) {
109114
prev->signal.wait(lock);
110115
}
111116
}

include/chia/copy.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* copy.h
3+
*
4+
* Created on: Jun 8, 2021
5+
* Author: mad
6+
*/
7+
8+
#ifndef INCLUDE_CHIA_COPY_H_
9+
#define INCLUDE_CHIA_COPY_H_
10+
11+
#include <chia/stdiox.hpp>
12+
#include <chia/settings.h>
13+
14+
#include <string>
15+
#include <vector>
16+
#include <stdexcept>
17+
18+
#include <cstdio>
19+
#include <cstdint>
20+
21+
22+
inline
23+
uint64_t copy_file(const std::string& src_path, const std::string& dst_path)
24+
{
25+
FILE* src = FOPEN(src_path.c_str(), "rb");
26+
if(!src) {
27+
throw std::runtime_error("fopen() failed");
28+
}
29+
FILE* dst = FOPEN(dst_path.c_str(), "wb");
30+
if(!dst) {
31+
throw std::runtime_error("fopen() failed");
32+
}
33+
uint64_t total_bytes = 0;
34+
std::vector<uint8_t> buffer(g_read_chunk_size);
35+
while(true) {
36+
const auto num_bytes = fread(buffer.data(), 1, buffer.size(), src);
37+
if(fwrite(buffer.data(), 1, num_bytes, dst) != num_bytes) {
38+
throw std::runtime_error("fwrite() failed");
39+
}
40+
total_bytes += num_bytes;
41+
if(num_bytes < buffer.size()) {
42+
break;
43+
}
44+
}
45+
if(fclose(dst)) {
46+
throw std::runtime_error("fclose() failed");
47+
}
48+
fclose(src);
49+
return total_bytes;
50+
}
51+
52+
inline
53+
uint64_t final_copy(const std::string& src_path, const std::string& dst_path)
54+
{
55+
if(src_path == dst_path) {
56+
return 0;
57+
}
58+
const std::string tmp_dst_path = dst_path + ".tmp";
59+
uint64_t total_bytes = 0;
60+
if(rename(src_path.c_str(), tmp_dst_path.c_str())) {
61+
// try manual copy
62+
total_bytes = copy_file(src_path, tmp_dst_path);
63+
}
64+
remove(src_path.c_str());
65+
rename(tmp_dst_path.c_str(), dst_path.c_str());
66+
return total_bytes;
67+
}
68+
69+
70+
#endif /* INCLUDE_CHIA_COPY_H_ */

include/chia/phase1.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace phase1 {
2525
struct input_t {
2626
std::array<uint8_t, 32> id = {};
2727
std::vector<uint8_t> memo;
28+
std::string plot_name;
2829
};
2930

3031
struct entry_1 {

0 commit comments

Comments
 (0)