Skip to content

Commit

Permalink
Force different algos
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvforvendetta committed Apr 6, 2018
1 parent e459d43 commit 80c81ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
42 changes: 28 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,26 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c
return true;
}

bool CBlock::CheckPrevAlgo(CBlockIndex* pIndex)
{
unsigned checkedBlocks = 0;
unsigned sameAlgoBlocks = 0;

while (pIndex && checkedBlocks != 2*SAME_ALGO_MAX_COUNT)
{
if (::GetAlgo(pIndex->nVersion) == GetAlgo())
++sameAlgoBlocks;

++checkedBlocks;
pIndex = pIndex->pprev;
}

if (sameAlgoBlocks > SAME_ALGO_MAX_COUNT)

This comment has been minimized.

Copy link
@strazzere

strazzere Apr 6, 2018

Contributor

So using this logic - VERGE will now essentially only allow half the blocks in the past 10 to be (or whatever SAME_ALGO_MAX_COUNT may change to) be allowed in the future?

This might be good to document as it would likely be preferable for miners to optimize their efficency.

On a related note, it appears based on other bits of code in main.h that PoS is currently pinned to scrypt - which would mean that folks participating in PoS or mining via scrypt that may hit the maximum allowed for that algorithm counts more often than the other algorithms.

These all might be acceptable choices - I'm mainly asking if this was all intended and if they'll be documented.

return false;

return true;
}

bool CBlock::AcceptBlock()
{
// Check for duplicate
Expand All @@ -2299,25 +2319,19 @@ bool CBlock::AcceptBlock()
CBlockIndex* pindexPrev = (*mi).second;
int nHeight = pindexPrev->nHeight+1;

if (nHeight > ALGO_RULES_SWITCH_BLOCK)
{
if (!CheckPrevAlgo(pindexPrev))
return error("AcceptBlock() : too many blocks found using same algorithm");
}

// Check proof-of-work or proof-of-stake
if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake(), GetAlgo()))
return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake"));

// Check timestamp against prev
if (nHeight <= TIMESTAMP_RULES_SWITCH_BLOCK)
{
const unsigned oldMaxDrift = 7200; //2 hours
if (GetBlockTime() <= pindexPrev->GetMedianTimePast() || GetBlockTime() + oldMaxDrift < pindexPrev->GetBlockTime())
return error("AcceptBlock() : block's timestamp is too early");
}
else
{
if (GetBlockTime() < pindexPrev->GetBlockTime())
return error("AcceptBlock() : block's timestamp is too early");

if (GetBlockTime() > GetAdjustedTime() + nMaxClockDrift)
return error("AcceptBlock() : block too much in the future");
}
if (GetBlockTime() <= pindexPrev->GetMedianTimePast() || GetBlockTime() + nMaxClockDrift < pindexPrev->GetBlockTime())
return error("AcceptBlock() : block's timestamp is too early");

// Check that all transactions are finalized
BOOST_FOREACH(const CTransaction& tx, vtx)
Expand Down
4 changes: 3 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class CNode;

static const int MULTI_ALGO_SWITCH_BLOCK = 340000;
static const int STEALTH_TX_SWITCH_BLOCK = 1824150;
static const int TIMESTAMP_RULES_SWITCH_BLOCK = 2040000;
static const int ALGO_RULES_SWITCH_BLOCK = 2042000;
static const int SAME_ALGO_MAX_COUNT = 5;
static const unsigned int MAX_BLOCK_SIZE = 1000000;
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
Expand Down Expand Up @@ -1008,6 +1009,7 @@ class CBlock : public CBlockHeader
}

int GetAlgo() const { return ::GetAlgo(nVersion); }
bool CheckPrevAlgo(CBlockIndex* pIndex);

IMPLEMENT_SERIALIZE
(
Expand Down

7 comments on commit 80c81ae

@strazzere
Copy link
Contributor

Choose a reason for hiding this comment

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

Pardon - since this is removing the original switch which would occur at block 2040000, is there not a issue where some nodes may be running code for that fork soon?

Mostly curious if the fork should have been kept and the second layer on top of it to prevent thrashing between blocks 2040000 and 2042000. Though maybe this is just too small of a chunk (or the no one has upgraded?) for it to matter.

@justinvforvendetta
Copy link
Member Author

Choose a reason for hiding this comment

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

i have been contacting everyone, and am still doing that now.

@justinvforvendetta
Copy link
Member Author

Choose a reason for hiding this comment

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

@strazzere pos is disabled =]

@strazzere
Copy link
Contributor

Choose a reason for hiding this comment

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

That would make more sense then - might still be good to document the current variables and such as it might allow some miners (or some miningpooltype place) to implement switching if the chain is already "full" of the hashes it can potentially provide through that algorithm.

@justinvforvendetta
Copy link
Member Author

Choose a reason for hiding this comment

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

thats a solid idea

@ocminer
Copy link

Choose a reason for hiding this comment

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

I'm impressed, you actually seem to managed to insert/merge the code I mentioned from myriad, good work, hope it works :)

@justinvforvendetta
Copy link
Member Author

Choose a reason for hiding this comment

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

it's not identical but it is working. we're working on a much more sophisticated block verification routine now though :)

Please sign in to comment.