Skip to content

Commit

Permalink
Alpha 1.2 (#64)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mariano54 authored and wjblanke committed Jan 9, 2020
1 parent d9bf22c commit 281be67
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 310 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# chia-blockchain
Python 3.7 is used for this project. Make sure your default python version is >=3.7 by typing python3.
Python 3.7 is used for this project. Make sure your default python version is >=3.7 by typing python3.

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.

Expand Down Expand Up @@ -82,12 +82,12 @@ mongod --fork --dbpath ./db/ --logpath mongod.log
```

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

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

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

Note the the simulation is local only and requires installation of timelords and VDFs.
Expand Down
87 changes: 37 additions & 50 deletions lib/chiapos/src/calculate_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <map>
#include <algorithm>
#include <utility>
#include <array>

#include "util.hpp"
#include "bits.hpp"
Expand Down Expand Up @@ -60,20 +61,22 @@ std::map<uint8_t, uint8_t> kVectorLens = {
{8, 0}
};

// Precomputed shifts that specify which entries match with which other entries
// in adjacent buckets.
uint16_t matching_shifts_c[2][kC];

// Performs the precomputation of shifts.
void precompute_shifts() {
uint32_t L_targets[2][kBC][kExtraBitsPow];
bool initialized = false;
void load_tables()
{
for (uint8_t parity = 0; parity < 2; parity++) {
for (uint16_t r = 0; r < kExtraBitsPow; r++) {
uint16_t v = (uint16_t)pow((2 * r + parity), 2) % kC;
matching_shifts_c[parity][r] = v;
for (uint16_t i = 0; i < kBC; i++) {
uint16_t indJ = i / kC;
for (uint16_t m = 0; m < kExtraBitsPow; m++) {
uint16_t yr = ((indJ + m) % kB) * kC + (((2*m + parity) * (2*m + parity) + i) % kC);
L_targets[parity][i][m] = yr;
}
}
}
}


// Class to evaluate F1
class F1Calculator {
public:
Expand All @@ -87,9 +90,6 @@ class F1Calculator {

// Loads the key into the global AES context
aes_load_key(this->aes_key_, 32);

// Precomputes the shifts, this is only done once
precompute_shifts();
}

inline ~F1Calculator() {
Expand Down Expand Up @@ -243,15 +243,13 @@ class FxCalculator {
// for these f functions (as opposed to f1, which uses a 32 byte key). Note that, however,
// block sizes are still 128 bits (32 bytes).
aes_load_key(this->aes_key_, 16);

// One time precomputation of the shifts
precompute_shifts();

// Preallocates vector to be used for matching
for (uint16_t i = 0; i < kC; i++) {
for (uint16_t i = 0; i < kBC; i++) {
std::vector<uint16_t> new_vec;
this->R_positions.push_back(new_vec);
this->R_bids.push_back(new_vec);
this->rmap.push_back(new_vec);
}
if(!initialized) {
initialized = true;
load_tables();
}
}

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

for (uint16_t i = 0; i < rmap_clean.size(); i++) {
uint16_t yl = rmap_clean[i];
this->rmap[yl].clear();
}
rmap_clean.clear();

uint64_t remove = (bucket_R[0].y / kBC) * kBC;
for (uint16_t pos_R = 0; pos_R < bucket_R.size(); pos_R++) {
R_bids[bucket_R[pos_R].y % kC].push_back((bucket_R[pos_R].y % kBC) / kC);
R_positions[bucket_R[pos_R].y % kC].push_back(pos_R);
uint64_t r_y = bucket_R[pos_R].y - remove;
rmap[r_y].push_back(pos_R);
rmap_clean.push_back(r_y);
}

uint64_t remove_y = remove - kBC;
for (uint16_t pos_L = 0; pos_L < bucket_L.size(); pos_L++) {
uint16_t yl_bid = (bucket_L[pos_L].y % kBC) / kC;
uint16_t yl_cid = bucket_L[pos_L].y % kC;
for (uint8_t m = 0; m < kExtraBitsPow; m++) {
uint16_t target_bid = (yl_bid + m);
uint16_t target_cid = yl_cid + matching_shifts_c[parity][m];

// This is faster than %
if (target_bid >= kB) {
target_bid -= kB;
}
if (target_cid >= kC) {
target_cid -= kC;
}

for (uint32_t i = 0; i < R_bids[target_cid].size(); i++) {
uint16_t R_bid = R_bids[target_cid][i];
if (target_bid == R_bid) {
uint64_t yl_bucket = bucket_L[pos_L].y / kBC;
if (yl_bucket + 1 == bucket_R[R_positions[target_cid][i]].y / kBC) {
matches.push_back(std::make_pair(pos_L, R_positions[target_cid][i]));
}
}
uint64_t r = bucket_L[pos_L].y - remove_y;
for (uint8_t i = 0; i < kExtraBitsPow; i++) {
uint16_t r_target = L_targets[parity][r][i];
for (uint8_t j = 0; j < rmap[r_target].size(); j++) {
matches.push_back(std::make_pair(pos_L, rmap[r_target][j]));
}
}
}

return matches;
}

Expand All @@ -402,8 +389,8 @@ class FxCalculator {
uint8_t block_3[kBlockSizeBits/8];
uint8_t block_4[kBlockSizeBits/8];
uint8_t ciphertext[kBlockSizeBits/8];
std::vector<std::vector<uint16_t> > R_positions;
std::vector<std::vector<uint16_t> > R_bids;
std::vector<std::vector<uint16_t>> rmap;
std::vector<uint16_t> rmap_clean;
};

#endif // SRC_CPP_CALCULATE_BUCKET_HPP_
6 changes: 5 additions & 1 deletion lib/chiapos/src/verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ class Verifier {
vector<PlotEntry> bucket_R = {r_plot_entry};

// If there is no match, fails.
if (f.FindMatches(bucket_L, bucket_R).size() != 1) {
uint64_t cdiff = r_plot_entry.y / kBC - l_plot_entry.y / kBC;
if (cdiff != 1) {
return LargeBits();
} else if (f.FindMatches(bucket_L, bucket_R).size() != 1) {
return LargeBits();
}

std::pair<Bits, Bits> results = f.CalculateBucket(ys[i], ys[i+1],
metadata[i], metadata[i+1]);
new_ys.push_back(std::get<0>(results));
Expand Down
Loading

0 comments on commit 281be67

Please sign in to comment.