Skip to content

Commit

Permalink
Merge pull request #402 from meritlabs/feature/pog3
Browse files Browse the repository at this point in the history
Merging PoG3 after testing concluded.
  • Loading branch information
mempko authored Oct 24, 2018
2 parents 1f14343 + 998532e commit 4e3e6f9
Show file tree
Hide file tree
Showing 17 changed files with 1,777 additions and 106 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 6)
define(_CLIENT_VERSION_REVISION, 5)
define(_CLIENT_VERSION_MINOR, 7)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2018)
Expand Down
6 changes: 6 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ MERIT_CORE_H = \
pog2/cgs.h \
pog2/select.h \
pog2/reward.h \
pog3/cgs.h \
pog3/select.h \
pog3/reward.h \
protocol.h \
random.h \
refdb.h \
Expand Down Expand Up @@ -234,6 +237,9 @@ libmerit_server_a_SOURCES = \
pog2/cgs.cpp \
pog2/reward.cpp \
pog2/select.cpp \
pog3/cgs.cpp \
pog3/reward.cpp \
pog3/select.cpp \
policy/fees.cpp \
policy/policy.cpp \
policy/rbf.cpp \
Expand Down
36 changes: 36 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ class CMainParams : public CChainParams
consensus.pog2_convex_b = 0.2;
consensus.pog2_convex_s = 0.05;

// PoG v3 settings.
consensus.pog3_blockheight = 441700; //October 31th 2018
consensus.pog3_total_winning_ambassadors = 20;
consensus.pog3_ambassador_percent_cut = 75; //75%
consensus.pog3_pow_target_timespan = 5 * 60 * 60; // every 5 hours
consensus.pog3_initial_ambassador_stake = 20_merit;
consensus.pog3_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
consensus.pog3_new_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
consensus.pog3_max_outstanding_invites_per_address = 20;
consensus.pog3_convex_b = 0.2;
consensus.pog3_convex_s = 0.05;

// Fix invite lottery distribution amount.
consensus.imp_fix_invites_blockheight = 348400;

Expand Down Expand Up @@ -358,6 +370,18 @@ class CTestNetParams : public CChainParams
consensus.pog2_convex_b = 0.2;
consensus.pog2_convex_s = 0.05;

// PoG v3 settings.
consensus.pog3_blockheight = 291500; //October 20th 2018
consensus.pog3_total_winning_ambassadors = 20;
consensus.pog3_ambassador_percent_cut = 75; //75%
consensus.pog3_pow_target_timespan = 5 * 60 * 60; // every 5 hours
consensus.pog3_initial_ambassador_stake = 20_merit;
consensus.pog3_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
consensus.pog3_new_coin_maturity = blocks_per_minute * 60 * 24 * 30; //Month for coin maturity
consensus.pog3_max_outstanding_invites_per_address = 20;
consensus.pog3_convex_b = 0.2;
consensus.pog3_convex_s = 0.05;

// Fix invite lottery distribution amount.
consensus.imp_fix_invites_blockheight = 217450;

Expand Down Expand Up @@ -502,6 +526,18 @@ class CRegTestParams : public CChainParams
consensus.pog2_convex_b = 0.2;
consensus.pog2_convex_s = 0.05;

// PoG v3 settings.
consensus.pog3_blockheight = 12;
consensus.pog3_total_winning_ambassadors = 20;
consensus.pog3_ambassador_percent_cut = 75; //75%
consensus.pog3_pow_target_timespan = 30 * 60; // every 30 min
consensus.pog3_initial_ambassador_stake = 20_merit;
consensus.pog3_coin_maturity = blocks_per_minute * 20; //20 minutes for coin maturity
consensus.pog3_new_coin_maturity = blocks_per_minute * 10; //10 minutes for coin maturity
consensus.pog3_max_outstanding_invites_per_address = 20;
consensus.pog3_convex_b = 0.2;
consensus.pog3_convex_s = 0.05;

consensus.imp_fix_invites_blockheight = 20;

pchMessageStart[0] = 0xfa;
Expand Down
12 changes: 12 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ struct Params {
double pog2_convex_b;
double pog2_convex_s;

/** PoG version 3 */
int pog3_blockheight;
int64_t pog3_total_winning_ambassadors;
int64_t pog3_ambassador_percent_cut;
int64_t pog3_pow_target_timespan;
CAmount pog3_initial_ambassador_stake;
int pog3_coin_maturity;
int pog3_new_coin_maturity;
int pog3_max_outstanding_invites_per_address;
double pog3_convex_b;
double pog3_convex_s;

};
} // namespace Consensus

Expand Down
7 changes: 1 addition & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,11 +1232,6 @@ bool AppInitLockDataDirectory()
return true;
}

namespace pog2
{
extern void SetupCgsThreadPool(size_t threads);
}

bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
{
const CChainParams& chainparams = Params();
Expand All @@ -1260,7 +1255,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
LogPrintf("Using config file %s\n", GetConfigFile(gArgs.GetArg("-conf", MERIT_CONF_FILENAME)).string());
LogPrintf("Using at most %i automatic connections (%i file descriptors available)\n", nMaxConnections, nFD);

pog2::SetupCgsThreadPool(boost::thread::hardware_concurrency());
pog3::SetupCgsThreadPool(boost::thread::hardware_concurrency());
InitSignatureCache();
InitScriptExecutionCache();

Expand Down
14 changes: 9 additions & 5 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,24 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
previousBlockHash,
subsidy.ambassador,
chain_params);
assert(lottery.first.remainder >= 0);

auto cgs_selector = lottery.second;
const auto& ambassador_lottery = std::get<0>(lottery);
assert(ambassador_lottery.remainder >= 0);

auto pog2_cgs_selector = std::get<1>(lottery);
auto pog3_cgs_selector = std::get<2>(lottery);

/**
* Update the coinbase transaction vout with rewards.
*/
PayAmbassadors(lottery.first, coinbaseTx);
PayAmbassadors(ambassador_lottery, coinbaseTx);

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

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

referral::ConfirmedAddresses dummy_selected_new_pool_addresses;
RewardInvites(
cgs_selector,
pog2_cgs_selector,
pog3_cgs_selector,
nHeight,
pindexPrev,
previousBlockHash,
Expand Down
16 changes: 7 additions & 9 deletions src/pog2/cgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace pog2
{
const size_t BATCH_SIZE = 100;
const int NO_GENESIS = 13500;
ctpl::thread_pool cgs_pool;
}

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

void SetupCgsThreadPool(size_t threads)
{
cgs_pool.resize(threads);
}

using UnspentPair = std::pair<CAddressUnspentKey, CAddressUnspentValue>;

using BigInt = boost::multiprecision::cpp_int;
Expand Down Expand Up @@ -470,11 +464,13 @@ namespace pog2
}

void ComputeAges(CGSContext& context) {
assert(context.cgs_pool != nullptr);

std::vector<std::future<void>> jobs;
jobs.reserve(context.entrants.size() / BATCH_SIZE);
for(size_t b = 0; b < context.entrants.size(); b+=BATCH_SIZE) {
jobs.push_back(
cgs_pool.push([b, &context](int id) {
context.cgs_pool->push([b, &context](int id) {
const auto end = std::min(context.entrants.size(), b + BATCH_SIZE);
for(size_t i = b; i < end; i++) {
auto& e = context.entrants[i];
Expand Down Expand Up @@ -526,12 +522,13 @@ namespace pog2
void ComputeAllContributions(
CGSContext& context,
referral::ReferralsViewCache& db) {
assert(context.cgs_pool != nullptr);

std::vector<std::future<void>> jobs;
jobs.reserve(context.entrants.size() / BATCH_SIZE);
for(size_t b = 0; b < context.entrants.size(); b+=BATCH_SIZE) {
jobs.push_back(
cgs_pool.push([b, &context, &db](int id) {
context.cgs_pool->push([b, &context, &db](int id) {
const auto end = std::min(context.entrants.size(), b + BATCH_SIZE);
for(size_t i = b; i < end; i++) {
auto& e = context.entrants[i];
Expand All @@ -550,6 +547,7 @@ namespace pog2
const Consensus::Params& params,
Entrants& entrants)
{
assert(context.cgs_pool != nullptr);
const auto minimum_stake = GetAmbassadorMinumumStake(context.tip_height, params);

std::vector<std::future<Entrants>> jobs;
Expand All @@ -561,7 +559,7 @@ namespace pog2
//Important, 1 here to skip the genesis address
for(size_t b = 1; b < context.entrants.size(); b+=BATCH_SIZE) {
jobs.push_back(
cgs_pool.push([b, minimum_stake , &context, &db](int id) {
context.cgs_pool->push([b, minimum_stake , &context, &db](int id) {
const auto end = std::min(context.entrants.size(), b + BATCH_SIZE);
Entrants es;
es.reserve(end - b);
Expand Down
3 changes: 2 additions & 1 deletion src/pog2/cgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "primitives/referral.h"
#include "consensus/params.h"
#include "ctpl/ctpl.h"
#include "referrals.h"
#include "pog/wrs.h"
#include "coins.h"
Expand Down Expand Up @@ -101,6 +102,7 @@ namespace pog2
CachedEntrant& GetEntrant(const referral::Address&);
const CachedEntrant& GetEntrant(const referral::Address&) const;

ctpl::thread_pool* cgs_pool = nullptr;
};

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

void TestChain();
void SetupCgsThreadPool(size_t threads);

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

Expand Down
Loading

0 comments on commit 4e3e6f9

Please sign in to comment.