Skip to content

Commit

Permalink
Merge pull request #25 from bitgreen/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
konez2k committed May 10, 2020
2 parents 93fdb81 + 03e384c commit 5168cb2
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 303 deletions.
4 changes: 2 additions & 2 deletions configure.ac
@@ -1,9 +1,9 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 4)
define(_CLIENT_VERSION_MINOR, 5)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 9)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2020)
Expand Down
23 changes: 14 additions & 9 deletions src/chainparams.cpp
Expand Up @@ -254,10 +254,15 @@ class CMainParams : public CChainParams

checkpointData = {
{
{ 1, uint256S("0x0000062cf9ac97b1582474e313770e4609c338ed6fae01142da65722353465f3")},
{ 100, uint256S("0x000005faf4d7d9dccd3a1986eb7150a22f21f80664d5deb91cb1ca38eb305e7e")},
{ 6439, uint256S("0x7c6f9621fe18f22e57d042a3804be45a9ace2d17a305036242d7ba90b68345cb")},
{ 70004, uint256S("0x2da7cf773e5032a76aa4480b033c1ac6978ff64531f168c92d022c90f5bf7996")}
{ 1, uint256S("0x0000062cf9ac97b1582474e313770e4609c338ed6fae01142da65722353465f3")},
{ 100, uint256S("0x000005faf4d7d9dccd3a1986eb7150a22f21f80664d5deb91cb1ca38eb305e7e")},
{ 6439, uint256S("0x7c6f9621fe18f22e57d042a3804be45a9ace2d17a305036242d7ba90b68345cb")},
{ 70004, uint256S("0x2da7cf773e5032a76aa4480b033c1ac6978ff64531f168c92d022c90f5bf7996")},
{ 80000, uint256S("0x1f6545f0cd4a07a02a5b0175f22b371fc1839839df8d835c04f6420a08d43877")},
{ 90000, uint256S("0x1d4a1b059b96fa871e9aa09eca0e2ed18ef369556ef8ee88bacf3b3705812e26")},
{ 100000, uint256S("0x8a58bc2b0d6b13229f4ec1d9733317a82e62dbc035e09384ee9e73b77a3e3c76")},
{ 105000, uint256S("0xa9e075e368ebc428c223055d4c3db108106098237dc9f55af687f56781c4d932")},
{ 110000, uint256S("0xfc62dddbd615c0c5d34fc24cb4f6d6b86f02465c036ac42d1bda585e1ac3d066")}
}};

chainTxData = ChainTxData{
Expand Down Expand Up @@ -291,7 +296,7 @@ class CTestNetParams : public CChainParams
consensus.fPowNoRetargeting = false;
consensus.nPosTargetSpacing = 2 * 60; // PoS: 2 minutes
consensus.nPosTargetTimespan = 60 * 40;
consensus.nStakeMinAge = 60 * 10; // 10 minutes
consensus.nStakeMinAge = 60 * 1; // 1 minute
consensus.nStakeMaxAge = 60 * 60; // 1 hour
consensus.nModifierInterval = 60; // Modifier interval: time to elapse before new modifier is computed (1 minute)
consensus.nLastPoWBlock = 200;
Expand All @@ -300,9 +305,9 @@ class CTestNetParams : public CChainParams
consensus.nMasternodeMinimumConfirmations = 1;

// Stake constants
consensus.nStakeEnforcement = 60000;
consensus.nMinStakeAmount = 150 * COIN;
consensus.nMinStakeHistory = 600;
consensus.nStakeEnforcement = 200;
consensus.nMinStakeAmount = 1 * COIN;
consensus.nMinStakeHistory = 10;

// Governance
consensus.nSuperblockCycle = 24; // Superblocks can be issued hourly on testnet
Expand Down Expand Up @@ -380,7 +385,7 @@ class CTestNetParams : public CChainParams
fAllowMultiplePorts = false;
nFulfilledRequestExpireTime = 5 * 60; // fulfilled requests expire in 5 minutes

vSporkAddresses = {"GMWbuDW6m6WCc7Zc9W3CSuviXzqPKK3eBj"};
vSporkAddresses = {"gprpehZBigGDp7sNMjEKY46afAd9BWtd29"};
nMinSporkKeys = 1;

checkpointData = {
Expand Down
49 changes: 23 additions & 26 deletions src/governance/governance-classes.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 The Dash Core developers
// Copyright (c) 2014-2019 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -143,7 +143,7 @@ void CGovernanceTriggerManager::CleanAndRemove()
CGovernanceObject* pObj = nullptr;
CSuperblock_sptr& pSuperblock = it->second;
if (!pSuperblock) {
LogPrint(BCLog::GOBJECT, "CGovernanceTriggerManager::CleanAndRemove -- NULL superblock marked for removal\n");
LogPrint(BCLog::GOBJECT, "CGovernanceTriggerManager::CleanAndRemove -- nullptr superblock\n");
remove = true;
} else {
pObj = governance.FindGovernanceObject(it->first);
Expand All @@ -160,28 +160,29 @@ void CGovernanceTriggerManager::CleanAndRemove()
remove = true;
break;
case SEEN_OBJECT_IS_VALID:
case SEEN_OBJECT_EXECUTED:
remove = pSuperblock->IsExpired();
case SEEN_OBJECT_EXECUTED: {
LogPrint(BCLog::GOBJECT, "CGovernanceTriggerManager::CleanAndRemove -- Valid trigger found\n");
if (pSuperblock->IsExpired()) {
// update corresponding object
pObj->SetExpired();
remove = true;
}
break;
}
default:
break;
}
}
LogPrint(BCLog::GOBJECT, "CGovernanceTriggerManager::CleanAndRemove -- %smarked for removal\n", remove ? "" : "NOT ");

if (remove) {
std::string strDataAsPlainString = "NULL";
std::string strDataAsPlainString = "nullptr";
if (pObj) {
strDataAsPlainString = pObj->GetDataAsPlainString();
// mark corresponding object for deletion
pObj->PrepareDeletion(GetAdjustedTime());
}
LogPrint(BCLog::GOBJECT, "CGovernanceTriggerManager::CleanAndRemove -- Removing trigger object %s\n", strDataAsPlainString);
// mark corresponding object for deletion
if (pObj) {
pObj->fCachedDelete = true;
if (pObj->nDeletionTime == 0) {
pObj->nDeletionTime = GetAdjustedTime();
}
}
// delete the trigger
mapTrigger.erase(it++);
} else {
Expand Down Expand Up @@ -601,7 +602,9 @@ bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount b
}

// miner and masternodes should not get more than they would usually get
CAmount nBlockValue = txNew.GetValueOut();
CCoinsViewCache view(pcoinsTip.get());
CAmount nValueIn = view.GetValueIn(txNew);
CAmount nBlockValue = txNew.GetValueOut() - nValueIn;
if (nBlockValue > blockReward + nPaymentsTotalAmount) {
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, block value limit exceeded: block %lld, limit %lld\n", nBlockValue, blockReward + nPaymentsTotalAmount);
return false;
Expand Down Expand Up @@ -643,9 +646,8 @@ bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount b
return true;
}

bool CSuperblock::IsExpired()
bool CSuperblock::IsExpired() const
{
bool fExpired{false};
int nExpirationBlocks{0};
// Executed triggers are kept for another superblock cycle (approximately 1 month),
// other valid triggers are kept for ~1 day only, everything else is pruned after ~1h.
Expand All @@ -667,16 +669,10 @@ bool CSuperblock::IsExpired()

if (governance.GetCachedBlockHeight() > nExpirationBlock) {
LogPrint(BCLog::GOBJECT, "CSuperblock::IsExpired -- Outdated trigger found\n");
fExpired = true;
CGovernanceObject* pgovobj = GetGovernanceObject();
if (pgovobj) {
LogPrint(BCLog::GOBJECT, "CSuperblock::IsExpired -- Expiring outdated object: %s\n", pgovobj->GetHash().ToString());
pgovobj->fExpired = true;
pgovobj->nDeletionTime = GetAdjustedTime();
}
return true;
}

return fExpired;
return false;
}

/**
Expand Down Expand Up @@ -707,13 +703,14 @@ std::string CSuperblockManager::GetRequiredPaymentsString(int nBlockHeight)

CTxDestination address1;
ExtractDestination(payment.script, address1);
std::string address2 = EncodeDestination(address1);

// RETURN NICE OUTPUT FOR CONSOLE

if(ret != "Unknown") {
ret += ", " + EncodeDestination(address1);
if (ret != "Unknown") {
ret += ", " + address2;
} else {
ret = EncodeDestination(address1);
ret = address2;
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/governance/governance-classes.h
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 The Dash Core developers
// Copyright (c) 2014-2020 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_CLASSES_H
Expand Down Expand Up @@ -151,8 +151,6 @@ class CSuperblock : public CGovernanceObject
int GetStatus() { return nStatus; }
void SetStatus(int nStatusIn) { nStatus = nStatusIn; }

// IS THIS TRIGGER ALREADY EXECUTED?
bool IsExecuted() { return nStatus == SEEN_OBJECT_EXECUTED; }
// TELL THE ENGINE WE EXECUTED THIS EVENT
void SetExecuted() { nStatus = SEEN_OBJECT_EXECUTED; }

Expand All @@ -173,7 +171,7 @@ class CSuperblock : public CGovernanceObject
CAmount GetPaymentsTotalAmount();

bool IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
bool IsExpired();
bool IsExpired() const;
};

#endif
2 changes: 1 addition & 1 deletion src/governance/governance-exceptions.h
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2018 The Dash Core developers
// Copyright (c) 2014-2019 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down
63 changes: 5 additions & 58 deletions src/governance/governance-object.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2014-2019 The Dash Core developers
// Copyright (c) 2014-2020 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -39,7 +39,6 @@ CGovernanceObject::CGovernanceObject() :
fExpired(false),
fUnparsable(false),
mapCurrentMNVotes(),
cmmapOrphanVotes(),
fileVotes()
{
// PARSE JSON DATA STORAGE (VCHDATA)
Expand Down Expand Up @@ -67,7 +66,6 @@ CGovernanceObject::CGovernanceObject(const uint256& nHashParentIn, int nRevision
fExpired(false),
fUnparsable(false),
mapCurrentMNVotes(),
cmmapOrphanVotes(),
fileVotes()
{
// PARSE JSON DATA STORAGE (VCHDATA)
Expand Down Expand Up @@ -95,7 +93,6 @@ CGovernanceObject::CGovernanceObject(const CGovernanceObject& other) :
fExpired(other.fExpired),
fUnparsable(other.fUnparsable),
mapCurrentMNVotes(other.mapCurrentMNVotes),
cmmapOrphanVotes(other.cmmapOrphanVotes),
fileVotes(other.fileVotes)
{
}
Expand Down Expand Up @@ -123,12 +120,7 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
if (!dmn) {
std::ostringstream ostr;
ostr << "CGovernanceObject::ProcessVote -- Masternode " << vote.GetMasternodeOutpoint().ToStringShort() << " not found";
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
if (cmmapOrphanVotes.Insert(vote.GetMasternodeOutpoint(), vote_time_pair_t(vote, GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME))) {
LogPrintf("%s\n", ostr.str());
} else {
LogPrint(BCLog::GOBJECT, "%s\n", ostr.str());
}
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_PERMANENT_ERROR, 20);
return false;
}

Expand Down Expand Up @@ -235,6 +227,7 @@ void CGovernanceObject::ClearMasternodeVotes()
if (!mnList.HasMNByCollateral(it->first)) {
fileVotes.RemoveVotesFromMasternode(it->first);
mapCurrentMNVotes.erase(it++);
fDirtyCache = true;
} else {
++it;
}
Expand Down Expand Up @@ -282,19 +275,6 @@ std::set<uint256> CGovernanceObject::RemoveInvalidVotes(const COutPoint& mnOutpo
return removedVotes;
}

std::string CGovernanceObject::GetSignatureMessage() const
{
LOCK(cs);
std::string strMessage = nHashParent.ToString() + "|" +
std::to_string(nRevision) + "|" +
std::to_string(nTime) + "|" +
GetDataAsHexString() + "|" +
masternodeOutpoint.ToStringShort() + "|" +
nCollateralHash.ToString();

return strMessage;
}

uint256 CGovernanceObject::GetHash() const
{
// Note: doesn't match serialization
Expand Down Expand Up @@ -449,15 +429,13 @@ void CGovernanceObject::UpdateLocalValidity()

bool CGovernanceObject::IsValidLocally(std::string& strError, bool fCheckCollateral) const
{
bool fMissingMasternode = false;
bool fMissingConfirmations = false;

return IsValidLocally(strError, fMissingMasternode, fMissingConfirmations, fCheckCollateral);
return IsValidLocally(strError, fMissingConfirmations, fCheckCollateral);
}

bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMasternode, bool& fMissingConfirmations, bool fCheckCollateral) const
bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingConfirmations, bool fCheckCollateral) const
{
fMissingMasternode = false;
fMissingConfirmations = false;

if (fUnparsable) {
Expand Down Expand Up @@ -714,34 +692,3 @@ void CGovernanceObject::UpdateSentinelVariables()

if (GetAbsoluteNoCount(VOTE_SIGNAL_VALID) >= nAbsVoteReq) fCachedValid = false;
}

void CGovernanceObject::CheckOrphanVotes(CConnman& connman)
{
int64_t nNow = GetAdjustedTime();
auto mnList = deterministicMNManager->GetListAtChainTip();
const vote_cmm_t::list_t& listVotes = cmmapOrphanVotes.GetItemList();
vote_cmm_t::list_cit it = listVotes.begin();
while (it != listVotes.end()) {
bool fRemove = false;
const COutPoint& key = it->key;
const vote_time_pair_t& pairVote = it->value;
const CGovernanceVote& vote = pairVote.first;
if (pairVote.second < nNow) {
fRemove = true;
} else if (!mnList.HasValidMNByCollateral(vote.GetMasternodeOutpoint())) {
++it;
continue;
}
CGovernanceException exception;
if (!ProcessVote(nullptr, vote, exception, connman)) {
LogPrintf("CGovernanceObject::CheckOrphanVotes -- Failed to add orphan vote: %s\n", exception.what());
} else {
vote.Relay(connman);
fRemove = true;
}
++it;
if (fRemove) {
cmmapOrphanVotes.Erase(key, pairVote);
}
}
}

0 comments on commit 5168cb2

Please sign in to comment.