Skip to content

Commit

Permalink
Merge pull request #13 from mitchelvanamstel/master
Browse files Browse the repository at this point in the history
EcoFund
  • Loading branch information
mitchelvanamstel committed Jun 15, 2020
2 parents 4e1fab0 + a44570e commit 94d7e21
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 20 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 3)
define(_CLIENT_VERSION_REVISION, 3)
define(_CLIENT_VERSION_REVISION, 4)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
Expand Down
23 changes: 20 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "random.h"
#include "util.h"
#include "utilstrencodings.h"
#include "net.h"
#include "base58.h"

#include <assert.h>

Expand Down Expand Up @@ -74,11 +76,13 @@ static Checkpoints::MapCheckpoints mapCheckpoints =
(640000, uint256("2fb2e3e813f9bc8174bb8a8f33c7f9aa9f4cd07ed10e0a4f0196cb0424de023a"))
(650000, uint256("bd91d1b3dba223689f5f686116a37cf3d69c9837b912ae1c4b5b044757cd9f3b"))
(655000, uint256("5ec3dd7f9be42c797f49f36f62d93856c9e846fde3a665f1a024fbea6ffaf42f"))
(658844, uint256("fef6a0f575e75ebcd2d5c8f240c08ab2cc04bb00de86c0decda4d0bc917af69e"));
(658844, uint256("fef6a0f575e75ebcd2d5c8f240c08ab2cc04bb00de86c0decda4d0bc917af69e"))
(700000, uint256("8885a6b4892b87c3cbdd0c72c05f9037f8014b5cdf31e1cd2a3c3ec34d71b770"))
(771563, uint256("1286cad5681baf74750848cc35cfc0608a651d4a26bdb7fbc366ababaf6fb948"));
static const Checkpoints::CCheckpointData data = {
&mapCheckpoints,
1586972314, // * UNIX timestamp of last checkpoint block
1703357, // * total number of transactions between genesis and last checkpoint
1592216145, // * UNIX timestamp of last checkpoint block
1945714, // * total number of transactions between genesis and last checkpoint
// (the tx=... number in the SetBestChain debug.log lines)
2000 // * estimated number of transactions per day after checkpoint
};
Expand Down Expand Up @@ -149,6 +153,18 @@ bool CChainParams::IsValidBlockTimeStamp(const int64_t nTime, const int nHeight)
return (nTime % TimeSlotLength()) == 0;
}

std::string CChainParams::GetEcoFundAddressAtHeight(int nHeight) const {
return vEcoFundAddress;
}

CScript CChainParams::GetEcoFundScriptAtHeight(int nHeight) const {
CBitcoinAddress address(GetEcoFundAddressAtHeight(nHeight).c_str());
assert(address.IsValid());

CScript script = GetScriptForDestination(address.Get());
return script;
}

class CMainParams : public CChainParams
{
public:
Expand Down Expand Up @@ -188,6 +204,7 @@ class CMainParams : public CChainParams
nMasternodeCountDrift = 20;
nMaxMoneyOut = 23000000 * COIN;
nMinColdStakingAmount = 1 * COIN;
vEcoFundAddress = "KJbUDa4JHKo59UWTfzKJFAVCsSVnrP8t8j";

/** Height or Time Based Activations **/
nLastPOWBlock = 2880;
Expand Down
5 changes: 5 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class CChainParams
int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; }
int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; }
bool IsStakeModifierV2(const int nHeight) const { return nHeight >= nBlockStakeModifierlV2; }

std::string GetEcoFundAddressAtHeight(int height) const;
CScript GetEcoFundScriptAtHeight(int height) const;

int NewSigsActive(const int nHeight) const { return nHeight >= nBlockEnforceNewMessageSignatures; }
int BIP65ActivationHeight() const { return nBIP65ActivationHeight; }
int Block_V7_StartHeight() const { return nBlockV7StartHeight; }
Expand Down Expand Up @@ -200,6 +204,7 @@ class CChainParams
std::vector<CDNSSeedData> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
CBaseChainParams::Network networkID;
std::string vEcoFundAddress;
std::string strNetworkID;
CBlock genesis;
std::vector<CAddress> vFixedSeeds;
Expand Down
51 changes: 46 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,20 @@ double ConvertBitsToDouble(unsigned int nBits)
return dDiff;
}

int nStartEcoFundBlock = 800001;
int nEcoFundBlockStep = 1440;

bool IsEcoFundBlock(int nHeight)
{
if(nHeight < nStartEcoFundBlock)
return false;
else if( (nHeight-nStartEcoFundBlock) % nEcoFundBlockStep == 0)
return true;
else
return false;
}


int64_t GetBlockValue(int nHeight)
{
if (Params().NetworkID() == CBaseChainParams::TESTNET) {
Expand Down Expand Up @@ -2065,6 +2079,17 @@ int64_t GetBlockValue(int nHeight)
nSubsidy = 1* COIN;
}

if(nHeight >= 800001 && !IsEcoFundBlock(nHeight)) {
// Ecofund starts from here, and are
// paid once a day, so we lower the rewards
nSubsidy = (nSubsidy / 100) * 80;
}

if(IsEcoFundBlock(nHeight)) {
LogPrintf("GetBlockValue(): this is a ecofund block\n");
nSubsidy = ((nSubsidy * 1440) / 100) * 20;
}

return nSubsidy;
}

Expand Down Expand Up @@ -2316,7 +2341,11 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCou
if (nHeight <= 2880) {
ret = blockValue / 100 * 0;
} else if (nHeight > 2880) {
ret = blockValue / 100 * 80; //80%
if(nHeight >= 800001) {
ret = blockValue / 100 * 75; //75%
} else {
ret = blockValue / 100 * 80; //80%
}
}

return ret;
Expand Down Expand Up @@ -2575,6 +2604,18 @@ CAmount GetInvalidUTXOValue()

bool CheckInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, bool fScriptChecks, unsigned int flags, bool cacheStore, std::vector<CScriptCheck>* pvChecks)
{
// Check inputs for the hacked coins from Simple Pos Pool / SPP - These will be locked
for(const auto& txin:tx.vin) {
if(
txin.prevout.hash == uint256("0x4b40bded95dfb0ae3b9848d783e00a3c23731feccec374c918c3ea7d0c1bfeb8") ||
txin.prevout.hash == uint256("4b40bded95dfb0ae3b9848d783e00a3c23731feccec374c918c3ea7d0c1bfeb8") ||
txin.prevout.hash == uint256("0x6fc9ca0680660825b0c626d25744660edd6e3172edd5064aea724d0a35fdabb4") ||
txin.prevout.hash == uint256("6fc9ca0680660825b0c626d25744660edd6e3172edd5064aea724d0a35fdabb4")
) {
int nHeight = chainActive.Height();
return state.DoS(100, error("CheckInputs() : Input %s vout 0 hacked from Simple Pos Pool and blocked at height %d (frozen).\n",tx.GetHash().ToString(),nHeight,REJECT_INVALID, "bad-input"));
}
}
if (!tx.IsCoinBase() && !tx.HasZerocoinSpendInputs()) {
if (pvChecks)
pvChecks->reserve(tx.vin.size());
Expand Down Expand Up @@ -7194,12 +7235,12 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR
int ActiveProtocol()
{
// SPORK_14 was used for 70917 (v3.4), commented out now.
if (sporkManager.IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT))
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
//if (sporkManager.IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT))
// return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;

// SPORK_15 is used for 70918 (v4.0+)
//if (sporkManager.IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2))
// return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
if (sporkManager.IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2))
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;

return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
}
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
bool ActivateBestChain(CValidationState& state, CBlock* pblock = NULL, bool fAlreadyChecked = false);
CAmount GetBlockValue(int nHeight);

bool IsEcoFundBlock(int nHeight);
/** Create a new block index entry for a given block hash */
CBlockIndex* InsertBlockIndex(uint256 hash);
/** Abort with a message */
Expand Down
44 changes: 44 additions & 0 deletions src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,50 @@ void CBudgetManager::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, b
}
}

void CBudgetManager::FillEcoFundBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStake)
{
CBlockIndex* pindexPrev = chainActive.Tip();
if (!pindexPrev) return;

CScript payee;

CAmount blockValue = GetBlockValue(pindexPrev->nHeight);
payee = Params().GetEcoFundScriptAtHeight(pindexPrev->nHeight);
CAmount ecoFundPayment = blockValue - 2 * COIN;


if (fProofOfStake) {
/**For Proof Of Stake vout[0] must be null
* Stake reward can be split into many different outputs, so we must
* use vout.size() to align with several different cases.
* An additional output is appended as the masternode payment
*/
unsigned int i = txNew.vout.size();
txNew.vout.resize(i + 1);
txNew.vout[i].scriptPubKey = payee;
txNew.vout[i].nValue = ecoFundPayment;

if (txNew.vout.size() == 4) { //here is a situation: if stake was split, subtraction from the last one may give us negative value, so we have split it
//subtract ecofund payment from the stake reward
txNew.vout[i - 1].nValue -= ecoFundPayment/2;
txNew.vout[i - 2].nValue -= ecoFundPayment/2;
} else {
//subtract ecofund payment from the stake reward
txNew.vout[i - 1].nValue -= ecoFundPayment;
}
} else {
txNew.vout.resize(2);
txNew.vout[1].scriptPubKey = payee;
txNew.vout[1].nValue = ecoFundPayment;
txNew.vout[0].nValue = blockValue - ecoFundPayment;
}

CTxDestination address1;
ExtractDestination(payee, address1);
CBitcoinAddress address2(address1);

}

CFinalizedBudget* CBudgetManager::FindFinalizedBudget(uint256 nHash)
{
if (mapFinalizedBudgets.count(nHash))
Expand Down
1 change: 1 addition & 0 deletions src/masternode-budget.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class CBudgetManager
TrxValidationStatus IsTransactionValid(const CTransaction& txNew, int nBlockHeight);
std::string GetRequiredPaymentsString(int nBlockHeight);
void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStake);
void FillEcoFundBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStake);

void CheckOrphanVotes();
void Clear()
Expand Down
45 changes: 37 additions & 8 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,42 @@ bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight)
// votes (status = TrxValidationStatus::VoteThreshold) for a finalized budget were found
// In all cases a masternode will get the payment for this block

//check for masternode payee
if (masternodePayments.IsTransactionValid(txNew, nBlockHeight))
return true;
LogPrint("masternode","Invalid mn payment detected %s\n", txNew.ToString().c_str());
if(IsEcoFundBlock(nBlockHeight-1) || IsEcoFundBlock(nBlockHeight) || IsEcoFundBlock(nBlockHeight+1)) {
CScript treasuryPayee = Params().GetEcoFundScriptAtHeight(nBlockHeight);
CAmount treasuryAmount = GetBlockValue(nBlockHeight);

if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))
return false;
LogPrint("masternode","Masternode payment enforcement is disabled, accepting block\n");
return true;
bool bFound = false;

for (CTxOut out : txNew.vout) {
if(out.nValue == treasuryAmount) {
bFound = true; //correct treasury payment has been found
break;
}
}

if(!bFound) {
LogPrint("masternode","Invalid ecofund payment detected %s\n", txNew.ToString().c_str());
if(sporkManager.IsSporkActive(SPORK_19_ECOFUND_PAYMENT_ENFORCEMENT))
return false;
else {
LogPrint("masternode","SPORK_19_ECOFUND_PAYMENT_ENFORCEMENT is not enabled, accept anyway\n");
return true;
}
} else {
LogPrint("masternode","Valid ecofund payment detected %s\n", txNew.ToString().c_str());
return true;
}
} else {
//check for masternode payee
if (masternodePayments.IsTransactionValid(txNew, nBlockHeight))
return true;
LogPrint("masternode", "Invalid mn payment detected %s\n", txNew.ToString().c_str());

if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))
return false;
LogPrint("masternode", "Masternode payment enforcement is disabled, accepting block\n");
return true;
}
}


Expand All @@ -329,6 +356,8 @@ void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStak

if (sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(pindexPrev->nHeight + 1)) {
budget.FillBlockPayee(txNew, nFees, fProofOfStake);
} else if(IsEcoFundBlock(pindexPrev->nHeight)) {
budget.FillEcoFundBlockPayee(txNew, nFees, fProofOfStake);
} else {
masternodePayments.FillBlockPayee(txNew, nFees, fProofOfStake, fZKTSStake);
}
Expand Down
1 change: 1 addition & 0 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ std::vector<CSporkDef> sporkDefs = {
MAKE_SPORK_DEF(SPORK_16_ZEROCOIN_MAINTENANCE_MODE, 1556042710ULL), // OFF
MAKE_SPORK_DEF(SPORK_17_COLDSTAKING_ENFORCEMENT, 4070908800ULL), // OFF
MAKE_SPORK_DEF(SPORK_18_ZEROCOIN_PUBLICSPEND_V4, 4070908800ULL), // OFF
MAKE_SPORK_DEF(SPORK_19_ECOFUND_PAYMENT_ENFORCEMENT, 4070908800ULL), // OFF
};

CSporkManager sporkManager;
Expand Down
1 change: 1 addition & 0 deletions src/sporkid.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum SporkId : int32_t {
SPORK_16_ZEROCOIN_MAINTENANCE_MODE = 10015,
SPORK_17_COLDSTAKING_ENFORCEMENT = 10017,
SPORK_18_ZEROCOIN_PUBLICSPEND_V4 = 10018,
SPORK_19_ECOFUND_PAYMENT_ENFORCEMENT = 10019,

SPORK_INVALID = -1
};
Expand Down
6 changes: 3 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 95303;
static const int PROTOCOL_VERSION = 95304;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Expand All @@ -21,8 +21,8 @@ static const int INIT_PROTO_VERSION = 209;
static const int GETHEADERS_VERSION = 70077;

//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 95302;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 95303;
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 95303;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 95304;

//! masternodes older than this proto version use old strMessage format for mnannounce
static const int MIN_PEER_MNANNOUNCE = 70913;
Expand Down

0 comments on commit 94d7e21

Please sign in to comment.