Skip to content

Commit

Permalink
Merge pull request #32 from ghostlander/master
Browse files Browse the repository at this point in the history
Diamond v2.1
  • Loading branch information
DMDcoin committed May 8, 2016
2 parents 0388777 + 7fb011a commit d1a86ed
Show file tree
Hide file tree
Showing 54 changed files with 2,661 additions and 590 deletions.
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013-2015 Diamond Foundation
Copyright (c) 2013-2016 Diamond Foundation
Copyright (c) 2011-2012 PPCoin Developers
Copyright (c) 2009-2012 Bitcoin Developers

Expand Down
11 changes: 8 additions & 3 deletions diamond.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = diamond-qt
VERSION = 2.0.5.7
VERSION = 2.1.0.1
INCLUDEPATH += src src/json src/qt
QT += core gui network
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN __NO_SYSTEM_INCLUDES
Expand Down Expand Up @@ -228,7 +228,9 @@ HEADERS += src/qt/bitcoingui.h \
src/hash.h \
src/scrypt.h \
src/sph_groestl.h \
src/sph_types.h
src/sph_types.h \
src/auxpow.h \
src/reactors.h

SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/transactiontablemodel.cpp \
Expand Down Expand Up @@ -299,7 +301,10 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/pbkdf2.cpp \
src/hash.cpp \
src/scrypt.cpp \
src/groestl.c
src/groestl.c \
src/auxpow.cpp \
src/reactors.cpp \
src/reactorlist.cpp

RESOURCES += \
src/qt/bitcoin.qrc
Expand Down
129 changes: 129 additions & 0 deletions src/auxpow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright (c) 2011 Vince Durham
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#include "script.h"
#include "auxpow.h"
#include "init.h"

using namespace std;
using namespace boost;

unsigned char pchMergedMiningHeader[] = { 0xfa, 0xbe, 'm', 'm' } ;

void RemoveMergedMiningHeader(vector<unsigned char>& vchAux)
{
if (vchAux.begin() != std::search(vchAux.begin(), vchAux.end(), UBEGIN(pchMergedMiningHeader), UEND(pchMergedMiningHeader)))
throw runtime_error("merged mining aux too short");
vchAux.erase(vchAux.begin(), vchAux.begin() + sizeof(pchMergedMiningHeader));
}

bool CAuxPow::Check(uint256 hashAuxBlock, int nChainID)
{
if (nIndex != 0)
return error("AuxPow is not a generate");

if (!fTestNet && parentBlock.GetChainID() == nChainID)
return error("Aux POW parent has our chain ID");

if (vChainMerkleBranch.size() > 30)
return error("Aux POW chain merkle branch too long");

// Check that the chain merkle root is in the coinbase
uint256 nRootHash = CBlock::CheckMerkleBranch(hashAuxBlock, vChainMerkleBranch, nChainIndex);
vector<unsigned char> vchRootHash(nRootHash.begin(), nRootHash.end());
std::reverse(vchRootHash.begin(), vchRootHash.end()); // correct endian

// Check that we are in the parent block merkle tree
if (CBlock::CheckMerkleBranch(GetHash(), vMerkleBranch, nIndex) != parentBlock.hashMerkleRoot)
return error("Aux POW merkle root incorrect");

const CScript script = vin[0].scriptSig;

// Check that the same work is not submitted twice to our chain.
//

CScript::const_iterator pcHead =
std::search(script.begin(), script.end(), UBEGIN(pchMergedMiningHeader), UEND(pchMergedMiningHeader));

CScript::const_iterator pc =
std::search(script.begin(), script.end(), vchRootHash.begin(), vchRootHash.end());

if (pc == script.end())
return error("Aux POW missing chain merkle root in parent coinbase");

if (pcHead != script.end())
{
// Enforce only one chain merkle root by checking that a single instance of the merged
// mining header exists just before.
if (script.end() != std::search(pcHead + 1, script.end(), UBEGIN(pchMergedMiningHeader), UEND(pchMergedMiningHeader)))
return error("Multiple merged mining headers in coinbase");
if (pcHead + sizeof(pchMergedMiningHeader) != pc)
return error("Merged mining header is not just before chain merkle root");
}
else
{
// For backward compatibility.
// Enforce only one chain merkle root by checking that it starts early in the coinbase.
// 8-12 bytes are enough to encode extraNonce and nBits.
if (pc - script.begin() > 20)
return error("Aux POW chain merkle root must start in the first 20 bytes of the parent coinbase");
}


// Ensure we are at a deterministic point in the merkle leaves by hashing
// a nonce and our chain ID and comparing to the index.
pc += vchRootHash.size();
if (script.end() - pc < 8)
return error("Aux POW missing chain merkle tree size and nonce in parent coinbase");

int nSize;
memcpy(&nSize, &pc[0], 4);
if (nSize != (1 << vChainMerkleBranch.size()))
return error("Aux POW merkle branch size does not match parent coinbase");

int nNonce;
memcpy(&nNonce, &pc[4], 4);

// Choose a pseudo-random slot in the chain merkle tree
// but have it be fixed for a size/nonce/chain combination.
//
// This prevents the same work from being used twice for the
// same chain while reducing the chance that two chains clash
// for the same slot.
int rand = nNonce;
rand = rand * 1103515245 + 12345;
rand += nChainID;
rand = rand * 1103515245 + 12345;

if (nChainIndex != (rand % nSize))
return error("Aux POW wrong index");

return true;
}

CScript MakeCoinbaseWithAux(unsigned int nHeight, unsigned int nExtraNonce,
vector<unsigned char>& vchAux) {
vector<unsigned char> vchAuxWithHeader(UBEGIN(pchMergedMiningHeader), UEND(pchMergedMiningHeader));
vchAuxWithHeader.insert(vchAuxWithHeader.end(), vchAux.begin(), vchAux.end());

// Push OP_2 just in case we want versioning later
/* BIP34: v2 coin base must start with nHeight */
return(((CScript() << nHeight << CBigNum(nExtraNonce)) + COINBASE_FLAGS) << OP_2 << vchAuxWithHeader);
}


void IncrementExtraNonceWithAux(CBlock* pblock, CBlockIndex* pindexPrev,
unsigned int& nExtraNonce, vector<unsigned char>& vchAux) {

// Update nExtraNonce
static uint256 hashPrevBlock;
if (hashPrevBlock != pblock->hashPrevBlock)
{
nExtraNonce = 0;
hashPrevBlock = pblock->hashPrevBlock;
}
++nExtraNonce;

pblock->vtx[0].vin[0].scriptSig = MakeCoinbaseWithAux(pindexPrev->nHeight + 1, nExtraNonce, vchAux);
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
}
86 changes: 86 additions & 0 deletions src/auxpow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_AUXPOW_H
#define BITCOIN_AUXPOW_H

#include "main.h"

class CAuxPow : public CMerkleTx
{
public:
CAuxPow(const CTransaction& txIn) : CMerkleTx(txIn)
{
}

CAuxPow() :CMerkleTx()
{
}

// Merkle branch with root vchAux
// root must be present inside the coinbase
std::vector<uint256> vChainMerkleBranch;
// Index of chain in chains merkle tree
int nChainIndex;
CBlock parentBlock;

IMPLEMENT_SERIALIZE
(
nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion, ser_action);
nVersion = this->nVersion;
READWRITE(vChainMerkleBranch);
READWRITE(nChainIndex);

// Always serialize the saved parent block as header so that the size of CAuxPow
// is consistent.
nSerSize += SerReadWrite(s, parentBlock, nType | SER_BLOCKHEADERONLY, nVersion, ser_action);
)

bool Check(uint256 hashAuxBlock, int nChainID);

uint256 GetParentBlockHash() {
return(parentBlock.GetHashGroestl());
}
};

template <typename Stream>
int ReadWriteAuxPow(Stream& s, const boost::shared_ptr<CAuxPow>& auxpow, int nType, int nVersion, CSerActionGetSerializeSize ser_action)
{
if (nVersion & BLOCK_VERSION_AUXPOW)
{
return ::GetSerializeSize(*auxpow, nType, nVersion);
}
return 0;
}

template <typename Stream>
int ReadWriteAuxPow(Stream& s, const boost::shared_ptr<CAuxPow>& auxpow, int nType, int nVersion, CSerActionSerialize ser_action)
{
if (nVersion & BLOCK_VERSION_AUXPOW)
{
return SerReadWrite(s, *auxpow, nType, nVersion, ser_action);
}
return 0;
}

template <typename Stream>
int ReadWriteAuxPow(Stream& s, boost::shared_ptr<CAuxPow>& auxpow, int nType, int nVersion, CSerActionUnserialize ser_action)
{
if (nVersion & BLOCK_VERSION_AUXPOW)
{
auxpow.reset(new CAuxPow());
return SerReadWrite(s, *auxpow, nType, nVersion, ser_action);
}
else
{
auxpow.reset();
return 0;
}
}

extern void RemoveMergedMiningHeader(std::vector<unsigned char>& vchAux);
extern void IncrementExtraNonceWithAux(CBlock* pblock, CBlockIndex* pindexPrev,
unsigned int& nExtraNonce, std::vector<unsigned char>& vchAux);
extern CScript MakeCoinbaseWithAux(unsigned int nBits, unsigned int nExtraNonce,
std::vector<unsigned char>& vchAux);
#endif
24 changes: 15 additions & 9 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ static const CRPCCommand vRPCCommands[] =
{ "signmessage", &signmessage, false, false },
{ "verifymessage", &verifymessage, false, false },
{ "getwork", &getwork, true, false },
{ "getworkex", &getworkex, true, false },
{ "getworkaux", &getworkaux, true, false },
{ "listaccounts", &listaccounts, false, false },
{ "settxfee", &settxfee, false, false },
{ "getblocktemplate", &getblocktemplate, true, false },
{ "getauxblock", &getauxblock, true, false },
{ "submitblock", &submitblock, false, false },
{ "listsinceblock", &listsinceblock, false, false },
{ "dumpprivkey", &dumpprivkey, false, false },
Expand All @@ -262,14 +263,19 @@ static const CRPCCommand vRPCCommands[] =
{ "signrawtransaction", &signrawtransaction, false, false },
{ "sendrawtransaction", &sendrawtransaction, false, false },
{ "getcheckpoint", &getcheckpoint, true, false },
{ "reservebalance", &reservebalance, false, true},
{ "checkwallet", &checkwallet, false, true},
{ "repairwallet", &repairwallet, false, true},
{ "resendtx", &resendtx, false, true},
{ "makekeypair", &makekeypair, false, true},
{ "sendalert", &sendalert, false, false},
{ "setchangeaddress", &setchangeaddress, true, false },
{ "getchangeaddress", &getchangeaddress, true, false },
{ "reservebalance", &reservebalance, false, true },
{ "checkwallet", &checkwallet, false, true },
{ "repairwallet", &repairwallet, false, true },
{ "resendtx", &resendtx, false, true },
{ "makekeypair", &makekeypair, false, true },
{ "sendalert", &sendalert, false, false },
{ "setchangeaddress", &setchangeaddress, true, false },
{ "getchangeaddress", &getchangeaddress, true, false },
{ "getscrapeaddress", &getscrapeaddress, true, false },
{ "listscrapeaddresses", &listscrapeaddresses, true, false },
{ "setscrapeaddress", &setscrapeaddress, true, true },
{ "deletescrapeaddress", &deletescrapeaddress, true, true },
{ "listreactordata", &listreactordata, true, false }
};

CRPCTable::CRPCTable()
Expand Down
12 changes: 11 additions & 1 deletion src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ int CommandLineRPC(int argc, char *argv[]);
/** Convert parameter values for RPC call from strings to command-specific JSON objects. */
json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams);

/** Call the RPC service directly (placed here to allow for more in depth tests). */
json_spirit::Object CallRPC(const std::string &strMethod, const json_spirit::Array &params);

/*
Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
the right number of arguments are passed, just that any passed are the correct type.
Expand Down Expand Up @@ -146,9 +149,10 @@ extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHe
extern json_spirit::Value gethashespersec(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getworkex(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getworkaux(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getauxblock(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp);
Expand Down Expand Up @@ -188,6 +192,7 @@ extern json_spirit::Value makekeypair(const json_spirit::Array& params, bool fHe
extern json_spirit::Value validatepubkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnewpubkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listreactordata(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
Expand All @@ -207,4 +212,9 @@ extern json_spirit::Value getcheckpoint(const json_spirit::Array& params, bool f
extern json_spirit::Value setchangeaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getchangeaddress(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value setscrapeaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getscrapeaddress(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value listscrapeaddresses(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value deletescrapeaddress(const json_spirit::Array& params, bool fHelp);

#endif
6 changes: 3 additions & 3 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Checkpoints
(443923, uint256("0x0000000001f9b10759fa67418e4c20a772ec39c3eff33742cb5899c7b50d7348"))
(468356, uint256("0x000000000543a19eaf97aa0ad933cb6423dedacb09786f4891126ac02bd8b7d4"))
(895493, uint256("0x0000000003140f322a3913d0d67b77b462b0bcdd2a4a0ec0cd791de743cf9202"))

(1500000, uint256("0x0000000008040b20b2e7ebdea7cf0c57d43195ec1da886b652339cb87253f369"))
;

static MapCheckpoints mapCheckpointsTestnet =
Expand Down Expand Up @@ -362,8 +362,8 @@ namespace Checkpoints
// sync-checkpoint should always be accepted block
assert(mapBlockIndex.count(hashSyncCheckpoint));
const CBlockIndex* pindexSync = mapBlockIndex[hashSyncCheckpoint];
return (nBestHeight >= pindexSync->nHeight + nCoinbaseMaturity ||
pindexSync->GetBlockTime() + nStakeMinAge < GetAdjustedTime());
return((nBestHeight >= pindexSync->nHeight + nCoinbaseMaturity) ||
(pindexSync->GetBlockTime() + nStakeMinAgeFixed < GetAdjustedTime()));
}

// Is the sync-checkpoint too old?
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CSyncCheckpoint : public CUnsignedSyncCheckpoint

uint256 GetHash() const
{
return SerializeHash(*this);
return(SerializeHash2(*this));
}

bool RelayTo(CNode* pnode) const
Expand Down
6 changes: 3 additions & 3 deletions src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

// These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 5
#define CLIENT_VERSION_BUILD 7
#define CLIENT_VERSION_MINOR 1
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 1

// Converts the parameter X to a string after macro replacement on X has been performed.
// Don't merge these into one macro!
Expand Down
Loading

0 comments on commit d1a86ed

Please sign in to comment.