Skip to content

Commit 281be67

Browse files
mariano54wjblanke
authored andcommitted
Alpha 1.2 (#64)
Remove database access from blockchain, and handle headers instead of blocks Avoid processing blocks and unfinished blocks that we have already seen. Also adds test for load. Plotting improvements
1 parent d9bf22c commit 281be67

File tree

12 files changed

+355
-310
lines changed

12 files changed

+355
-310
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# chia-blockchain
2-
Python 3.7 is used for this project. Make sure your default python version is >=3.7 by typing python3.
2+
Python 3.7 is used for this project. Make sure your default python version is >=3.7 by typing python3.
33

44
You will need to enable [UPnP](https://www.homenethowto.com/ports-and-nat/upnp-automatic-port-forward/) on your router or add a NAT (for IPv4 but not IPv6) and firewall rule to allow TCP port 8444 access to your peer. These methods tend to be router make/model specific.
55

@@ -82,12 +82,12 @@ mongod --fork --dbpath ./db/ --logpath mongod.log
8282
```
8383

8484
### Windows (WSL + Ubuntu)
85-
#### Install WSL + Ubuntu 18.04 LTS, upgrade to Ubuntu 19.x
85+
#### Install WSL + Ubuntu 18.04 LTS, upgrade to Ubuntu 19.x
8686

8787
This will require multiple reboots. From an Administrator PowerShell
88-
`Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux`
89-
and then
90-
`Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform`.
88+
`Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux`
89+
and then
90+
`Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform`.
9191
Once that is complete, install Ubuntu 18.04 LTS from the Windows Store.
9292
```bash
9393
# Upgrade to 19.x
@@ -260,7 +260,7 @@ Due to the nature of proof of space lookups by the harvester you should limit th
260260
on a physical drive to 50 or less. This limit should significantly increase before beta.
261261

262262
You can also run the simulation, which runs all servers and multiple full nodes, locally, at once.
263-
If you want to run the simulation, change the introducer ip in ./config/config.yaml so that the
263+
If you want to run the simulation, change the introducer ip in ./config/config.yaml so that the
264264
full node points to the local introducer (127.0.0.1:8445).
265265

266266
Note the the simulation is local only and requires installation of timelords and VDFs.

lib/chiapos/src/calculate_bucket.hpp

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <map>
2424
#include <algorithm>
2525
#include <utility>
26+
#include <array>
2627

2728
#include "util.hpp"
2829
#include "bits.hpp"
@@ -60,20 +61,22 @@ std::map<uint8_t, uint8_t> kVectorLens = {
6061
{8, 0}
6162
};
6263

63-
// Precomputed shifts that specify which entries match with which other entries
64-
// in adjacent buckets.
65-
uint16_t matching_shifts_c[2][kC];
66-
67-
// Performs the precomputation of shifts.
68-
void precompute_shifts() {
64+
uint32_t L_targets[2][kBC][kExtraBitsPow];
65+
bool initialized = false;
66+
void load_tables()
67+
{
6968
for (uint8_t parity = 0; parity < 2; parity++) {
70-
for (uint16_t r = 0; r < kExtraBitsPow; r++) {
71-
uint16_t v = (uint16_t)pow((2 * r + parity), 2) % kC;
72-
matching_shifts_c[parity][r] = v;
69+
for (uint16_t i = 0; i < kBC; i++) {
70+
uint16_t indJ = i / kC;
71+
for (uint16_t m = 0; m < kExtraBitsPow; m++) {
72+
uint16_t yr = ((indJ + m) % kB) * kC + (((2*m + parity) * (2*m + parity) + i) % kC);
73+
L_targets[parity][i][m] = yr;
74+
}
7375
}
7476
}
7577
}
7678

79+
7780
// Class to evaluate F1
7881
class F1Calculator {
7982
public:
@@ -87,9 +90,6 @@ class F1Calculator {
8790

8891
// Loads the key into the global AES context
8992
aes_load_key(this->aes_key_, 32);
90-
91-
// Precomputes the shifts, this is only done once
92-
precompute_shifts();
9393
}
9494

9595
inline ~F1Calculator() {
@@ -243,15 +243,13 @@ class FxCalculator {
243243
// for these f functions (as opposed to f1, which uses a 32 byte key). Note that, however,
244244
// block sizes are still 128 bits (32 bytes).
245245
aes_load_key(this->aes_key_, 16);
246-
247-
// One time precomputation of the shifts
248-
precompute_shifts();
249-
250-
// Preallocates vector to be used for matching
251-
for (uint16_t i = 0; i < kC; i++) {
246+
for (uint16_t i = 0; i < kBC; i++) {
252247
std::vector<uint16_t> new_vec;
253-
this->R_positions.push_back(new_vec);
254-
this->R_bids.push_back(new_vec);
248+
this->rmap.push_back(new_vec);
249+
}
250+
if(!initialized) {
251+
initialized = true;
252+
load_tables();
255253
}
256254
}
257255

@@ -352,43 +350,32 @@ class FxCalculator {
352350
inline std::vector<std::pair<uint16_t, uint16_t>> FindMatches(const std::vector<PlotEntry>& bucket_L,
353351
const std::vector<PlotEntry>& bucket_R) {
354352
std::vector<std::pair<uint16_t, uint16_t>> matches;
355-
for (uint16_t i = 0; i < kC; i++) {
356-
this->R_bids[i].clear();
357-
this->R_positions[i].clear();
358-
}
359353
uint16_t parity = (bucket_L[0].y / kBC) % 2;
360354

355+
for (uint16_t i = 0; i < rmap_clean.size(); i++) {
356+
uint16_t yl = rmap_clean[i];
357+
this->rmap[yl].clear();
358+
}
359+
rmap_clean.clear();
360+
361+
uint64_t remove = (bucket_R[0].y / kBC) * kBC;
361362
for (uint16_t pos_R = 0; pos_R < bucket_R.size(); pos_R++) {
362-
R_bids[bucket_R[pos_R].y % kC].push_back((bucket_R[pos_R].y % kBC) / kC);
363-
R_positions[bucket_R[pos_R].y % kC].push_back(pos_R);
363+
uint64_t r_y = bucket_R[pos_R].y - remove;
364+
rmap[r_y].push_back(pos_R);
365+
rmap_clean.push_back(r_y);
364366
}
365367

368+
uint64_t remove_y = remove - kBC;
366369
for (uint16_t pos_L = 0; pos_L < bucket_L.size(); pos_L++) {
367-
uint16_t yl_bid = (bucket_L[pos_L].y % kBC) / kC;
368-
uint16_t yl_cid = bucket_L[pos_L].y % kC;
369-
for (uint8_t m = 0; m < kExtraBitsPow; m++) {
370-
uint16_t target_bid = (yl_bid + m);
371-
uint16_t target_cid = yl_cid + matching_shifts_c[parity][m];
372-
373-
// This is faster than %
374-
if (target_bid >= kB) {
375-
target_bid -= kB;
376-
}
377-
if (target_cid >= kC) {
378-
target_cid -= kC;
379-
}
380-
381-
for (uint32_t i = 0; i < R_bids[target_cid].size(); i++) {
382-
uint16_t R_bid = R_bids[target_cid][i];
383-
if (target_bid == R_bid) {
384-
uint64_t yl_bucket = bucket_L[pos_L].y / kBC;
385-
if (yl_bucket + 1 == bucket_R[R_positions[target_cid][i]].y / kBC) {
386-
matches.push_back(std::make_pair(pos_L, R_positions[target_cid][i]));
387-
}
388-
}
370+
uint64_t r = bucket_L[pos_L].y - remove_y;
371+
for (uint8_t i = 0; i < kExtraBitsPow; i++) {
372+
uint16_t r_target = L_targets[parity][r][i];
373+
for (uint8_t j = 0; j < rmap[r_target].size(); j++) {
374+
matches.push_back(std::make_pair(pos_L, rmap[r_target][j]));
389375
}
390376
}
391377
}
378+
392379
return matches;
393380
}
394381

@@ -402,8 +389,8 @@ class FxCalculator {
402389
uint8_t block_3[kBlockSizeBits/8];
403390
uint8_t block_4[kBlockSizeBits/8];
404391
uint8_t ciphertext[kBlockSizeBits/8];
405-
std::vector<std::vector<uint16_t> > R_positions;
406-
std::vector<std::vector<uint16_t> > R_bids;
392+
std::vector<std::vector<uint16_t>> rmap;
393+
std::vector<uint16_t> rmap_clean;
407394
};
408395

409396
#endif // SRC_CPP_CALCULATE_BUCKET_HPP_

lib/chiapos/src/verifier.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ class Verifier {
7979
vector<PlotEntry> bucket_R = {r_plot_entry};
8080

8181
// If there is no match, fails.
82-
if (f.FindMatches(bucket_L, bucket_R).size() != 1) {
82+
uint64_t cdiff = r_plot_entry.y / kBC - l_plot_entry.y / kBC;
83+
if (cdiff != 1) {
84+
return LargeBits();
85+
} else if (f.FindMatches(bucket_L, bucket_R).size() != 1) {
8386
return LargeBits();
8487
}
88+
8589
std::pair<Bits, Bits> results = f.CalculateBucket(ys[i], ys[i+1],
8690
metadata[i], metadata[i+1]);
8791
new_ys.push_back(std::get<0>(results));

0 commit comments

Comments
 (0)