Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bitmarkd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void DetectShutdownThread(boost::thread_group* threadGroup)
//
bool AppInit(int argc, char* argv[])
{
printf("appinit\n");
boost::thread_group threadGroup;
boost::thread* detectShutdownThread = NULL;

Expand Down Expand Up @@ -110,7 +109,7 @@ bool AppInit(int argc, char* argv[])
std::string strUsage = _("Bitmark Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
fprintf(stdout, "%s", strUsage.c_str());
return false;
}
}

// Command-line RPC
bool fCommandLine = false;
Expand Down Expand Up @@ -183,7 +182,6 @@ bool AppInit(int argc, char* argv[])

int main(int argc, char* argv[])
{
printf("main");
SetupEnvironment();

bool fRet = false;
Expand Down
11 changes: 8 additions & 3 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ class CBlockIndex
int64_t nMoneySupply;

// the scaling factor for the block
unsigned int subsidyScalingFactor;
CBigNum subsidyScalingFactor;

// Which # file this block is stored in (blk?????.dat)
int nFile;
Expand Down Expand Up @@ -924,6 +924,11 @@ class CBlockIndex
return false;
}

bool onFork2() const {
if (this->nHeight >= nForkHeight && IsSuperMajority(5,this->pprev,950,1000)) return true;
return false;
}

CBlockHeader GetBlockHeader() const
{
CBlockHeader block;
Expand Down Expand Up @@ -977,7 +982,7 @@ class CBlockIndex
//LogPrintf("algo is %d and weight is %lu\n",nVersion & BLOCK_VERSION_ALGO,weight.getulong());
return (CBigNum(1)<<256) / (bnTarget/weight+1);
}

// Get Average Work of latest 50 Blocks
CBigNum GetBlockWorkAv() const
{
Expand All @@ -988,7 +993,7 @@ class CBlockIndex
work += pindex->GetBlockWork();
n++;
pindex = pindex->pprev;
if (!pindex) break;
if (!pindex) break;
}
return work/n;
}
Expand Down
47 changes: 32 additions & 15 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,12 +1202,17 @@ bool onFork (const CBlockIndex * pindex) {
return pindex->onFork();
}

bool onFork2(const CBlockIndex * pindex) {
return pindex->onFork2();
}

int64_t GetBlockValue(CBlockIndex* pindex, int64_t nFees, bool noScale)
{
// for testnet
int nHeight = pindex->nHeight;
bool onForkNow = onFork(pindex);

if (!onFork(pindex)) {
if (!onForkNow) {
int64_t nHalfReward = 10 * COIN;
int64_t nSubsidy = 0;
int halvings = nHeight / Params().SubsidyHalvingInterval();
Expand Down Expand Up @@ -1236,10 +1241,10 @@ int64_t GetBlockValue(CBlockIndex* pindex, int64_t nFees, bool noScale)
emitted = NUM_ALGOS * get_mpow_ms_correction(pindex);
}

unsigned int scalingFactor = 0;
if (onFork(pindex) && !noScale) {
CBigNum scalingFactor = CBigNum(0);
if (onForkNow && !noScale) {
scalingFactor = pindex->subsidyScalingFactor;
if (!scalingFactor) { // find the key block and recalculate
if (!scalingFactor.getuint()) { // find the key block and recalculate
CBlockIndex * pprev_algo = pindex;
do {
if (update_ssf(pprev_algo->nVersion)) {
Expand Down Expand Up @@ -1549,7 +1554,7 @@ unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, int algo) {
if (lastInRow>=9 && !lastInRowMod) {
bnNew /= 3;
}
else if (!justHadSurge) {
else if (!justHadSurge || smultiply && CBlockIndex::IsSuperMajority(5,pindexLast,75,100)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is forking change.

bnNew *= nActualTimespan;
bnNew /= _nTargetTimespan;
}
Expand Down Expand Up @@ -2106,15 +2111,22 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
// Check it again in case a previous version let a bad block in
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck))
return false;

bool onForkNow = onFork(pindex);

// Force min version after fork
if (onFork(pindex) && block.nVersion<CBlock::CURRENT_VERSION) {
LogPrintf("nVersion<=2 and after fork\n");
if (onForkNow && block.nVersion<4) {
LogPrintf("version<4 and after fork\n");
return false;
}

if (onFork2(pindex) && GetBlockVersion(block.nVersion)<5) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential forking change.

LogPrintf("version<5 and after fork\n");
return false;
}

// Check SSF
if (onFork(pindex)) { //new multi algo blocks are identified like this
if (onForkNow) { //new multi algo blocks are identified like this
CBlockIndex * pprev_algo = pindex;
if (update_ssf(pindex->nVersion)) {
for (int i=0; i<nSSF; i++) {
Expand Down Expand Up @@ -2189,7 +2201,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
}

if (onFork(pindex)) {
if (onForkNow) {
flags |= SCRIPT_VERIFY_DERSIG;
}

Expand Down Expand Up @@ -2250,7 +2262,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C

CBlockIndex * pprev_algo = 0;
if (!fJustCheck) pprev_algo = get_pprev_algo(pindex,-1);
if (!fJustCheck && onFork(pindex)) { // set scaling factor
if (!fJustCheck && onForkNow) { // set scaling factor
if (update_ssf(pindex->nVersion)) {
pindex->subsidyScalingFactor = get_ssf(pindex);
}
Expand All @@ -2264,7 +2276,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
if (block.vtx[0].GetValueOut() > block_value_needed)
return state.DoS(100,
error("ConnectBlock() : coinbase pays too much (actual=%d vs limit=%d)",
block.vtx[0].GetValueOut(), GetBlockValue(pindex, nFees, false)),
block.vtx[0].GetValueOut(), block_value_needed),
REJECT_INVALID, "bad-cb-amount");

if (block.vtx[0].GetValueOut() < block_value_needed) {
Expand All @@ -2282,7 +2294,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C

// Increment the nMoneySupply to include this blocks subsidy

if (onFork(pindex)) {
if (onForkNow) {
if (pprev_algo) {
pindex->nMoneySupply = pprev_algo->nMoneySupply + block.vtx[0].GetValueOut() - nFees;
}
Expand Down Expand Up @@ -4956,8 +4968,8 @@ bool update_ssf (int nVersion) {
return nVersion & BLOCK_VERSION_UPDATE_SSF;
}

unsigned int get_ssf (CBlockIndex * pindex) {
unsigned int scalingFactor = 0; // ensures that it has no effect
CBigNum get_ssf (CBlockIndex * pindex) {
CBigNum scalingFactor = CBigNum(0); // ensures that it has no effect
CBlockIndex * pprev_algo = pindex;
CBigNum hashes_peak = CBigNum(0);
CBigNum hashes_cur = CBigNum(0);
Expand Down Expand Up @@ -5004,7 +5016,12 @@ unsigned int get_ssf (CBlockIndex * pindex) {
if (i==0) hashes_cur = hashes;
}
if (hashes_peak > CBigNum(0) && hashes_cur != hashes_peak) {
scalingFactor = ((100000000*hashes_peak)/(hashes_peak-hashes_cur)).getuint(); // a 9-10 digit integer
if (onFork2(pindex)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forking change.

scalingFactor = (100000000*hashes_peak)/(hashes_peak-hashes_cur);
}
else {
scalingFactor = CBigNum(((100000000*hashes_peak)/(hashes_peak-hashes_cur)).getuint());
}
}
//LogPrintf("return scaling factor %lu\n",scalingFactor);
return scalingFactor;
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ int64_t get_mpow_ms_correction (CBlockIndex * p);
bool update_ssf (int nVersion);

/* Calculate the subsidy scaling factor for the CBlockIndex pointer */
unsigned int get_ssf (CBlockIndex * pindex);
CBigNum get_ssf (CBlockIndex * pindex);

/* Get the number of blocks since the last update of the subsidy scaling factor */
int get_ssf_height (const CBlockIndex * pindex);
Expand Down
2 changes: 1 addition & 1 deletion src/pureheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum

class CPureBlockHeader { // Needed to resolve circular dependecies with CAuxPow in CBlockHeader
public:
static const int CURRENT_VERSION=4;
static const int CURRENT_VERSION=5;
int nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
Expand Down
1 change: 1 addition & 0 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
result.push_back(Pair("height", blockindex->nHeight));
result.push_back(Pair("version", block.nVersion));
result.push_back(Pair("coreversion",GetBlockVersion(block.nVersion)));
int algo = GetAlgo(block.nVersion);
result.push_back(Pair("algo",GetAlgoName(algo)));
bool auxpow = block.IsAuxpow();
Expand Down