Skip to content

Commit

Permalink
Merge pull request #15 from mitchelvanamstel/master
Browse files Browse the repository at this point in the history
EcoFund stuck fix
  • Loading branch information
mitchelvanamstel committed Jul 1, 2020
2 parents cf3fc96 + 9467d44 commit c23f1f5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -3,7 +3,7 @@

The core wallet of the Klimatas project. Klimatas is a project aiming to improve global sustainability with an investment platform and on-chain governance.

Current stable version: 1.3.4
Current stable version: 1.3.4.1

## Installation

Expand All @@ -16,8 +16,8 @@ You can also build Klimatas core from source yourself. Please use the source cod
### Build instructions

```bash
wget https://github.com/klimatas/klimatas-core/archive/1.3.4.tar.gz
tar xzvf 1.3.4.tar.gz && cd 1.3.4
wget https://github.com/klimatas/klimatas-core/archive/1.3.4.1.tar.gz
tar xzvf 1.3.4.1.tar.gz && cd 1.3.4.1
./autogen.sh
./configure
make -j2
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 3)
define(_CLIENT_VERSION_REVISION, 4)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2020)
Expand Down
10 changes: 8 additions & 2 deletions src/main.cpp
Expand Up @@ -2001,6 +2001,9 @@ int nEcoFundBlockStep = 1440;

bool IsEcoFundBlock(int nHeight)
{
if(nHeight == 800033)
return true;

if(nHeight < nStartEcoFundBlock)
return false;
else if( (nHeight-nStartEcoFundBlock) % nEcoFundBlockStep == 0)
Expand Down Expand Up @@ -4451,8 +4454,11 @@ bool CheckColdStakeFreeOutput(const CTransaction& tx, const int nHeight)
return true;

if (budget.IsBudgetPaymentBlock(nHeight) &
sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) &&
sporkManager.IsSporkActive(SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT))
sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) &&
sporkManager.IsSporkActive(SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT))
return true;

if (IsEcoFundBlock(nHeight))
return true;

return error("%s: Wrong cold staking outputs: vout[%d].scriptPubKey (%s) != vout[%d].scriptPubKey (%s) - value: %s",
Expand Down
20 changes: 13 additions & 7 deletions src/masternode-budget.cpp
Expand Up @@ -598,9 +598,9 @@ void CBudgetManager::FillEcoFundBlockPayee(CMutableTransaction& txNew, CAmount n

CScript payee;

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


if (fProofOfStake) {
Expand All @@ -614,10 +614,16 @@ void CBudgetManager::FillEcoFundBlockPayee(CMutableTransaction& txNew, CAmount n
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;
if (txNew.vout.size() > 2) {
// special case, stake is split between (i-1) outputs
unsigned int outputs = i-1;
CAmount ecfundPaymentSplit = ecoFundPayment / outputs;
CAmount ecfundPaymentRemainder = ecoFundPayment - (ecfundPaymentSplit * outputs);
for (unsigned int j=1; j<=outputs; j++) {
txNew.vout[j].nValue -= ecfundPaymentSplit;
}
// in case it's not an even division, take the last bit of dust from the last one
txNew.vout[outputs].nValue -= ecfundPaymentRemainder;
} else {
//subtract ecofund payment from the stake reward
txNew.vout[i - 1].nValue -= ecoFundPayment;
Expand Down
4 changes: 2 additions & 2 deletions src/masternode-payments.cpp
Expand Up @@ -310,7 +310,7 @@ 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

if(IsEcoFundBlock(nBlockHeight-1) || IsEcoFundBlock(nBlockHeight) || IsEcoFundBlock(nBlockHeight+1)) {
if(IsEcoFundBlock(nBlockHeight)) {
CScript treasuryPayee = Params().GetEcoFundScriptAtHeight(nBlockHeight);
CAmount treasuryAmount = GetBlockValue(nBlockHeight);

Expand Down Expand Up @@ -356,7 +356,7 @@ 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)) {
} else if(IsEcoFundBlock(pindexPrev->nHeight + 1)) {
budget.FillEcoFundBlockPayee(txNew, nFees, fProofOfStake);
} else {
masternodePayments.FillBlockPayee(txNew, nFees, fProofOfStake, fZKTSStake);
Expand Down
6 changes: 3 additions & 3 deletions src/version.h
Expand Up @@ -12,7 +12,7 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 95304;
static const int PROTOCOL_VERSION = 95305;

//! 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 = 95303;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 95304;
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 95304;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 95305;

//! 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 c23f1f5

Please sign in to comment.