fixed voting errors

This commit is contained in:
Evan Duffield 2016-05-19 11:34:43 -07:00
parent 5a5a556608
commit 2ca8c85820
8 changed files with 39 additions and 26 deletions

15
env/dash.bash vendored
View File

@ -11,6 +11,7 @@ DASHLOG="mnbudget,mnpayments"
DASHDEBUG="lldb --" DASHDEBUG="lldb --"
DASHBINARY="./dashd" DASHBINARY="./dashd"
DASHNETWORK="testnet" #mainnet, testnet, regtest DASHNETWORK="testnet" #mainnet, testnet, regtest
DASHDIR=".dash-develop"
#DASHBINARY="./dash-qt" #DASHBINARY="./dash-qt"
touch_logs() touch_logs()
@ -98,21 +99,21 @@ cmd_dash()
if [ "$1 $2" = "set mode" ]; then return; fi; if [ "$1 $2" = "set mode" ]; then return; fi;
#---- generic commands #---- generic commands
if [ "$1" = "start" ]; then $DASHDEBUG $DASHBINARY --datadir=/Users/$HOMEUSER/.dash --debug=$DASHLOG -logthreadnames; return; fi; if [ "$1" = "start" ]; then $DASHDEBUG $DASHBINARY --datadir=/Users/$HOMEUSER/$DASHDIR --debug=$DASHLOG -logthreadnames; return; fi;
if [ "$1 $2" = "hard start" ]; then $DASHDEBUG $DASHBINARY --datadir=/Users/$HOMEUSER/.dash --debug=$DASHLOG -reindex -logthreadnames; return; fi; if [ "$1 $2" = "hard start" ]; then $DASHDEBUG $DASHBINARY --datadir=/Users/$HOMEUSER/$DASHDIR --debug=$DASHLOG -reindex -logthreadnames; return; fi;
if [ "$1" = "cd" ]; then cd ~/Desktop/dash-develop; return; fi; if [ "$1" = "cd" ]; then cd ~/Desktop/dash-develop; return; fi;
#---- tail .dash/network/debug.log #---- tail $DASHDIR/network/debug.log
if [ "$1 $DASHNETWORK" = "tail testnet" ]; then cd ~/.dash/testnet3 && tail -f debug.log ; return; fi; if [ "$1 $DASHNETWORK" = "tail testnet" ]; then cd ~/$DASHDIR/testnet3 && tail -f debug.log ; return; fi;
if [ "$1 $DASHNETWORK" = "tail mainnet" ]; then cd ~/.dash/ && tail -f debug.log ; return; fi; if [ "$1 $DASHNETWORK" = "tail mainnet" ]; then cd ~/$DASHDIR/ && tail -f debug.log ; return; fi;
if [ "$1 $DASHNETWORK" = "tail regtest" ]; then cd ~/.dash/regtest && tail -f debug.log ; return; fi; if [ "$1 $DASHNETWORK" = "tail regtest" ]; then cd ~/$DASHDIR/regtest && tail -f debug.log ; return; fi;
array=$@; array=$@;
array="${array[@]:3}"; array="${array[@]:3}";
echo $array; echo $array;
#----- cli commands #----- cli commands
if [ "$1" = "cli" ]; then cd ~/Desktop/dash-develop && ./dash-cli --datadir=/Users/$HOMEUSER/.dash $array ; return; fi; if [ "$1" = "cli" ]; then cd ~/Desktop/dash-develop && ./dash-cli --datadir=/Users/$HOMEUSER/$DASHDIR $array; return; fi;
echo "unknown dash command. see 'dash help'" echo "unknown dash command. see 'dash help'"
} }

View File

@ -96,7 +96,7 @@ void CActiveMasternode::ManageStatus()
if(GetMasterNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress)) { if(GetMasterNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress)) {
if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){ if(GetInputAge(vin) < GetMasternodeConfirmationsRequired()){
status = ACTIVE_MASTERNODE_INPUT_TOO_NEW; status = ACTIVE_MASTERNODE_INPUT_TOO_NEW;
notCapableReason = strprintf("%s - %d confirmations", GetStatus(), GetInputAge(vin)); notCapableReason = strprintf("%s - %d confirmations", GetStatus(), GetInputAge(vin));
LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason); LogPrintf("CActiveMasternode::ManageStatus() - %s\n", notCapableReason);
@ -153,7 +153,7 @@ std::string CActiveMasternode::GetStatus() {
switch (status) { switch (status) {
case ACTIVE_MASTERNODE_INITIAL: return "Node just started, not yet activated"; case ACTIVE_MASTERNODE_INITIAL: return "Node just started, not yet activated";
case ACTIVE_MASTERNODE_SYNC_IN_PROCESS: return "Sync in progress. Must wait until sync is complete to start Masternode"; case ACTIVE_MASTERNODE_SYNC_IN_PROCESS: return "Sync in progress. Must wait until sync is complete to start Masternode";
case ACTIVE_MASTERNODE_INPUT_TOO_NEW: return strprintf("Masternode input must have at least %d confirmations", MASTERNODE_MIN_CONFIRMATIONS); case ACTIVE_MASTERNODE_INPUT_TOO_NEW: return strprintf("Masternode input must have at least %d confirmations", GetMasternodeConfirmationsRequired());
case ACTIVE_MASTERNODE_NOT_CAPABLE: return "Not capable masternode: " + notCapableReason; case ACTIVE_MASTERNODE_NOT_CAPABLE: return "Not capable masternode: " + notCapableReason;
case ACTIVE_MASTERNODE_STARTED: return "Masternode successfully started"; case ACTIVE_MASTERNODE_STARTED: return "Masternode successfully started";
default: return "unknown"; default: return "unknown";

View File

@ -545,7 +545,7 @@ CGovernanceObject::CGovernanceObject()
// caching // caching
fCachedFunding = false; fCachedFunding = false;
fCachedValid = false; fCachedValid = true;
fCachedDelete = false; fCachedDelete = false;
fCachedClearRegisters = false; fCachedClearRegisters = false;
fCachedEndorsed = false; fCachedEndorsed = false;

View File

@ -487,8 +487,8 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos)
LogPrint("masternode", "CMasternodeBroadcast::CheckInputsAndAdd - Accepted Masternode entry\n"); LogPrint("masternode", "CMasternodeBroadcast::CheckInputsAndAdd - Accepted Masternode entry\n");
if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){ if(GetInputAge(vin) < GetMasternodeConfirmationsRequired()){
LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Input must have at least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS); LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Input must have at least %d confirmations\n", GetMasternodeConfirmationsRequired());
// maybe we miss few blocks, let this mnb to be checked again later // maybe we miss few blocks, let this mnb to be checked again later
mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); mnodeman.mapSeenMasternodeBroadcast.erase(GetHash());
masternodeSync.mapSeenSyncMNB.erase(GetHash()); masternodeSync.mapSeenSyncMNB.erase(GetHash());
@ -496,7 +496,7 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos)
} }
// verify that sig time is legit in past // verify that sig time is legit in past
// should be at least not earlier than block when 1000 DASH tx got MASTERNODE_MIN_CONFIRMATIONS // should be at least not earlier than block when 1000 DASH tx got GetMasternodeConfirmationsRequired()
uint256 hashBlock = uint256(); uint256 hashBlock = uint256();
CTransaction tx2; CTransaction tx2;
GetTransaction(vin.prevout.hash, tx2, Params().GetConsensus(), hashBlock, true); GetTransaction(vin.prevout.hash, tx2, Params().GetConsensus(), hashBlock, true);
@ -506,11 +506,11 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos)
if (mi != mapBlockIndex.end() && (*mi).second) if (mi != mapBlockIndex.end() && (*mi).second)
{ {
CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation CBlockIndex* pMNIndex = (*mi).second; // block for 1000 DASH tx -> 1 confirmation
CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + MASTERNODE_MIN_CONFIRMATIONS - 1]; // block where tx got MASTERNODE_MIN_CONFIRMATIONS CBlockIndex* pConfIndex = chainActive[pMNIndex->nHeight + GetMasternodeConfirmationsRequired() - 1]; // block where tx got GetMasternodeConfirmationsRequired()
if(pConfIndex->GetBlockTime() > sigTime) if(pConfIndex->GetBlockTime() > sigTime)
{ {
LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n", LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Bad sigTime %d for Masternode %20s %105s (%i conf block is at %d)\n",
sigTime, addr.ToString(), vin.ToString(), MASTERNODE_MIN_CONFIRMATIONS, pConfIndex->GetBlockTime()); sigTime, addr.ToString(), vin.ToString(), GetMasternodeConfirmationsRequired(), pConfIndex->GetBlockTime());
return false; return false;
} }
} }

View File

@ -13,7 +13,8 @@
#include "main.h" #include "main.h"
#include "timedata.h" #include "timedata.h"
#define MASTERNODE_MIN_CONFIRMATIONS 15 #define MASTERNODE_MIN_CONFIRMATIONS_TEST 1
#define MASTERNODE_MIN_CONFIRMATIONS_MAIN 15
#define MASTERNODE_MIN_MNP_SECONDS (10*60) #define MASTERNODE_MIN_MNP_SECONDS (10*60)
#define MASTERNODE_MIN_MNB_SECONDS (5*60) #define MASTERNODE_MIN_MNB_SECONDS (5*60)
#define MASTERNODE_PING_SECONDS (5*60) #define MASTERNODE_PING_SECONDS (5*60)
@ -30,6 +31,14 @@ extern map<int64_t, uint256> mapCacheBlockHashes;
bool GetBlockHash(uint256& hash, int nBlockHeight); bool GetBlockHash(uint256& hash, int nBlockHeight);
int GetMasternodeConfirmationsRequired()
{
if(Params().NetworkIDString() == CBaseChainParams::MAIN)
return MASTERNODE_MIN_CONFIRMATIONS_MAIN;
else
return MASTERNODE_MIN_CONFIRMATIONS_TEST;
}
// //
// The Masternode Ping Class : Contains a different serialize method for sending pings from masternodes throughout the network // The Masternode Ping Class : Contains a different serialize method for sending pings from masternodes throughout the network

View File

@ -20,6 +20,8 @@ bool CMasternodeConfig::read(std::string& strErr) {
boost::filesystem::path pathMasternodeConfigFile = GetMasternodeConfigFile(); boost::filesystem::path pathMasternodeConfigFile = GetMasternodeConfigFile();
boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile); boost::filesystem::ifstream streamConfig(pathMasternodeConfigFile);
LogPrintf("loading masternode file at %s\n", pathMasternodeConfigFile.c_str());
if (!streamConfig.good()) { if (!streamConfig.good()) {
FILE* configFile = fopen(pathMasternodeConfigFile.string().c_str(), "a"); FILE* configFile = fopen(pathMasternodeConfigFile.string().c_str(), "a");
if (configFile != NULL) { if (configFile != NULL) {

View File

@ -82,6 +82,7 @@ public:
void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex); void add(std::string alias, std::string ip, std::string privKey, std::string txHash, std::string outputIndex);
std::vector<CMasternodeEntry>& getEntries() { std::vector<CMasternodeEntry>& getEntries() {
printf("%d\n", (int)entries.size());
return entries; return entries;
} }

View File

@ -22,7 +22,7 @@
using namespace std; using namespace std;
int ConvertVoteAction(std::string strVoteAction) int ConvertVoteOutcome(std::string strVoteAction)
{ {
int nVote = -1; int nVote = -1;
if(strVoteAction == "yes") nVote = VOTE_OUTCOME_YES; if(strVoteAction == "yes") nVote = VOTE_OUTCOME_YES;
@ -32,7 +32,7 @@ int ConvertVoteAction(std::string strVoteAction)
return nVote; return nVote;
} }
int ConvertVoteOutcome(std::string strVoteOutcome) int ConvertVoteAction(std::string strVoteOutcome)
{ {
if(strVoteOutcome == "none") return 0; if(strVoteOutcome == "none") return 0;
if(strVoteOutcome == "funding") return 1; if(strVoteOutcome == "funding") return 1;
@ -109,7 +109,7 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
" get - Get proposal hash(es) by proposal name\n" " get - Get proposal hash(es) by proposal name\n"
" list - List all proposals\n" " list - List all proposals\n"
" diff - List differences since last diff\n" " diff - List differences since last diff\n"
" vote-alias - Vote on a proposal by masternode alias\n" " vote-alias - Vote on a governance object by masternode alias\n"
); );
if(strCommand == "prepare") if(strCommand == "prepare")
@ -162,6 +162,7 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
if(strCommand == "submit") if(strCommand == "submit")
{ {
printf("%d\n", (int)params.size());
if (params.size() != 7) if (params.size() != 7)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance submit <fee-tx> <parent-hash> <revision> <time> <name> <registers-hex>'"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance submit <fee-tx> <parent-hash> <revision> <time> <name> <registers-hex>'");
@ -213,18 +214,17 @@ UniValue mngovernance(const UniValue& params, bool fHelp)
if(strCommand == "vote-alias") if(strCommand == "vote-alias")
{ {
if(params.size() != 4) if(params.size() != 5)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance vote-alias <governance-hash> <vote-action> [yes|no|abstain] <alias-name>'"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mngovernance vote-alias <governance-hash> [funding|valid|delete] [yes|no|abstain] <alias-name>'");
uint256 hash; uint256 hash;
std::string strVote; std::string strVote;
hash = ParseHashV(params[1], "Object hash"); hash = ParseHashV(params[1], "Object hash");
strVote = params[2].get_str(); std::string strVoteAction = params[2].get_str();
std::string strAlias = params[3].get_str(); std::string strVoteOutcome = params[3].get_str();
std::string strVoteAction = params[4].get_str(); std::string strAlias = params[4].get_str();
std::string strVoteOutcome = params[5].get_str();
int nVoteAction = ConvertVoteAction(strVoteAction); int nVoteAction = ConvertVoteAction(strVoteAction);
if(nVoteAction == VOTE_OUTCOME_NONE || nVoteAction == -1) if(nVoteAction == VOTE_OUTCOME_NONE || nVoteAction == -1)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");