Skip to content

Commit

Permalink
Do 150000-hardfork on testnet at 108000.
Browse files Browse the repository at this point in the history
  • Loading branch information
domob1812 committed Dec 17, 2014
1 parent 08d3deb commit af8b5e6
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/namecoin.cpp
Expand Up @@ -25,7 +25,6 @@ extern int64 AmountFromValue(const Value& value);
extern Object JSONRPCError(int code, const string& message);
template<typename T> void ConvertTo(Value& value, bool fAllowNull=false);

static const int BUG_WORKAROUND_BLOCK_START = 139750; // Bug was not exploited before block 139872, so skip checking earlier blocks
static const int BUG_WORKAROUND_BLOCK = 150000; // Point of hard fork

std::map<vchType, uint256> mapMyNames;
Expand Down Expand Up @@ -115,6 +114,19 @@ class CNamecoinHooks : public CHooks
}
};

/**
* Check whether the given height is post-libcoin-hardfork. I. e.,
* strict checks for name_update and tx decoding should be applied.
*/
static bool
postLibcoinFork(unsigned nHeight)
{
if (fTestNet)
return nHeight >= 108000;

return nHeight >= BUG_WORKAROUND_BLOCK;
}

int64 getAmount(Value value)
{
ConvertTo<double>(value);
Expand Down Expand Up @@ -1734,7 +1746,7 @@ bool CNameDB::ReconstructNameIndex()

// Bug workaround
CDiskTxPos prevTxPos;
if (nHeight >= BUG_WORKAROUND_BLOCK_START && nHeight < BUG_WORKAROUND_BLOCK)
if (!postLibcoinFork (nHeight))
if (!NameBugWorkaround(tx, txdb, &prevTxPos))
{
printf("NameBugWorkaround rejected tx %s at height %d (name %s)\n", tx.GetHash().ToString().c_str(), nHeight, stringFromVch(vchName).c_str());
Expand All @@ -1748,7 +1760,8 @@ bool CNameDB::ReconstructNameIndex()
return error("Rescanfornames() : failed to read from name DB");
}

if (op == OP_NAME_UPDATE && nHeight >= BUG_WORKAROUND_BLOCK_START && nHeight < BUG_WORKAROUND_BLOCK && !CheckNameTxPos(vtxPos, prevTxPos))
if (op == OP_NAME_UPDATE && !postLibcoinFork (nHeight)
&& !CheckNameTxPos(vtxPos, prevTxPos))
{
printf("NameBugWorkaround rejected tx %s at height %d (name %s), because previous tx was also rejected\n", tx.GetHash().ToString().c_str(), nHeight, stringFromVch(vchName).c_str());
continue;
Expand Down Expand Up @@ -1864,7 +1877,7 @@ bool DecodeNameTx(const CTransaction& tx, int& op, int& nOut, vector<vector<unsi
}

// Bug workaround
if (nHeight >= BUG_WORKAROUND_BLOCK)
if (postLibcoinFork (nHeight))
{
// Strict check - bug disallowed
for (int i = 0; i < tx.vout.size(); i++)
Expand Down Expand Up @@ -2165,7 +2178,7 @@ CNamecoinHooks::ConnectInputs (DatabaseSet& dbset,
std::vector<vchType> vvchPrevArgs;

// Bug workaround
if (fMiner || !fBlock || pindexBlock->nHeight >= BUG_WORKAROUND_BLOCK)
if (fMiner || !fBlock || postLibcoinFork (pindexBlock->nHeight))
{
// Strict check - bug disallowed
for (int i = 0; i < tx.vin.size(); i++)
Expand Down Expand Up @@ -2306,7 +2319,7 @@ CNamecoinHooks::ConnectInputs (DatabaseSet& dbset,
uint160 hash = Hash160(vchToHash);
if (uint160(vchHash) != hash)
{
if (pindexBlock->nHeight >= BUG_WORKAROUND_BLOCK)
if (postLibcoinFork (pindexBlock->nHeight))
return error("ConnectInputsHook() : name_firstupdate hash mismatch");
else
{
Expand Down Expand Up @@ -2360,7 +2373,7 @@ CNamecoinHooks::ConnectInputs (DatabaseSet& dbset,
// Check name
if (vvchPrevArgs[0] != vvchArgs[0])
{
if (pindexBlock->nHeight >= BUG_WORKAROUND_BLOCK)
if (postLibcoinFork (pindexBlock->nHeight))
return error("ConnectInputsHook() : name_update name mismatch");
else
{
Expand Down Expand Up @@ -2412,7 +2425,7 @@ CNamecoinHooks::ConnectInputs (DatabaseSet& dbset,
{
printf("ConnectInputsHook() : Name bug workaround: tx %s rejected, since previous tx (%s) is not in the name DB\n", tx.GetHash().ToString().c_str(), vTxPrev[nInput].GetHash().ToString().c_str());
// Valid tx on top of buggy tx: reject only after hard-fork
if (pindexBlock->nHeight >= BUG_WORKAROUND_BLOCK)
if (postLibcoinFork (pindexBlock->nHeight))
return false;
else
fBugWorkaround = true;
Expand Down

0 comments on commit af8b5e6

Please sign in to comment.