Skip to content

Commit

Permalink
Merge pull request #1 from kerryoncrypto/tiered-masternodes
Browse files Browse the repository at this point in the history
MasterWin 3.0
  • Loading branch information
Master-Win committed Oct 2, 2020
2 parents cbbf897 + bb53c37 commit dee5f52
Show file tree
Hide file tree
Showing 30 changed files with 968 additions and 872 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.dirstamp
*.o
*.a
*.Po
*.Plo
*.Tpo
src/masterwin-cli
src/masterwin-tx
src/masterwind
src/test/buildenv.py
src/test/data/*.h
autom4te.cache/*
Makefile
Makefile.in
aclocal.m4
build_cmd
config.log
config.status
configure
contrib/devtools/split-debug.sh
libtool
qa/pull-tester/run-bitcoind-for-test.sh
qa/pull-tester/tests-config.sh
share/qt/Info.plist
share/setup.nsi
src/Makefile
src/Makefile.in
src/config/masterwin-config.h
src/config/stamp-h1
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MAJOR, 3)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2019)
define(_COPYRIGHT_YEAR, 2020)
AC_INIT([MasterWin],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[www.mw.one],[masterwin])
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADERS([src/config/masterwin-config.h])
Expand Down
117 changes: 36 additions & 81 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,38 +194,6 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)

mnp.Relay();

/*
* IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS
* AFTER MIGRATION TO V12 IS DONE
*/

if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true;
// for migration purposes ping our node on old masternodes network too
std::string retErrorMessage;
std::vector<unsigned char> vchMasterNodeSignature;
int64_t masterNodeSignatureTime = GetAdjustedTime();

std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + boost::lexical_cast<std::string>(false);

if (!obfuScationSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyMasternode)) {
errorMessage = "dseep sign message failed: " + retErrorMessage;
return false;
}

if (!obfuScationSigner.VerifyMessage(pubKeyMasternode, vchMasterNodeSignature, strMessage, retErrorMessage)) {
errorMessage = "dseep verify message failed: " + retErrorMessage;
return false;
}

LogPrint("masternode", "dseep - relaying from active mn, %s \n", vin.ToString().c_str());
LOCK(cs_vNodes);
BOOST_FOREACH (CNode* pnode, vNodes)
pnode->PushMessage("dseep", vin, vchMasterNodeSignature, masterNodeSignatureTime, false);

/*
* END OF "REMOVE"
*/

return true;
} else {
// Seems like we are trying to send a ping while the Masternode is not registered in the network
Expand Down Expand Up @@ -296,44 +264,6 @@ bool CActiveMasternode::CreateBroadcast(CTxIn vin, CService service, CKey keyCol
return false;
}

/*
* IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS
* AFTER MIGRATION TO V12 IS DONE
*/

if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true;
// for migration purposes inject our node in old masternodes' list too
std::string retErrorMessage;
std::vector<unsigned char> vchMasterNodeSignature;
int64_t masterNodeSignatureTime = GetAdjustedTime();
std::string donationAddress = "";
int donationPercantage = 0;

std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end());
std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end());

std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION) + donationAddress + boost::lexical_cast<std::string>(donationPercantage);

if (!obfuScationSigner.SignMessage(strMessage, retErrorMessage, vchMasterNodeSignature, keyCollateralAddress)) {
errorMessage = "dsee sign message failed: " + retErrorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str());
return false;
}

if (!obfuScationSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, retErrorMessage)) {
errorMessage = "dsee verify message failed: " + retErrorMessage;
LogPrintf("CActiveMasternode::Register() - Error: %s\n", errorMessage.c_str());
return false;
}

LOCK(cs_vNodes);
BOOST_FOREACH (CNode* pnode, vNodes)
pnode->PushMessage("dsee", vin, service, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyCollateralAddress, pubKeyMasternode, -1, -1, masterNodeSignatureTime, PROTOCOL_VERSION, donationAddress, donationPercantage);

/*
* END OF "REMOVE"
*/

return true;
}

Expand All @@ -355,6 +285,8 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
COutput* selectedOutput;

// Find the vin
bool found = false;

if (!strTxHash.empty()) {
// Let's find it
uint256 txHash(strTxHash);
Expand All @@ -366,26 +298,49 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
return false;
}

bool found = false;
BOOST_FOREACH (COutput& out, possibleCoins) {
if (out.tx->GetHash() == txHash && out.i == outputIndex) {
if ((out.tx->GetHash () == txHash) &&
(out.i == outputIndex) &&
(Params ().isMasternodeCollateral (out.tx->vout [out.i].nValue))) {
selectedOutput = &out;
found = true;
break;
}
}
if (!found) {
LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n");
return false;
}
} else {
// No output specified, Select the first one
if (possibleCoins.size() > 0) {
selectedOutput = &possibleCoins[0];
} else {
// No output specified, Select the first usable one
if (!possibleCoins.size ()) {
LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate specified vin from possible list\n");
return false;
}

selectedOutput = &possibleCoins [0];

unsigned int selectedTier = Params ().getMasternodeTier (selectedOutput->tx->vout [selectedOutput->i].nValue);
unsigned int maxTier = Params ().getMasternodeTierCount ();

BOOST_FOREACH (COutput& out, possibleCoins) {
if (selectedTier == maxTier)
break;

unsigned int nextTier = Params ().getMasternodeTier (out.tx->vout [out.i].nValue);

if (nextTier <= selectedTier)
continue;

selectedTier = nextTier;
selectedOutput = &out;
found = true;
}

if (maxTier < 1)
found = false;
}

if (!found) {
LogPrintf("CActiveMasternode::GetMasterNodeVin - Could not locate valid vin\n");

return false;
}

// At this point we have a selected output, retrieve the associated info
Expand Down Expand Up @@ -457,7 +412,7 @@ vector<COutput> CActiveMasternode::SelectCoinsMasternode()

// Filter
BOOST_FOREACH (const COutput& out, vCoins) {
if (out.tx->vout[out.i].nValue == 4000 * COIN) { //exactly
if (Params ().isMasternodeCollateral (out.tx->vout [out.i].nValue)) {
filteredCoins.push_back(out);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,14 @@ class CMainParams : public CChainParams
blacklistedAddresses = std::set<std::string>{
"MUqGH9fvKxjSSJhLQuKMM1yD8EsuZnc6P3",
};
}

vMasternodeTiers.push_back ({
nLastPOWBlock,
{
{ 4000 * COIN, 1 }
}
});
}

const Checkpoints::CCheckpointData& Checkpoints() const
{
Expand Down
109 changes: 109 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include "primitives/block.h"
#include "protocol.h"
#include "uint256.h"
#include "chain.h"

#include "libzerocoin/Params.h"
#include <vector>
#include <boost/foreach.hpp>

typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];

Expand All @@ -25,6 +27,19 @@ struct CDNSSeedData {
CDNSSeedData(const std::string& strName, const std::string& strHost) : name(strName), host(strHost) {}
};

struct MasternodeTier {
CAmount Collateral;
uint16_t Weight;
};

struct MasternodeTiers {
unsigned int blockHeight;
std::vector<MasternodeTier> masternodeTiers;
};

/** The currently-connected chain of blocks. */
extern CChain chainActive;

/**
* CChainParams defines various tweakable parameters of a given instance of the
* MasterWin system. There are three: the main network on which people trade goods
Expand Down Expand Up @@ -127,7 +142,99 @@ class CChainParams
int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; }
int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; }
CAmount InvalidAmountFiltered() const { return nInvalidAmountFiltered; };

bool isMasternodeCollateral (CAmount nValue, unsigned int atBlockHeight = 0) const {
MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight);

if (currentTiers == NULL)
return false;

// Check if the given value is on collateral-list
BOOST_FOREACH (const MasternodeTier& masternodeTier, currentTiers->masternodeTiers) {
if (nValue == masternodeTier.Collateral)
return true;
}

// Cannot be a valid collateral-value if we get here
return false;
}

MasternodeTiers *getMasternodeTiers (unsigned int atBlockHeight = 0) const {
if (atBlockHeight == 0) {
CBlockIndex* chainTip = chainActive.Tip ();

if (chainTip != NULL)
atBlockHeight = chainTip->nHeight;
}

MasternodeTiers *currentTiers = NULL;

BOOST_FOREACH (const MasternodeTiers& masternodeTiers, vMasternodeTiers) {
if (masternodeTiers.blockHeight <= atBlockHeight)
currentTiers = (MasternodeTiers *)&masternodeTiers;
else
break;
}

return currentTiers;
}

unsigned int getMasternodeTierCount (unsigned int atBlockHeight = 0) const {
MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight);

if (currentTiers == NULL)
return 0;

return currentTiers->masternodeTiers.size ();
}

unsigned int getMasternodeTier (CAmount collateralValue, unsigned int atBlockHeight = 0) const {
MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight);

if (currentTiers == NULL)
return 0;

unsigned int currentLevel = 0;

// Check if the given value is on collateral-list
BOOST_FOREACH (const MasternodeTier& masternodeTier, currentTiers->masternodeTiers) {
currentLevel++;

if (collateralValue == masternodeTier.Collateral)
return currentLevel;
}

return 0;
}

unsigned int getMasternodeTierWeight (unsigned int masternodeTier = 0, unsigned int atBlockHeight = 0) const {
MasternodeTiers *currentTiers = getMasternodeTiers (atBlockHeight);

if (currentTiers == NULL)
return (masternodeTier == 0 ? 1 : 0);

// Make sure the tier is valid
if (masternodeTier > currentTiers->masternodeTiers.size ())
return 0;

// Return weight of a given tier
if (masternodeTier > 0)
return currentTiers->masternodeTiers [masternodeTier - 1].Weight;

// Collect sum of all tiers
unsigned int tierWeightSum = 0;

BOOST_FOREACH (const MasternodeTier& masternodeTier, currentTiers->masternodeTiers) {
tierWeightSum += masternodeTier.Weight;
}

// Never return something less than one, to prevent divisions by zero
if (tierWeightSum < 1)
tierWeightSum = 1;

return tierWeightSum;
}

protected:
CChainParams() {}

Expand Down Expand Up @@ -191,6 +298,8 @@ class CChainParams
int nBlockLastGoodCheckpoint;
int nBlockEnforceInvalidUTXO;
int nBlockZerocoinV2;

std::vector<MasternodeTiers> vMasternodeTiers;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/fcntl.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/types.h>
Expand Down
4 changes: 2 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-onlynet=<net>", _("Only connect to nodes in network <net> (ipv4, ipv6 or onion)"));
strUsage += HelpMessageOpt("-permitbaremultisig", strprintf(_("Relay non-P2SH multisig (default: %u)"), 1));
strUsage += HelpMessageOpt("-peerbloomfilters", strprintf(_("Support filtering of blocks and transaction with bloom filters (default: %u)"), DEFAULT_PEERBLOOMFILTERS));
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), 33555, 29991));
strUsage += HelpMessageOpt("-port=<port>", strprintf(_("Listen for connections on <port> (default: %u or testnet: %u)"), Params ().GetDefaultPort (), 29991));
strUsage += HelpMessageOpt("-proxy=<ip:port>", _("Connect through SOCKS5 proxy"));
strUsage += HelpMessageOpt("-proxyrandomize", strprintf(_("Randomize credentials for every proxy connection. This enables Tor stream isolation (default: %u)"), 1));
strUsage += HelpMessageOpt("-seednode=<ip>", _("Connect to a node to retrieve peer addresses, and disconnect"));
Expand Down Expand Up @@ -531,7 +531,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-mnconf=<file>", strprintf(_("Specify masternode configuration file (default: %s)"), "masternode.conf"));
strUsage += HelpMessageOpt("-mnconflock=<n>", strprintf(_("Lock masternodes from masternode configuration file (default: %u)"), 1));
strUsage += HelpMessageOpt("-masternodeprivkey=<n>", _("Set the masternode private key"));
strUsage += HelpMessageOpt("-masternodeaddr=<n>", strprintf(_("Set external address:port to get to this masternode (example: %s)"), "128.127.106.235:33555"));
strUsage += HelpMessageOpt("-masternodeaddr=<n>", strprintf(_("Set external address:port to get to this masternode (example: %s)"), "128.127.106.235:" + Params ().GetDefaultPort ()));
strUsage += HelpMessageOpt("-budgetvotemode=<mode>", _("Change automatic finalized budget voting behavior. mode=auto: Vote for only exact finalized budget match to my generated budget. (string, default: auto)"));


Expand Down
Loading

0 comments on commit dee5f52

Please sign in to comment.