Proposal nTime based on fee transaction block

This commit is contained in:
Evan Duffield 2015-07-29 18:26:21 -07:00
parent 0e7b73e166
commit 805452955b
4 changed files with 22 additions and 43 deletions

View File

@ -227,12 +227,6 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste
return false;
}
if(!ConnectNode((CAddress)service, service.ToString().c_str())){
errorMessage = strprintf("Error: Could not connect to %s", service.ToString());
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
return false;
}
return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage);
}

View File

@ -30,7 +30,7 @@ int GetBudgetPaymentCycleBlocks(){
return 50;
}
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError)
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime)
{
CTransaction txCollateral;
uint256 nBlockHash;
@ -69,6 +69,7 @@ bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, s
CBlockIndex* pindex = (*mi).second;
if (chainActive.Contains(pindex)) {
conf += chainActive.Height() - pindex->nHeight + 1;
nTime = pindex->nTime;
}
}
}
@ -88,6 +89,7 @@ void CBudgetManager::CheckOrphanVotes()
LogPrintf("LOCK - %\n", __func__);
LOCK(cs);
std::string strError = "";
std::map<uint256, CBudgetVote>::iterator it1 = mapOrphanMasternodeBudgetVotes.begin();
while(it1 != mapOrphanMasternodeBudgetVotes.end()){
@ -906,7 +908,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
}
std::string strError = "";
if(!IsBudgetCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError)){
if(!IsBudgetCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError, finalizedBudgetBroadcast.nTime)){
LogPrintf("Finalized Budget FeeTX is not valid - %s - %s\n", finalizedBudgetBroadcast.nFeeTXHash.ToString(), strError);
return;
}
@ -1098,7 +1100,7 @@ CBudgetProposal::CBudgetProposal()
fValid = true;
}
CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn, int64_t nTimeIn)
CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn)
{
strProposalName = strProposalNameIn;
strURL = strURLIn;
@ -1106,7 +1108,6 @@ CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strU
nBlockEnd = nBlockEndIn;
address = addressIn;
nAmount = nAmountIn;
nTime = nTimeIn;
nFeeTXHash = nFeeTXHashIn;
fValid = true;
}
@ -1143,14 +1144,7 @@ bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral)
}
if(fCheckCollateral){
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError)){
return false;
}
}
if(masternodeSync.IsSynced()) {
if(nTime < GetTime() - (60*60*2) || nTime < GetTime() - (60*60)) {
strError = "Time is out of acceptable range.";
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError, nTime)){
return false;
}
}
@ -1341,8 +1335,8 @@ CBudgetProposalBroadcast::CBudgetProposalBroadcast()
nBlockStart = 0;
nBlockEnd = 0;
nAmount = 0;
nTime = 0;
nFeeTXHash = 0;
nTime = 0;
}
CBudgetProposalBroadcast::CBudgetProposalBroadcast(const CBudgetProposal& other)
@ -1357,7 +1351,7 @@ CBudgetProposalBroadcast::CBudgetProposalBroadcast(const CBudgetProposal& other)
nTime = other.nTime;
}
CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn, int64_t nTimeIn)
CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn)
{
strProposalName = strProposalNameIn;
strURL = strURLIn;
@ -1372,8 +1366,6 @@ CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn
nAmount = nAmountIn;
nFeeTXHash = nFeeTXHashIn;
nTime = nTimeIn;
}
void CBudgetProposalBroadcast::Relay()
@ -1458,6 +1450,7 @@ CFinalizedBudget::CFinalizedBudget()
vecBudgetPayments.clear();
mapVotes.clear();
nFeeTXHash = 0;
nTime = 0;
fValid = true;
}
@ -1468,6 +1461,7 @@ CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other)
vecBudgetPayments = other.vecBudgetPayments;
mapVotes = other.mapVotes;
nFeeTXHash = other.nFeeTXHash;
nTime = other.nTime;
fValid = true;
}
@ -1652,7 +1646,7 @@ bool CFinalizedBudget::IsValid(std::string& strError, bool fCheckCollateral)
std::string strError2 = "";
if(fCheckCollateral){
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2)){
if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2, nTime)){
{strError = "Invalid Collateral : " + strError2; return false;}
}
}

View File

@ -43,7 +43,7 @@ void DumpBudgets();
int GetBudgetPaymentCycleBlocks();
//Check the collateral transaction for the budget proposal/finalized budget
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError);
bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime);
/** Save Budget Manager (budget.dat)
*/
@ -208,6 +208,7 @@ public:
std::vector<CTxBudgetPayment> vecBudgetPayments;
map<uint256, CFinalizedBudgetVote> mapVotes;
uint256 nFeeTXHash;
int64_t nTime;
CFinalizedBudget();
CFinalizedBudget(const CFinalizedBudget& other);
@ -276,6 +277,7 @@ public:
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
READWRITE(LIMITED_STRING(strBudgetName, 20));
READWRITE(nFeeTXHash);
READWRITE(nTime);
READWRITE(nBlockStart);
READWRITE(vecBudgetPayments);
@ -381,7 +383,7 @@ public:
CBudgetProposal();
CBudgetProposal(const CBudgetProposal& other);
CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn, int64_t nTimeIn);
CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn);
void Calculate();
bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError);
@ -413,7 +415,6 @@ public:
int GetNays();
int GetAbstains();
CAmount GetAmount() {return nAmount;}
void SetAllotted(CAmount nAllotedIn) {nAlloted = nAllotedIn;}
CAmount GetAllotted() {return nAlloted;}
@ -423,7 +424,6 @@ public:
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
ss << strProposalName;
ss << strURL;
ss << nTime;
ss << nBlockStart;
ss << nBlockEnd;
ss << nAmount;
@ -462,7 +462,7 @@ private:
public:
CBudgetProposalBroadcast();
CBudgetProposalBroadcast(const CBudgetProposal& other);
CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn, int64_t nTimeIn);
CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn);
void Relay();

View File

@ -92,7 +92,7 @@ Value mnbudget(const Array& params, bool fHelp)
//*************************************************************************
// create transaction 15 minutes into the future, to allow for confirmation time
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, 0, GetAdjustedTime()+(60*15));
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, 0);
std::string strError = "";
if(!budgetProposalBroadcast.IsValid(strError, false))
@ -113,12 +113,7 @@ Value mnbudget(const Array& params, bool fHelp)
//send the tx to the network
pwalletMain->CommitTransaction(wtx, reservekey, useIX ? "ix" : "tx");
Object returnObj;
returnObj.push_back(Pair("fee_tx", wtx.GetHash().ToString()));
returnObj.push_back(Pair("time", (int64_t)budgetProposalBroadcast.nTime));
return returnObj;
return wtx.GetHash().ToString();
}
if(strCommand == "submit")
@ -129,8 +124,8 @@ Value mnbudget(const Array& params, bool fHelp)
std::vector<CMasternodeConfig::CMasternodeEntry> mnEntries;
mnEntries = masternodeConfig.getEntries();
if (params.size() != 9)
throw runtime_error("Correct usage is 'mnbudget submit proposal-name url payment_count block_start dash_address monthly_payment_dash fee_tx nTime'");
if (params.size() != 8)
throw runtime_error("Correct usage is 'mnbudget submit proposal-name url payment_count block_start dash_address monthly_payment_dash fee_tx'");
// Check these inputs the same way we check the vote commands:
// **********************************************************
@ -172,16 +167,12 @@ Value mnbudget(const Array& params, bool fHelp)
CScript scriptPubKey = GetScriptForDestination(address.Get());
CAmount nAmount = AmountFromValue(params[6]);
uint256 hash = ParseHashV(params[7], "parameter 1");
int64_t nTime = params[8].get_int();
if(nTime < GetTime() - (60*60*2) || nTime > GetTime() + (60*60))
return "nTime is out of range, you must submit the proposal within 2 hours of creating the original colateral transaction";
//create the proposal incase we're the first to make it
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash, nTime);
CBudgetProposalBroadcast budgetProposalBroadcast(strProposalName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash);
std::string strError = "";
if(!IsBudgetCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError)){
if(!IsBudgetCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime)){
return "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError;
}