Skip to content

Commit 4e3e6f9

Browse files
authored
Merge pull request #402 from meritlabs/feature/pog3
Merging PoG3 after testing concluded.
2 parents 1f14343 + 998532e commit 4e3e6f9

17 files changed

+1777
-106
lines changed

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
22
AC_PREREQ([2.60])
33
define(_CLIENT_VERSION_MAJOR, 0)
4-
define(_CLIENT_VERSION_MINOR, 6)
5-
define(_CLIENT_VERSION_REVISION, 5)
4+
define(_CLIENT_VERSION_MINOR, 7)
5+
define(_CLIENT_VERSION_REVISION, 0)
66
define(_CLIENT_VERSION_BUILD, 0)
77
define(_CLIENT_VERSION_IS_RELEASE, true)
88
define(_COPYRIGHT_YEAR, 2018)

src/Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ MERIT_CORE_H = \
137137
pog2/cgs.h \
138138
pog2/select.h \
139139
pog2/reward.h \
140+
pog3/cgs.h \
141+
pog3/select.h \
142+
pog3/reward.h \
140143
protocol.h \
141144
random.h \
142145
refdb.h \
@@ -234,6 +237,9 @@ libmerit_server_a_SOURCES = \
234237
pog2/cgs.cpp \
235238
pog2/reward.cpp \
236239
pog2/select.cpp \
240+
pog3/cgs.cpp \
241+
pog3/reward.cpp \
242+
pog3/select.cpp \
237243
policy/fees.cpp \
238244
policy/policy.cpp \
239245
policy/rbf.cpp \

src/chainparams.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ class CMainParams : public CChainParams
193193
consensus.pog2_convex_b = 0.2;
194194
consensus.pog2_convex_s = 0.05;
195195

196+
// PoG v3 settings.
197+
consensus.pog3_blockheight = 441700; //October 31th 2018
198+
consensus.pog3_total_winning_ambassadors = 20;
199+
consensus.pog3_ambassador_percent_cut = 75; //75%
200+
consensus.pog3_pow_target_timespan = 5 * 60 * 60; // every 5 hours
201+
consensus.pog3_initial_ambassador_stake = 20_merit;
202+
consensus.pog3_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
203+
consensus.pog3_new_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
204+
consensus.pog3_max_outstanding_invites_per_address = 20;
205+
consensus.pog3_convex_b = 0.2;
206+
consensus.pog3_convex_s = 0.05;
207+
196208
// Fix invite lottery distribution amount.
197209
consensus.imp_fix_invites_blockheight = 348400;
198210

@@ -358,6 +370,18 @@ class CTestNetParams : public CChainParams
358370
consensus.pog2_convex_b = 0.2;
359371
consensus.pog2_convex_s = 0.05;
360372

373+
// PoG v3 settings.
374+
consensus.pog3_blockheight = 291500; //October 20th 2018
375+
consensus.pog3_total_winning_ambassadors = 20;
376+
consensus.pog3_ambassador_percent_cut = 75; //75%
377+
consensus.pog3_pow_target_timespan = 5 * 60 * 60; // every 5 hours
378+
consensus.pog3_initial_ambassador_stake = 20_merit;
379+
consensus.pog3_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
380+
consensus.pog3_new_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
381+
consensus.pog3_max_outstanding_invites_per_address = 20;
382+
consensus.pog3_convex_b = 0.2;
383+
consensus.pog3_convex_s = 0.05;
384+
361385
// Fix invite lottery distribution amount.
362386
consensus.imp_fix_invites_blockheight = 217450;
363387

@@ -502,6 +526,18 @@ class CRegTestParams : public CChainParams
502526
consensus.pog2_convex_b = 0.2;
503527
consensus.pog2_convex_s = 0.05;
504528

529+
// PoG v3 settings.
530+
consensus.pog3_blockheight = 12;
531+
consensus.pog3_total_winning_ambassadors = 20;
532+
consensus.pog3_ambassador_percent_cut = 75; //75%
533+
consensus.pog3_pow_target_timespan = 30 * 60; // every 30 min
534+
consensus.pog3_initial_ambassador_stake = 20_merit;
535+
consensus.pog3_coin_maturity = blocks_per_minute * 20; //20 minutes for coin maturity
536+
consensus.pog3_new_coin_maturity = blocks_per_minute * 10; //10 minutes for coin maturity
537+
consensus.pog3_max_outstanding_invites_per_address = 20;
538+
consensus.pog3_convex_b = 0.2;
539+
consensus.pog3_convex_s = 0.05;
540+
505541
consensus.imp_fix_invites_blockheight = 20;
506542

507543
pchMessageStart[0] = 0xfa;

src/consensus/params.h

+12
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ struct Params {
118118
double pog2_convex_b;
119119
double pog2_convex_s;
120120

121+
/** PoG version 3 */
122+
int pog3_blockheight;
123+
int64_t pog3_total_winning_ambassadors;
124+
int64_t pog3_ambassador_percent_cut;
125+
int64_t pog3_pow_target_timespan;
126+
CAmount pog3_initial_ambassador_stake;
127+
int pog3_coin_maturity;
128+
int pog3_new_coin_maturity;
129+
int pog3_max_outstanding_invites_per_address;
130+
double pog3_convex_b;
131+
double pog3_convex_s;
132+
121133
};
122134
} // namespace Consensus
123135

src/init.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,6 @@ bool AppInitLockDataDirectory()
12321232
return true;
12331233
}
12341234

1235-
namespace pog2
1236-
{
1237-
extern void SetupCgsThreadPool(size_t threads);
1238-
}
1239-
12401235
bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12411236
{
12421237
const CChainParams& chainparams = Params();
@@ -1260,7 +1255,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12601255
LogPrintf("Using config file %s\n", GetConfigFile(gArgs.GetArg("-conf", MERIT_CONF_FILENAME)).string());
12611256
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);
12621257

1263-
pog2::SetupCgsThreadPool(boost::thread::hardware_concurrency());
1258+
pog3::SetupCgsThreadPool(boost::thread::hardware_concurrency());
12641259
InitSignatureCache();
12651260
InitScriptExecutionCache();
12661261

src/miner.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,24 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
245245
previousBlockHash,
246246
subsidy.ambassador,
247247
chain_params);
248-
assert(lottery.first.remainder >= 0);
249248

250-
auto cgs_selector = lottery.second;
249+
const auto& ambassador_lottery = std::get<0>(lottery);
250+
assert(ambassador_lottery.remainder >= 0);
251+
252+
auto pog2_cgs_selector = std::get<1>(lottery);
253+
auto pog3_cgs_selector = std::get<2>(lottery);
251254

252255
/**
253256
* Update the coinbase transaction vout with rewards.
254257
*/
255-
PayAmbassadors(lottery.first, coinbaseTx);
258+
PayAmbassadors(ambassador_lottery, coinbaseTx);
256259

257260
/**
258261
* The miner recieves their subsidy and any remaining subsidy that was left
259262
* over from paying the ambassadors. The reason there is a remaining subsidy
260263
* is because we use integer math.
261264
*/
262-
const auto miner_subsidy = subsidy.miner + lottery.first.remainder;
265+
const auto miner_subsidy = subsidy.miner + ambassador_lottery.remainder;
263266
assert(miner_subsidy > 0);
264267

265268
coinbaseTx.vout[0].nValue = nFees + miner_subsidy;
@@ -303,7 +306,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
303306

304307
referral::ConfirmedAddresses dummy_selected_new_pool_addresses;
305308
RewardInvites(
306-
cgs_selector,
309+
pog2_cgs_selector,
310+
pog3_cgs_selector,
307311
nHeight,
308312
pindexPrev,
309313
previousBlockHash,

src/pog2/cgs.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace pog2
2323
{
2424
const size_t BATCH_SIZE = 100;
2525
const int NO_GENESIS = 13500;
26-
ctpl::thread_pool cgs_pool;
2726
}
2827

2928
CAmount GetAmbassadorMinumumStake(int height, const Consensus::Params& consensus_params)
@@ -33,11 +32,6 @@ namespace pog2
3332
consensus_params.pog2_initial_ambassador_stake >> halvings : 0;
3433
}
3534

36-
void SetupCgsThreadPool(size_t threads)
37-
{
38-
cgs_pool.resize(threads);
39-
}
40-
4135
using UnspentPair = std::pair<CAddressUnspentKey, CAddressUnspentValue>;
4236

4337
using BigInt = boost::multiprecision::cpp_int;
@@ -470,11 +464,13 @@ namespace pog2
470464
}
471465

472466
void ComputeAges(CGSContext& context) {
467+
assert(context.cgs_pool != nullptr);
468+
473469
std::vector<std::future<void>> jobs;
474470
jobs.reserve(context.entrants.size() / BATCH_SIZE);
475471
for(size_t b = 0; b < context.entrants.size(); b+=BATCH_SIZE) {
476472
jobs.push_back(
477-
cgs_pool.push([b, &context](int id) {
473+
context.cgs_pool->push([b, &context](int id) {
478474
const auto end = std::min(context.entrants.size(), b + BATCH_SIZE);
479475
for(size_t i = b; i < end; i++) {
480476
auto& e = context.entrants[i];
@@ -526,12 +522,13 @@ namespace pog2
526522
void ComputeAllContributions(
527523
CGSContext& context,
528524
referral::ReferralsViewCache& db) {
525+
assert(context.cgs_pool != nullptr);
529526

530527
std::vector<std::future<void>> jobs;
531528
jobs.reserve(context.entrants.size() / BATCH_SIZE);
532529
for(size_t b = 0; b < context.entrants.size(); b+=BATCH_SIZE) {
533530
jobs.push_back(
534-
cgs_pool.push([b, &context, &db](int id) {
531+
context.cgs_pool->push([b, &context, &db](int id) {
535532
const auto end = std::min(context.entrants.size(), b + BATCH_SIZE);
536533
for(size_t i = b; i < end; i++) {
537534
auto& e = context.entrants[i];
@@ -550,6 +547,7 @@ namespace pog2
550547
const Consensus::Params& params,
551548
Entrants& entrants)
552549
{
550+
assert(context.cgs_pool != nullptr);
553551
const auto minimum_stake = GetAmbassadorMinumumStake(context.tip_height, params);
554552

555553
std::vector<std::future<Entrants>> jobs;
@@ -561,7 +559,7 @@ namespace pog2
561559
//Important, 1 here to skip the genesis address
562560
for(size_t b = 1; b < context.entrants.size(); b+=BATCH_SIZE) {
563561
jobs.push_back(
564-
cgs_pool.push([b, minimum_stake , &context, &db](int id) {
562+
context.cgs_pool->push([b, minimum_stake , &context, &db](int id) {
565563
const auto end = std::min(context.entrants.size(), b + BATCH_SIZE);
566564
Entrants es;
567565
es.reserve(end - b);

src/pog2/cgs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "primitives/referral.h"
99
#include "consensus/params.h"
10+
#include "ctpl/ctpl.h"
1011
#include "referrals.h"
1112
#include "pog/wrs.h"
1213
#include "coins.h"
@@ -101,6 +102,7 @@ namespace pog2
101102
CachedEntrant& GetEntrant(const referral::Address&);
102103
const CachedEntrant& GetEntrant(const referral::Address&) const;
103104

105+
ctpl::thread_pool* cgs_pool = nullptr;
104106
};
105107

106108
using Entrants = std::vector<Entrant>;
@@ -119,7 +121,6 @@ namespace pog2
119121
referral::ReferralsViewCache& db);
120122

121123
void TestChain();
122-
void SetupCgsThreadPool(size_t threads);
123124

124125
CAmount GetAmbassadorMinumumStake(int height, const Consensus::Params& consensus_params);
125126

0 commit comments

Comments
 (0)