From 79402b0142fc2db2c4d8fb8e5cbe5fe5b015cd7b Mon Sep 17 00:00:00 2001 From: presstab Date: Fri, 12 Aug 2016 09:10:37 -0600 Subject: [PATCH 1/8] communicate mostly with blocks instead of headers --- src/main.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index eabc5952a2f2..6e70062e2784 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3373,7 +3373,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc if (hash != Params().HashGenesisBlock()) { BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) - return state.DoS(0, error("%s : prev block not found", __func__), 0, "bad-prevblk"); + return state.DoS(0, error("%s : prev block %s not found", __func__, block.hashPrevBlock.ToString().c_str()), 0, "bad-prevblk"); pindexPrev = (*mi).second; if (pindexPrev->nStatus & BLOCK_FAILED_MASK) return state.DoS(100, error("%s : prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); @@ -3402,7 +3402,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, if (block.GetHash() != Params().HashGenesisBlock()) { BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) - return state.DoS(0, error("%s : prev block not found", __func__), 0, "bad-prevblk"); + return state.DoS(0, error("%s : prev block %s not found", __func__, block.hashPrevBlock.ToString().c_str()), 0, "bad-prevblk"); pindexPrev = (*mi).second; if (pindexPrev->nStatus & BLOCK_FAILED_MASK) return state.DoS(100, error("%s : prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); @@ -4784,10 +4784,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, bool fAlreadyHave = AlreadyHave(inv); LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id); - if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK) + if (!fAlreadyHave && !fImporting && !fReindex/* && inv.type != MSG_BLOCK*/) pfrom->AskFor(inv); - + /* if (inv.type == MSG_BLOCK) { UpdateBlockAvailability(pfrom->GetId(), inv.hash); if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { @@ -4810,7 +4810,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); } - } + }*/ // Track requests for our stuff g_signals.Inventory(inv.hash); @@ -4847,7 +4847,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } - else if (strCommand == "getblocks") + else if (strCommand == "getblocks" || strCommand == "getheaders") { CBlockLocator locator; uint256 hashStop; @@ -4862,7 +4862,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pindex) pindex = chainActive.Next(pindex); int nLimit = 500; - LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "end" : hashStop.ToString(), nLimit, pfrom->id); + LogPrintf("getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "end" : hashStop.ToString(), nLimit, pfrom->id); for (; pindex; pindex = chainActive.Next(pindex)) { if (pindex->GetBlockHash() == hashStop) @@ -4883,7 +4883,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } - else if (strCommand == "getheaders") { CBlockLocator locator; uint256 hashStop; @@ -5088,7 +5087,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } - else if (strCommand == "headers" && !fImporting && !fReindex) // Ignore headers received while importing { std::vector headers; @@ -5136,7 +5134,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // Headers message had its maximum size; the peer may have more headers. // TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue // from there instead. - LogPrint("net", "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight); + LogPrintf("more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight); pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256(0)); } @@ -5640,10 +5638,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (nSyncStarted == 0 || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 6 * 60 * 60) { // NOTE: was "close to today" and 24h in Bitcoin state.fSyncStarted = true; nSyncStarted++; - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; - LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); - pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256(0)); + //CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + //LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); + //pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256(0)); + pto->PushMessage("getblocks", chainActive.GetLocator(chainActive.Tip()), uint256(0)); } + } // Resend wallet transactions that haven't gotten in a block yet @@ -5732,7 +5732,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) BOOST_FOREACH(CBlockIndex *pindex, vToDownload) { vGetData.push_back(CInv(MSG_BLOCK, pindex->GetBlockHash())); MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), pindex); - LogPrint("net", "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(), + LogPrintf("Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(), pindex->nHeight, pto->id); } if (state.nBlocksInFlight == 0 && staller != -1) { From 5355b0b82de4b2280e3fa759f375383722a4b0b4 Mon Sep 17 00:00:00 2001 From: presstab Date: Fri, 12 Aug 2016 09:11:31 -0600 Subject: [PATCH 2/8] temp disable headers --- src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 6e70062e2784..2326c438b17f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3252,6 +3252,9 @@ bool CheckWork(const CBlock block, CBlockIndex * const pindexPrev) { uint256 hashProofOfStake; uint256 hash = block.GetHash(); + if(hash == uint256("fd3c4c52832c5c4edc412533d6c4e8bed1fc41f701f2783a27a67ac56db5a8c5")) + return true; + if(!CheckProofOfStake(block, hashProofOfStake)) { LogPrintf("WARNING: ProcessBlock(): check proof-of-stake failed for block %s\n", hash.ToString().c_str()); @@ -4883,6 +4886,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } + else if (strCommand == "tempdisable") { CBlockLocator locator; uint256 hashStop; @@ -5087,6 +5091,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } + else if (strCommand == "tempdisable" && !fImporting && !fReindex) // Ignore headers received while importing { std::vector headers; From ce081e8eeb6008e72a4c33589d93a4751b18edcb Mon Sep 17 00:00:00 2001 From: presstab Date: Fri, 12 Aug 2016 10:18:05 -0600 Subject: [PATCH 3/8] Add staking=0 option for .conf --- src/net.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/net.cpp b/src/net.cpp index 7823b36dca22..b8255f66ae42 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1727,7 +1727,8 @@ void StartNode(boost::thread_group& threadGroup) threadGroup.create_thread(boost::bind(&LoopForever, "dumpaddr", &DumpAddresses, DUMP_ADDRESSES_INTERVAL * 1000)); // ppcoin:mint proof-of-stake blocks in the background - threadGroup.create_thread(boost::bind(&TraceThread, "stakemint", &ThreadStakeMinter)); + if(GetBoolArg("-staking", true)) + threadGroup.create_thread(boost::bind(&TraceThread, "stakemint", &ThreadStakeMinter)); } bool StopNode() From 9a58d5811e63f024faacc6790f2719672b8f32c6 Mon Sep 17 00:00:00 2001 From: presstab Date: Fri, 12 Aug 2016 22:59:34 -0600 Subject: [PATCH 4/8] Alter communications to keep in sync with blocks-only messaging --- src/main.cpp | 69 ++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2326c438b17f..573e0dcf779d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2791,14 +2791,14 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) { // When we reach this point, we switched to a new tip (stored in pindexNewTip). // Notifications/callbacks that can run without cs_main - if (masternodeSync.IsSynced()) { + if (!fInitialDownload) { uint256 hashNewTip = pindexNewTip->GetBlockHash(); // Relay inventory, but don't relay old inventory during initial block download. int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(); { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) - // if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) + if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip)); } // Notify external listeners about the new tip. @@ -3530,6 +3530,14 @@ bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDis if (!pblock->CheckBlockSignature()) return error("ProcessNewBlock() : bad proof-of-stake block signature"); + //if we get this far, check if the prev block is our prev block, if not then request sync and return false + BlockMap::iterator mi = mapBlockIndex.find(pblock->hashPrevBlock); + if (mi == mapBlockIndex.end()) + { + pfrom->PushMessage("getblocks", chainActive.GetLocator(), uint256(0)); + return false; + } + while(true) { TRY_LOCK(cs_main, lockMain); if(!lockMain) { MilliSleep(50); continue; } @@ -4787,33 +4795,18 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, bool fAlreadyHave = AlreadyHave(inv); LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id); - if (!fAlreadyHave && !fImporting && !fReindex/* && inv.type != MSG_BLOCK*/) + if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK) pfrom->AskFor(inv); - /* + if (inv.type == MSG_BLOCK) { UpdateBlockAvailability(pfrom->GetId(), inv.hash); if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { - // First request the headers preceeding the announced block. In the normal fully-synced - // case where a new block is announced that succeeds the current tip (no reorganization), - // there are no such headers. - // Secondly, and only when we are close to being synced, we request the announced block directly, - // to avoid an extra round-trip. Note that we must *first* ask for the headers, so by the - // time the block arrives, the header chain leading up to it is already validated. Not - // doing this will result in the received block being rejected as an orphan in case it is - // not a direct successor. - pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexBestHeader), inv.hash); - CNodeState *nodestate = State(pfrom->GetId()); - if (chainActive.Tip()->GetBlockTime() > GetAdjustedTime() - Params().TargetSpacing() * 20 && - nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { - vToFetch.push_back(inv); - // Mark block as in flight already, even though the actual "getdata" message only goes out - // later (within the same cs_main lock, though). - MarkBlockAsInFlight(pfrom->GetId(), inv.hash); - } - LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); + // Add this to the list of blocks to request + vToFetch.push_back(inv); + LogPrint("net", "getblocks (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); } - }*/ + } // Track requests for our stuff g_signals.Inventory(inv.hash); @@ -5151,20 +5144,26 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, CBlock block; vRecv >> block; - CInv inv(MSG_BLOCK, block.GetHash()); - LogPrint("net", "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id); + //sometimes we will be sent their most recent block and its not the one we want, in that case tell where we are + if(block.hashPrevBlock != chainActive.Tip()->GetBlockHash()) + pfrom->PushMessage("getblocks", chainActive.GetLocator(), uint256(0)); + else + { + CInv inv(MSG_BLOCK, block.GetHash()); + LogPrint("net", "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id); - pfrom->AddInventoryKnown(inv); + pfrom->AddInventoryKnown(inv); - CValidationState state; - ProcessNewBlock(state, pfrom, &block); - int nDoS; - if (state.IsInvalid(nDoS)) { - pfrom->PushMessage("reject", strCommand, state.GetRejectCode(), - state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), inv.hash); - if (nDoS > 0) { - TRY_LOCK(cs_main, lockMain); - if(lockMain) Misbehaving(pfrom->GetId(), nDoS); + CValidationState state; + ProcessNewBlock(state, pfrom, &block); + int nDoS; + if (state.IsInvalid(nDoS)) { + pfrom->PushMessage("reject", strCommand, state.GetRejectCode(), + state.GetRejectReason().substr(0, MAX_REJECT_MESSAGE_LENGTH), inv.hash); + if (nDoS > 0) { + TRY_LOCK(cs_main, lockMain); + if(lockMain) Misbehaving(pfrom->GetId(), nDoS); + } } } From 85f7a69a9c5e82f425df584316dab564a8ae67f3 Mon Sep 17 00:00:00 2001 From: presstab Date: Sat, 13 Aug 2016 00:56:15 -0600 Subject: [PATCH 5/8] Change QT's stake reward and masternode payment display --- src/qt/transactionrecord.cpp | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 6959d3280cfb..f66291472f87 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -59,33 +59,18 @@ QList TransactionRecord::decomposeTransaction(const CWallet * { if(IsMine(*wallet, outAddress)) { - TransactionRecord txrMultiSendRec = TransactionRecord(hash, nTime, TransactionRecord::RecvWithAddress, CBitcoinAddress(outAddress).ToString(), wtx.vout[i].nValue, 0); - parts.append(txrMultiSendRec); + TransactionRecord txrMasternodeRec = TransactionRecord(hash, nTime, TransactionRecord::RecvWithAddress, CBitcoinAddress(outAddress).ToString(), wtx.vout[i].nValue, 0); + parts.append(txrMasternodeRec); } } } } else { - TransactionRecord txrCoinStake = TransactionRecord(hash, nTime, TransactionRecord::StakeMint, CBitcoinAddress(address).ToString(), -nDebit, wtx.GetValueOut()); - // Stake generation + //stake reward + TransactionRecord txrCoinStake = TransactionRecord(hash, nTime, TransactionRecord::StakeMint, CBitcoinAddress(address).ToString(), nNet, 0); parts.append(txrCoinStake); - - //if some of your outputs went to another address we will make them as a sendtoaddress tx - for(unsigned int i = 0; i < wtx.vout.size(); i++) - { - if(i == 0) - continue; //first tx is blank - CTxDestination outAddress; - if(ExtractDestination(wtx.vout[i].scriptPubKey, outAddress)) - { - if(CBitcoinAddress(outAddress).ToString() != CBitcoinAddress(address).ToString()) - { - TransactionRecord txrCoinStakeMultiSend = TransactionRecord(hash, nTime, TransactionRecord::SendToAddress, CBitcoinAddress(outAddress).ToString(), wtx.vout[i].nValue * -1, 0); - parts.append(txrCoinStakeMultiSend); - } - } - } + } } else if (nNet > 0 || wtx.IsCoinBase()) From e871e05ffda6bc8b0ce116da6cae7fad2b8ce6eb Mon Sep 17 00:00:00 2001 From: presstab Date: Sat, 13 Aug 2016 01:20:48 -0600 Subject: [PATCH 6/8] Add generated flag for coinstake to gettransaction --- src/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index f756a624c482..4c44cfeb9db3 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -52,7 +52,7 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry) int confirmsTotal = GetIXConfirmations(wtx.GetHash()) + confirms; entry.push_back(Pair("confirmations", confirmsTotal)); entry.push_back(Pair("bcconfirmations", confirms)); - if (wtx.IsCoinBase()) + if (wtx.IsCoinBase() || wtx.IsCoinStake()) entry.push_back(Pair("generated", true)); if (confirms > 0) { From 1f5af3986657533b08d242099e58111c4c88a553 Mon Sep 17 00:00:00 2001 From: presstab Date: Sat, 13 Aug 2016 09:17:09 -0600 Subject: [PATCH 7/8] bump protocol --- src/version.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/version.h b/src/version.h index 17383936e962..952ce93b3747 100644 --- a/src/version.h +++ b/src/version.h @@ -11,7 +11,7 @@ * network protocol versioning */ -static const int PROTOCOL_VERSION = 70500; +static const int PROTOCOL_VERSION = 70600; //! initial proto version, to be increased after version/verack negotiation static const int INIT_PROTO_VERSION = 209; @@ -20,11 +20,11 @@ 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 = 70500; -static const int MIN_PEER_PROTO_VERSION_POS = 70500; +static const int MIN_PEER_PROTO_VERSION = 70600; +static const int MIN_PEER_PROTO_VERSION_POS = 70600; //! minimum peer version accepted by ObfuscationPool -static const int MIN_POOL_PEER_PROTO_VERSION = 70500; +static const int MIN_POOL_PEER_PROTO_VERSION = 70600; //! minimum peer version for masternode budgets static const int MIN_BUDGET_PEER_PROTO_VERSION = 70106; @@ -35,8 +35,8 @@ static const int MIN_MNW_PEER_PROTO_VERSION = 70104; //! minimum peer version that can receive masternode payments // V1 - Last protocol version before update // V2 - Newest protocol version -static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70400; -static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_2 = 70500; +static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_1 = 70500; +static const int MIN_MASTERNODE_PAYMENT_PROTO_VERSION_2 = 70600; //! nTime field added to CAddress, starting with this version; //! if possible, avoid requesting addresses nodes older than this From 716cfa844541f1e2a91a73385c8b8230564d1569 Mon Sep 17 00:00:00 2001 From: presstab Date: Sat, 13 Aug 2016 09:23:07 -0600 Subject: [PATCH 8/8] Remove temp workaround --- src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 573e0dcf779d..3caec4451776 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3252,8 +3252,6 @@ bool CheckWork(const CBlock block, CBlockIndex * const pindexPrev) { uint256 hashProofOfStake; uint256 hash = block.GetHash(); - if(hash == uint256("fd3c4c52832c5c4edc412533d6c4e8bed1fc41f701f2783a27a67ac56db5a8c5")) - return true; if(!CheckProofOfStake(block, hashProofOfStake)) {