Skip to content
Permalink
Browse files

Merge pull request #38 from observernet/fix-mn-collateral

Several fixes and improvements
  • Loading branch information
Charunder committed Aug 14, 2019
2 parents b8f710f + 94e4efd commit bac799d60d4ff3c88e58c1cc369c2fa396ec7710
Showing with 36 additions and 25 deletions.
  1. +9 −0 src/chainparams.cpp
  2. +2 −0 src/chainparams.h
  3. +1 −1 src/coins.cpp
  4. +4 −4 src/main.cpp
  5. +1 −1 src/obfuscation.h
  6. +1 −1 src/rpc/server.cpp
  7. +15 −15 src/wallet/wallet.cpp
  8. +3 −3 src/wallet/wallet.h
@@ -161,6 +161,9 @@ class CMainParams : public CChainParams
nEnforceNewSporkKey = 1538661892; //!> Sporks signed after GMT: Thursday, October 4, 2018 2:04:52 PM must use the new spork key
nRejectOldSporkKey = 1538661893; //!> Reject old spork key after GMT: Thursday, October 4, 2018 2:04:53 PM

// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
nBIP65Height = 402618;

// Public coin spend enforcement
nPublicZCSpends = 422779;

@@ -293,6 +296,9 @@ class CTestNetParams : public CMainParams
nEnforceNewSporkKey = 1538661892; //!> Sporks signed after GMT: Thursday, October 4, 2018 2:04:52 PM must use the new spork key
nRejectOldSporkKey = 1538661893; //!> Reject old spork key after GMT: Thursday, October 4, 2018 2:04:53 PM

// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
nBIP65Height = 1;

// Public coin spend enforcement
nPublicZCSpends = 500;

@@ -386,6 +392,9 @@ class CRegTestParams : public CTestNetParams
nBlockFirstFraudulent = 999999999; //First block that bad serials emerged
nBlockLastGoodCheckpoint = 999999999; //Last valid accumulator checkpoint

// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
nBIP65Height = 402618;

// Public coin spend enforcement
nPublicZCSpends = 350;

@@ -129,6 +129,7 @@ class CChainParams
int Zerocoin_StartTime() const { return nZerocoinStartTime; }
int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; }
int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; }
int BIP65Height() const { return nBIP65Height; }

// fake serial attack
int Zerocoin_Block_EndFakeSerial() const { return nFakeSerialBlockheightEnd; }
@@ -206,6 +207,7 @@ class CChainParams
int nBlockZerocoinV2;
int nBlockDoubleAccumulated;
int nPublicZCSpends;
int nBIP65Height;

// fake serial attack
int nFakeSerialBlockheightEnd = 0;
@@ -259,7 +259,7 @@ double CCoinsViewCache::GetPriority(const CTransaction& tx, int nHeight) const
assert(coins);
if (!coins->IsAvailable(txin.prevout.n)) continue;
if (coins->nHeight < nHeight) {
dResult += coins->vout[txin.prevout.n].nValue * (nHeight - coins->nHeight);
dResult += coins->vout[txin.prevout.n].nValue * (double)(nHeight - coins->nHeight);
}
}
return tx.ComputePriority(dResult);
@@ -1582,7 +1582,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);


bool fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority());
bool fCLTVHasMajority = chainActive.Tip()->nHeight >= Params().BIP65Height();

// Check against previous transactions
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
@@ -1790,8 +1790,8 @@ bool AcceptableInputs(CTxMemPool& pool, CValidationState& state, const CTransact
hash.ToString(),
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);

bool fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, chainActive.Tip(), Params().EnforceBlockUpgradeMajority());

bool fCLTVHasMajority = chainActive.Tip()->nHeight >= Params().BIP65Height();
// Check against previous transactions
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
int flags = STANDARD_SCRIPT_VERIFY_FLAGS;
@@ -3168,7 +3168,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// If scripts won't be checked anyways, don't bother seeing if CLTV is activated
bool fCLTVHasMajority = false;
if (fScriptChecks && pindex->pprev) {
fCLTVHasMajority = CBlockIndex::IsSuperMajority(5, pindex->pprev, Params().EnforceBlockUpgradeMajority());
fCLTVHasMajority = pindex->pprev->nHeight >= Params().BIP65Height();
}

// Do not allow blocks that contain transactions which 'overwrite' older transactions,
@@ -203,7 +203,7 @@ class CObfuscationBroadcastTx
class CObfuScationSigner
{
public:
/// Is the inputs associated with this public key? (and there is 10000 OBSR - checking if valid masternode)
/// Is the inputs associated with this public key? (and there is 1000000 OBSR - checking if valid masternode)
bool IsVinAssociatedWithPubkey(CTxIn& vin, CPubKey& pubkey);
/// Set the private/public key values, returns true if successful
bool GetKeysFromSecret(std::string strSecret, CKey& keyRet, CPubKey& pubkeyRet);
@@ -116,7 +116,7 @@ CAmount AmountFromValue(const UniValue& value)
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number");

double dAmount = value.get_real();
if (dAmount <= 0.0 || dAmount > 21000000.0)
if (dAmount <= 0.0 || dAmount > 11250000000.0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
CAmount nAmount = roundint64(dAmount * COIN);
if (!MoneyRange(nAmount))
@@ -476,7 +476,7 @@ bool CWallet::GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet, CKey&

// Find possible candidates
std::vector<COutput> vPossibleCoins;
AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_10000);
AvailableCoins(vPossibleCoins, true, NULL, false, ONLY_1000000);
if (vPossibleCoins.empty()) {
LogPrintf("CWallet::GetMasternodeVinAndKeys -- Could not locate any valid masternode vin\n");
return false;
@@ -1024,7 +1024,7 @@ CAmount CWalletTx::GetUnlockedCredit() const
const CTxOut& txout = vout[i];

if (pwallet->IsSpent(hashTx, i) || pwallet->IsLockedCoin(hashTx, i)) continue;
if (fMasterNode && vout[i].nValue == 10000 * COIN) continue; // do not count MN-like outputs
if (fMasterNode && vout[i].nValue == 1000000 * COIN) continue; // do not count MN-like outputs

nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
if (!MoneyRange(nCredit))
@@ -1058,7 +1058,7 @@ CAmount CWalletTx::GetLockedCredit() const
}

// Add masternode collaterals which are handled likc locked coins
else if (fMasterNode && vout[i].nValue == 10000 * COIN) {
else if (fMasterNode && vout[i].nValue == 1000000 * COIN) {
nCredit += pwallet->GetCredit(txout, ISMINE_SPENDABLE);
}

@@ -1133,7 +1133,7 @@ CAmount CWalletTx::GetLockedWatchOnlyCredit() const
}

// Add masternode collaterals which are handled likc locked coins
else if (fMasterNode && vout[i].nValue == 10000 * COIN) {
else if (fMasterNode && vout[i].nValue == 1000000 * COIN) {
nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY);
}

@@ -1662,14 +1662,14 @@ void CWallet::AvailableCoins(
bool found = false;
if (nCoinType == ONLY_DENOMINATED) {
found = IsDenominatedAmount(pcoin->vout[i].nValue);
} else if (nCoinType == ONLY_NOT10000IFMN) {
found = !(fMasterNode && pcoin->vout[i].nValue == 10000 * COIN);
} else if (nCoinType == ONLY_NONDENOMINATED_NOT10000IFMN) {
} else if (nCoinType == ONLY_NOT1000000IFMN) {
found = !(fMasterNode && pcoin->vout[i].nValue == 1000000 * COIN);
} else if (nCoinType == ONLY_NONDENOMINATED_NOT1000000IFMN) {
if (IsCollateralAmount(pcoin->vout[i].nValue)) continue; // do not use collateral amounts
found = !IsDenominatedAmount(pcoin->vout[i].nValue);
if (found && fMasterNode) found = pcoin->vout[i].nValue != 10000 * COIN; // do not use Hot MN funds
} else if (nCoinType == ONLY_10000) {
found = pcoin->vout[i].nValue == 10000 * COIN;
if (found && fMasterNode) found = pcoin->vout[i].nValue != 1000000 * COIN; // do not use Hot MN funds
} else if (nCoinType == ONLY_1000000) {
found = pcoin->vout[i].nValue == 1000000 * COIN;
} else {
found = true;
}
@@ -1692,7 +1692,7 @@ void CWallet::AvailableCoins(
if (mine == ISMINE_WATCH_ONLY && nWatchonlyConfig == 1)
continue;

if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_10000)
if (IsLockedCoin((*it).first, i) && nCoinType != ONLY_1000000)
continue;
if (pcoin->vout[i].nValue <= 0 && !fIncludeZeroValue)
continue;
@@ -2166,10 +2166,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, CAmount> >& vecSend,
if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl, coin_type, useIX)) {
if (coin_type == ALL_COINS) {
strFailReason = _("Insufficient funds.");
} else if (coin_type == ONLY_NOT10000IFMN) {
strFailReason = _("Unable to locate enough funds for this transaction that are not equal 10000 OBSR.");
} else if (coin_type == ONLY_NONDENOMINATED_NOT10000IFMN) {
strFailReason = _("Unable to locate enough Obfuscation non-denominated funds for this transaction that are not equal 10000 OBSR.");
} else if (coin_type == ONLY_NOT1000000IFMN) {
strFailReason = _("Unable to locate enough funds for this transaction that are not equal 1000000 OBSR.");
} else if (coin_type == ONLY_NONDENOMINATED_NOT1000000IFMN) {
strFailReason = _("Unable to locate enough Obfuscation non-denominated funds for this transaction that are not equal 1000000 OBSR.");
} else {
strFailReason = _("Unable to locate enough Obfuscation denominated funds for this transaction.");
strFailReason += " " + _("Obfuscation uses exact denominated amounts to send funds, you might simply need to anonymize some more coins.");
@@ -87,9 +87,9 @@ enum WalletFeature {
enum AvailableCoinsType {
ALL_COINS = 1,
ONLY_DENOMINATED = 2,
ONLY_NOT10000IFMN = 3,
ONLY_NONDENOMINATED_NOT10000IFMN = 4, // ONLY_NONDENOMINATED and not 10000 OBSR at the same time
ONLY_10000 = 5, // find masternode outputs including locked ones (use with caution)
ONLY_NOT1000000IFMN = 3,
ONLY_NONDENOMINATED_NOT1000000IFMN = 4, // ONLY_NONDENOMINATED and not 1000000 OBSR at the same time
ONLY_1000000 = 5, // find masternode outputs including locked ones (use with caution)
STAKABLE_COINS = 6 // UTXO's that are valid for staking
};

0 comments on commit bac799d

Please sign in to comment.
You can’t perform that action at this time.