fixed platform issues with calcscore / better re-converge after fork

This commit is contained in:
Evan Duffield 2015-02-07 10:30:16 -07:00
parent 3a72da77ac
commit 3a263ed1bf
6 changed files with 18 additions and 52 deletions

View File

@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 11)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 13)
define(_CLIENT_VERSION_BUILD, 14)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2015)
AC_INIT([Darkcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@darkcoin.io],[darkcoin])

View File

@ -12,7 +12,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 11
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 13
#define CLIENT_VERSION_BUILD 14

View File

@ -35,7 +35,7 @@ int nCompleteTXLocks;
void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv)
{
if(fLiteMode) return; //disable all darksend/masternode related functionality
if(fLargeWorkForkFound || fLargeWorkInvalidChainFound) return;
if(fManyOrphansFound) return;
if (strCommand == "txlreq")
{

View File

@ -66,6 +66,7 @@ struct COrphanBlock {
};
map<uint256, COrphanBlock*> mapOrphanBlocks;
multimap<uint256, COrphanBlock*> mapOrphanBlocksByPrev;
bool fManyOrphansFound;
struct COrphanTx {
CTransaction tx;
@ -1172,7 +1173,7 @@ int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const
int CMerkleTx::GetTransactionLockSignatures() const
{
if(fLargeWorkForkFound || fLargeWorkInvalidChainFound) return -2;
if(fManyOrphansFound) return -2;
if(nInstantXDepth == 0) return -1;
//compile consessus vote
@ -2825,7 +2826,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
// ----------- instantX transaction scanning -----------
if(!fLargeWorkForkFound && !fLargeWorkInvalidChainFound){
if(!fManyOrphansFound){
BOOST_FOREACH(const CTransaction& tx, block.vtx){
if (!tx.IsCoinBase()){
//only reject blocks when it's based on complete consensus
@ -2853,7 +2854,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
}
if(MasternodePayments && !fLargeWorkForkFound && !fLargeWorkInvalidChainFound)
if(MasternodePayments && !fManyOrphansFound)
{
LOCK2(cs_main, mempool.cs);
@ -3171,6 +3172,8 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl
return true;
}
fManyOrphansFound = (unsigned long)mapOrphanBlocks.size() >= 6;
// Store to disk
if (!AcceptBlock(*pblock, state, dbp))
return error("ProcessBlock() : AcceptBlock FAILED");

View File

@ -108,9 +108,7 @@ extern int nScriptCheckThreads;
extern bool fTxIndex;
extern unsigned int nCoinCacheSize;
extern bool fLargeWorkForkFound;
extern bool fLargeWorkInvalidChainFound;
extern bool fManyOrphansFound;
// Minimum disk space required - used in CheckDiskSpace()
static const uint64_t nMinDiskSpace = 52428800;

View File

@ -481,8 +481,9 @@ int GetMasternodeRank(CTxIn& vin, int64_t nBlockHeight, int minProtocol)
{
std::vector<pair<unsigned int, CTxIn> > vecMasternodeScores;
BOOST_FOREACH(CMasterNode mn, vecMasternodes) {
BOOST_FOREACH(CMasterNode& mn, vecMasternodes) {
mn.Check();
if(mn.protocolVersion < minProtocol) continue;
if(!mn.IsEnabled()) {
continue;
@ -500,7 +501,9 @@ int GetMasternodeRank(CTxIn& vin, int64_t nBlockHeight, int minProtocol)
unsigned int rank = 0;
BOOST_FOREACH (PAIRTYPE(unsigned int, CTxIn)& s, vecMasternodeScores){
rank++;
if(s.second == vin) return rank;
if(s.second == vin) {
return rank;
}
}
return -1;
@ -553,49 +556,11 @@ uint256 CMasterNode::CalculateScore(int mod, int64_t nBlockHeight)
uint256 aux = vin.prevout.hash;
if(!GetBlockHash(hash, nBlockHeight)) return 0;
uint256 hash2 = HashX11(BEGIN(hash), END(hash));
uint256 hash3 = HashX11(BEGIN(hash), END(aux));
uint256 hash2 = Hash(BEGIN(hash), END(hash));
uint256 hash3 = Hash(BEGIN(hash), END(aux));
// we'll make a 4 dimensional point in space
// the closest masternode to that point wins
uint64_t a1 = hash2.Get64(0);
uint64_t a2 = hash2.Get64(1);
uint64_t a3 = hash2.Get64(2);
uint64_t a4 = hash2.Get64(3);
return (hash3 - hash2 ? hash3 - hash2 : hash2 - hash3);
//copy part of our source hash
int i1, i2, i3, i4;
i1=0;i2=0;i3=0;i4=0;
memcpy(&i1, &a1, 1);
memcpy(&i2, &a2, 1);
memcpy(&i3, &a3, 1);
memcpy(&i4, &a4, 1);
//split up our mn-hash+aux into 4
uint64_t b1 = hash3.Get64(0);
uint64_t b2 = hash3.Get64(1);
uint64_t b3 = hash3.Get64(2);
uint64_t b4 = hash3.Get64(3);
//move mn hash around
b1 <<= (i1 % 64);
b2 <<= (i2 % 64);
b3 <<= (i3 % 64);
b4 <<= (i4 % 64);
// calculate distance between target point and mn point
uint256 r = 0;
r += (a1 > b1 ? a1 - b1 : b1 - a1);
r += (a2 > b2 ? a2 - b2 : b2 - a2);
r += (a3 > b3 ? a3 - b3 : b3 - a3);
r += (a4 > b4 ? a4 - b4 : b4 - a4);
/*
LogPrintf(" -- MasterNode CalculateScore() n2 = %s \n", n2.ToString().c_str());
LogPrintf(" -- MasterNode CalculateScore() vin = %s \n", vin.prevout.hash.GetHex().c_str());
LogPrintf(" -- MasterNode CalculateScore() n3 = %s \n", n3.ToString().c_str());*/
return r;
}
void CMasterNode::Check()