Commit 9dbf8257 authored by Adam P. Goucher's avatar Adam P. Goucher

Move difficulty ascertaining code to lifelib

parent 2daf4c3e
#define MAX_DIFFICULTY 1.0e80
typedef double difficul_t;
typedef std::pair<difficul_t, std::string> dsentry;
namespace apg {
class DifficultyHolder {
std::map<std::string, difficul_t> difficulties;
public:
DifficultyHolder() {
#include "difficulties.inc"
}
std::string representative(std::string apgcode) {
auto it = difficulties.find(apgcode);
if (it != difficulties.end()) { return apgcode; }
auto x = apgcode.find('_');
if (x == std::string::npos) { return apgcode; }
std::string prefix = apgcode.substr(0, x);
auto it2 = difficulties.find(prefix);
if (it2 != difficulties.end()) { return prefix; }
if (apgcode.substr(0, 2) == "yl") {
uint64_t period = std::stoll(apgcode.substr(2));
if ((period == 144) || (period % 96 == 0)) {
return "corderpuffer";
}
}
return apgcode;
}
difficul_t rep_difficulty(std::string rep) {
auto it = difficulties.find(rep);
if (it == difficulties.end()) {
return MAX_DIFFICULTY;
} else {
return it->second;
}
}
difficul_t get_difficulty(std::string apgcode) {
if ((apgcode[0] != 'y') && ((apgcode[0] != 'x') || (apgcode[1] == 's'))) {
// Not an oscillator, spaceship, or linear-growth pattern:
return 0;
}
return rep_difficulty(representative(apgcode));
}
std::map<std::string, int64_t> to_reps(std::map<std::string, int64_t> &occ) {
std::map<std::string, int64_t> occ2;
for (auto it = occ.begin(); it != occ.end(); ++it) {
occ2[representative(it->first)] += it->second;
}
return occ2;
}
void set_difficulties(std::string standard, std::map<std::string, int64_t> &occ_raw) {
/*
* Update difficulty estimates based upon initial segment of blockchain
* objects. This only affects the difficulties of objects in such a way
* that it cannot invalidate existing blocks.
*/
auto occ = to_reps(occ_raw);
std::set<std::pair<int64_t, std::string> > nocc;
int64_t totobj = 0;
for (auto it = occ.begin(); it != occ.end(); ++it) {
difficul_t di = rep_difficulty(it->first);
if (di > difficulties[standard]) {
nocc.emplace(it->second, it->first);
totobj += it->second;
}
}
totobj += occ[standard];
int64_t cumobj = 0;
for (auto it = nocc.begin(); it != nocc.end(); ++it) {
cumobj += it->first;
difficulties[it->second] = (difficulties[standard] * totobj) / cumobj;
}
}
};
}
// Proof-of-work difficulty table
// Difficulty estimates are in approximate CPU-minutes
// on a hypothetical machine running 2000 soups/second
difficulties[ "xp2_7"] = 0.0000;
difficulties[ "xq4_153"] = 0.0000;
difficulties[ "xp2_7e"] = 0.0001;
difficulties[ "xp2_318c"] = 0.0004;
difficulties[ "xq4_6frc"] = 0.0016;
difficulties[ "xp3_co9nas0san9oczgoldlo0oldlogz1047210127401"] = 0.0034;
difficulties[ "xq4_27dee6"] = 0.0090;
difficulties[ "xq4_27deee6"] = 0.0476;
difficulties[ "xp15_4r4z4r4"] = 0.1833;
difficulties[ "xp2_2a54"] = 0.2902;
difficulties[ "yl144_1_16_afb5f3db909e60548f086e22ee3353ac"] = 0.4396;
difficulties[ "yl384_1_59_7aeb1999980c43b4945fb7fcdb023326"] = 0.8157;
difficulties[ "xp2_31ago"] = 1.1790;
difficulties[ "xp2_0g0k053z32"] = 1.6579;
difficulties[ "xp2_g8gid1e8z1226"] = 2.6037;
difficulties[ "xp8_gk2gb3z11"] = 4.2891;
difficulties[ "xp2_rhewehr"] = 6.2025;
difficulties[ "xp2"] = 8.9413;
difficulties[ "xp4_37bkic"] = 14.4504;
difficulties[ "xp4_ssj3744zw3"] = 35.6755;
difficulties[ "xp8_g3jgz1ut"] = 49.5369;
difficulties[ "xp3_695qc8zx33"] = 67.9099;
difficulties[ "xp30_w33z8kqrqk8zzzx33"] = 94.4202;
difficulties[ "xp30_w33z8kqrqk8zzzw33"] = 121.5940;
difficulties[ "xp4_8eh5e0e5he8z178a707a871"] = 169.4148;
difficulties[ "xp5_idiidiz01w1"] = 226.3152;
difficulties[ "xp6_ccb7w66z066"] = 314.1888;
difficulties[ "xp3"] = 509.2696;
difficulties[ "xp14_j9d0d9j"] = 903.6111;
difficulties[ "xp8_wgovnz234z33"] = 3345.3205;
difficulties[ "xq4_27dee6z4eb776"] = 8255.3738;
difficulties[ "xq4"] = 12900.3796;
difficulties[ "xp5_3pmwmp3zx11"] = 24815.9591;
difficulties[ "xp15_4r4y14r4z4r4y14r4"] = 37667.7357;
difficulties[ "xp4_8eh5e0e5he8gz178a707a871"] = 52397.1833;
difficulties[ "xp4"] = 77136.7734;
difficulties[ "xp46_330279cx1aad3y833zx4e93x855bc"] = 103182.1455;
difficulties[ "xp46_330279cx1aad3zx4e93x855bcy8cc"] = 141904.1756;
difficulties[ "xp15"] = 198489.0183;
difficulties[ "xp30"] = 305587.4094;
difficulties[ "xp6"] = 558903.2883;
difficulties[ "xp5"] = 724033.8053;
difficulties[ "yl1152"] = 916762.2283;
difficulties[ "corderpuffer"] = 1190934.1096;
difficulties[ "xp8_2erore2z07x7"] = 1554023.7772;
difficulties[ "xp24_co9nas0san9oczgoldlo0oldlogy0ggz1047210127401y01581qo"] = 1991092.9645;
difficulties[ "xp8_25du4szx327ba4"] = 2600611.2189;
difficulties[ "xp46_033y133zzzckgsxsgkczz0cc"] = 3747939.6979;
difficulties[ "xp8"] = 5097197.9891;
difficulties[ "xq16_gcbgzvgg826frc"] = 7495879.3957;
difficulties[ "xp24_co9nas0san9ocy0ssszgoldlo0oldlogy3777z1047210127401"] = 12742994.9727;
difficulties[ "xp46"] = 31857487.4318;
difficulties[ "xq12"] = 127429949.7274;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment