Skip to content

Commit

Permalink
Add missing znode inventory. Fix payment and add check coinbase TX
Browse files Browse the repository at this point in the history
  • Loading branch information
sn-ntu committed Nov 28, 2017
1 parent 171b2b1 commit 245cc6d
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 110 deletions.
6 changes: 3 additions & 3 deletions ZNODE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Prerequisites
-------------
- Ubuntu 16.04+
- Libraries to build from zcoin source
- Port 18618 is open
- Port **18618** is open

Step 1. Build
----------------------
Expand All @@ -17,11 +17,11 @@ Step 1. Build

**1.2.** See [README.md](README.md) for instructions on building.

Step 2. (Optional - only if firewall is running). Open port 18618
Step 2. (Optional - only if firewall is running). Open port 28618
----------------------
**2.1.** Run:

sudo ufw allow 18618
sudo ufw allow 28618
sudo ufw default allow outgoing
sudo ufw enable

Expand Down
6 changes: 3 additions & 3 deletions src/activeznode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ void CActiveZnode::ManageStateInitial() {
CKey keyCollateral;

// If collateral is found switch to LOCAL mode
// if (pwalletMain->GetZnodeVinAndKeys(vin, pubKeyCollateral, keyCollateral)) {
// eType = ZNODE_LOCAL;
// }
if (pwalletMain->GetZnodeVinAndKeys(vin, pubKeyCollateral, keyCollateral)) {
eType = ZNODE_LOCAL;
}

LogPrint("znode", "CActiveZnode::ManageStateInitial -- End status = %s, type = %s, pinger enabled = %d\n",
GetStatus(), GetTypeString(), fPingerEnabled);
Expand Down
1 change: 1 addition & 0 deletions src/consensus/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static const unsigned char PUBCOIN_NOT_VALIDATE = 0x46;
static const unsigned char NSEQUENCE_INCORRECT = 0x47;
static const unsigned char PUBLIC_COIN_FOR_ACCUMULATOR_INVALID = 0x48;
static const unsigned char NO_MINT_ZEROCOIN = 0x49;
static const unsigned char REJECT_INVALID_ZNODE_PAYMENT = 0x50;

/** Capture information about block/transaction validation */
class CValidationState {
Expand Down
51 changes: 45 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,8 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &state, uint256 h
bool found_3 = false;
bool found_4 = false;
bool found_5 = false;
int total_payment_tx = 0;
bool found_znode_payment = true; // no more than 1 output for payment

CScript FOUNDER_1_SCRIPT;
CScript FOUNDER_2_SCRIPT;
Expand Down Expand Up @@ -1411,8 +1413,7 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &state, uint256 h
FOUNDER_5_SCRIPT = GetScriptForDestination(CBitcoinAddress("TTtLk1iapn8QebamQcb8GEh1MNq8agYcVk").Get());
}

BOOST_FOREACH(
const CTxOut &output, tx.vout) {
BOOST_FOREACH(const CTxOut &output, tx.vout) {
if (output.scriptPubKey == FOUNDER_1_SCRIPT && output.nValue == (int64_t)(2 * COIN)) {
found_1 = true;
}
Expand All @@ -1430,6 +1431,7 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &state, uint256 h
}
}
} else if (!fTestNet || nHeight >= Params().GetConsensus().nZnodePaymentsStartBlock) {

if (!fTestNet && GetAdjustedTime() > nStartRewardTime) {
FOUNDER_1_SCRIPT = GetScriptForDestination(CBitcoinAddress("aCAgTPgtYcA4EysU4UKC86EQd5cTtHtCcr").Get());
if (nHeight < 14000) {
Expand All @@ -1453,21 +1455,32 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &state, uint256 h
FOUNDER_5_SCRIPT = GetScriptForDestination(CBitcoinAddress("TTtLk1iapn8QebamQcb8GEh1MNq8agYcVk").Get());
}

CAmount znodePayment = GetZnodePayment(nHeight);
BOOST_FOREACH(const CTxOut &output, tx.vout) {
if (output.scriptPubKey == FOUNDER_1_SCRIPT && output.nValue == (int64_t)(1 * COIN)) {
found_1 = true;
continue;
}
if (output.scriptPubKey == FOUNDER_2_SCRIPT && output.nValue == (int64_t)(1 * COIN)) {
found_2 = true;
continue;
}
if (output.scriptPubKey == FOUNDER_3_SCRIPT && output.nValue == (int64_t)(1 * COIN)) {
found_3 = true;
continue;
}
if (output.scriptPubKey == FOUNDER_4_SCRIPT && output.nValue == (int64_t)(1 * COIN)) {
found_4 = true;
continue;
}
if (output.scriptPubKey == FOUNDER_5_SCRIPT && output.nValue == (int64_t)(3 * COIN)) {
found_5 = true;
continue;
}
if (znodePayment != output.nValue) {
found_znode_payment = false;
} else {
total_payment_tx = total_payment_tx + 1;
}
}
}
Expand All @@ -1476,6 +1489,11 @@ bool CheckTransaction(const CTransaction &tx, CValidationState &state, uint256 h
return state.DoS(100, false, REJECT_FOUNDER_REWARD_MISSING,
"CTransaction::CheckTransaction() : founders reward missing");
}

if (!found_znode_payment || total_payment_tx > 1) {
return state.DoS(100, false, REJECT_INVALID_ZNODE_PAYMENT,
"CTransaction::CheckTransaction() : invalid znode payment");
}
}
} else {
BOOST_FOREACH(const CTxIn &txin, tx.vin)
Expand Down Expand Up @@ -3640,7 +3658,7 @@ CAmount GetZnodePayment(int nHeight, CAmount blockValue) {
// if (nHeight > nMNPIBlock + (nMNPIPeriod * 6)) ret += blockValue / 40; // 261680 - 45.0% - 2015-05-01
// if (nHeight > nMNPIBlock + (nMNPIPeriod * 7)) ret += blockValue / 40; // 278960 - 47.5% - 2015-06-01
// if (nHeight > nMNPIBlock + (nMNPIPeriod * 9)) ret += blockValue / 40; // 313520 - 50.0% - 2015-08-03
CAmount ret = 15; //15XZC
CAmount ret = 15 * COIN; //15XZC

return ret;
}
Expand Down Expand Up @@ -8005,14 +8023,14 @@ bool SendMessages(CNode *pto) {
//
// Message: inventory
//
vector <CInv> vInv;
vector<CInv> vInv;
vector<CInv> vInvWait;
{
LOCK(pto->cs_inventory);
vInv.reserve(std::max<size_t>(pto->vInventoryBlockToSend.size(), INVENTORY_BROADCAST_MAX));

// Add blocks
BOOST_FOREACH(
const uint256 &hash, pto->vInventoryBlockToSend) {
BOOST_FOREACH(const uint256 &hash, pto->vInventoryBlockToSend) {
vInv.push_back(CInv(MSG_BLOCK, hash));
if (vInv.size() == MAX_INV_SZ) {
pto->PushMessage(NetMsgType::INV, vInv);
Expand Down Expand Up @@ -8134,6 +8152,27 @@ bool SendMessages(CNode *pto) {
}
}
}
// vInventoryToSend from dash
{
LOCK(pto->cs_inventory);
vInv.reserve(std::min<size_t>(1000, pto->vInventoryToSend.size()));
vInvWait.reserve(pto->vInventoryToSend.size());
BOOST_FOREACH(const CInv& inv, pto->vInventoryToSend)
{
pto->filterInventoryKnown.insert(inv.hash);

LogPrintf("SendMessages -- queued inv: %s index=%d peer=%d\n", inv.ToString(), vInv.size(), pto->id);
vInv.push_back(inv);
if (vInv.size() >= 1000)
{
LogPrintf("SendMessages -- pushing inv's: count=%d peer=%d\n", vInv.size(), pto->id);
pto->PushMessage(NetMsgType::INV, vInv);
vInv.clear();
}
}
pto->vInventoryToSend = vInvWait;
}

if (!vInv.empty())
pto->PushMessage(NetMsgType::INV, vInv);

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ int GetUTXOHeight(const COutPoint& outpoint);
int GetInputAge(const CTxIn &txin);
int GetInputAgeIX(const uint256 &nTXHash, const CTxIn &txin);
int GetIXConfirmations(const uint256 &nTXHash);
CAmount GetZnodePayment(int nHeight, CAmount blockValue);
CAmount GetZnodePayment(int nHeight, CAmount blockValue = 50 * COIN);

/** Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) */
bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
Expand Down
4 changes: 3 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ CBlockTemplate* BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
// Update coinbase transaction with additional info about masternode and governance payments,
// get some info back to pass to getblocktemplate
if (nHeight >= chainparams.GetConsensus().nZnodePaymentsStartBlock) {
FillBlockPayments(coinbaseTx, nHeight, blockReward, pblock->txoutZnode, pblock->voutSuperblock);
CAmount znodePayment = GetZnodePayment(nHeight, blockReward);
FillBlockPayments(coinbaseTx, nHeight, znodePayment, pblock->txoutZnode, pblock->voutSuperblock);
coinbaseTx.vout[0].nValue -= znodePayment;
}

nLastBlockTx = nBlockTx;
Expand Down
1 change: 0 additions & 1 deletion src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class BlockAssembler
BlockAssembler(const CChainParams& chainparams);
/** Construct a new block template with coinbase to scriptPubKeyIn */
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
CBlockTemplate* CreateNewBlock_(const CScript& scriptPubKeyIn);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);

private:
Expand Down
5 changes: 4 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,8 +2102,11 @@ void RelayInv(CInv &inv, const int minProtoVersion) {
LogPrintf("RelayInv, vNodes.size()=%s\n", vNodes.size());
BOOST_FOREACH(CNode * pnode, vNodes)
{
if (pnode->nVersion >= minProtoVersion)
LogPrintf("pnode->nVersion=%s\n", pnode->nVersion);
LogPrintf("minProtoVersion=%s\n", minProtoVersion);
if (pnode->nVersion >= minProtoVersion) {
pnode->PushInventory(inv);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class CNode

// inventory based relay
CRollingBloomFilter filterInventoryKnown;
std::vector<CInv> vInventoryToSend;
// Set of transaction ids we still have to announce.
// They are sorted by the mempool before relay, so the order is not important.
std::set<uint256> setInventoryTxToSend;
Expand Down Expand Up @@ -555,6 +556,8 @@ class CNode
}
} else if (inv.type == MSG_BLOCK) {
vInventoryBlockToSend.push_back(inv.hash);
} else {
vInventoryToSend.push_back(inv);
}
}

Expand Down
103 changes: 34 additions & 69 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ namespace NetMsgType {
const char *ZNODEPAYMENTVOTE = "mnw";
const char *ZNODEPAYMENTBLOCK = "mnwb";
const char *ZNODEPAYMENTSYNC = "mnget";
const char *MNBUDGETSYNC = "mnvs"; // depreciated since 12.1
const char *MNBUDGETVOTE = "mvote"; // depreciated since 12.1
const char *MNBUDGETPROPOSAL = "mprop"; // depreciated since 12.1
const char *MNBUDGETFINAL = "fbs"; // depreciated since 12.1
const char *MNBUDGETFINALVOTE = "fbvote"; // depreciated since 12.1
const char *MNQUORUM = "mn quorum"; // not implemented
const char *MNANNOUNCE = "mnb";
const char *MNPING = "mnp";
const char *DSACCEPT = "dsa";
Expand All @@ -66,34 +60,10 @@ namespace NetMsgType {
const char *DSQUEUE = "dsq";
const char *DSEG = "dseg";
const char *SYNCSTATUSCOUNT = "ssc";
const char *MNGOVERNANCESYNC = "govsync";
const char *MNGOVERNANCEOBJECT = "govobj";
const char *MNGOVERNANCEOBJECTVOTE = "govobjvote";
const char *MNVERIFY = "mnv";
const char *TXLOCKREQUEST = "ix";

};
static const char *ppszTypeName[] =
{
"ERROR", // Should never occur
NetMsgType::TX,
NetMsgType::BLOCK,
"filtered block", // Should never occur
// Dash message types
// NOTE: include non-implmented here, we must keep this list in sync with enum in protocol.h
NetMsgType::TXLOCKREQUEST,
NetMsgType::TXLOCKVOTE,
NetMsgType::SPORK,
NetMsgType::ZNODEPAYMENTVOTE,
NetMsgType::ZNODEPAYMENTBLOCK, // reusing, was MNSCANERROR previousely, was NOT used in 12.0, we need this for inv
NetMsgType::MNQUORUM, // not implemented
NetMsgType::MNANNOUNCE,
NetMsgType::MNPING,
NetMsgType::DSTX,
NetMsgType::MNGOVERNANCEOBJECT,
NetMsgType::MNGOVERNANCEOBJECTVOTE,
NetMsgType::MNVERIFY,
};

/** All known message types. Keep this in the same order as the list of
* messages above and in protocol.h.
Expand Down Expand Up @@ -143,9 +113,6 @@ const static std::string allNetMessageTypes[] = {
NetMsgType::DSQUEUE,
NetMsgType::DSEG,
NetMsgType::SYNCSTATUSCOUNT,
NetMsgType::MNGOVERNANCESYNC,
NetMsgType::MNGOVERNANCEOBJECT,
NetMsgType::MNGOVERNANCEOBJECTVOTE,
NetMsgType::MNVERIFY,

};
Expand Down Expand Up @@ -220,52 +187,50 @@ CInv::CInv(int typeIn, const uint256 &hashIn) {
hash = hashIn;
}

CInv::CInv(const std::string &strType, const uint256 &hashIn) {
unsigned int i;
for (i = 1; i < ARRAYLEN(ppszTypeName); i++) {
if (strType == ppszTypeName[i]) {
type = i;
break;
}
}
if (i == ARRAYLEN(ppszTypeName))
throw std::out_of_range(strprintf("CInv::CInv(string, uint256): unknown type '%s'", strType));
hash = hashIn;
}

bool operator<(const CInv &a, const CInv &b) {
return (a.type < b.type || (a.type == b.type && a.hash < b.hash));
}

//bool CInv::IsKnownType() const {
// return (type >= 1 && type < (int) ARRAYLEN(ppszTypeName));
//}

const char* CInv::GetCommand() const
{
std::string cmd;
LogPrintf("type=%s\n", type);
if (type & MSG_WITNESS_FLAG)
cmd.append("witness-");
int masked = type & MSG_TYPE_MASK;
switch (masked)
// int masked = type & MSG_TYPE_MASK;
// LogPrintf("masked=%s\n", masked);
// LogPrintf("MSG_TX=%s\n", MSG_TX);
// LogPrintf("MSG_BLOCK=%s\n", MSG_BLOCK);
// LogPrintf("MSG_FILTERED_BLOCK=%s\n", MSG_FILTERED_BLOCK);
// LogPrintf("MSG_CMPCT_BLOCK=%s\n", MSG_CMPCT_BLOCK);
// LogPrintf("MSG_TXLOCK_REQUEST=%s\n", MSG_TXLOCK_REQUEST);
// LogPrintf("MSG_TXLOCK_VOTE=%s\n", MSG_TXLOCK_VOTE);
// LogPrintf("MSG_SPORK=%s\n", MSG_SPORK);
// LogPrintf("MSG_ZNODE_PAYMENT_VOTE=%s\n", MSG_ZNODE_PAYMENT_VOTE);
// LogPrintf("MSG_ZNODE_ANNOUNCE=%s\n", MSG_ZNODE_ANNOUNCE);
// LogPrintf("MSG_ZNODE_PING=%s\n", MSG_ZNODE_PING);
// LogPrintf("MSG_DSTX=%s\n", MSG_DSTX);
// LogPrintf("MSG_ZNODE_VERIFY=%s\n", MSG_ZNODE_VERIFY);
switch (type)
{
case MSG_TX: return NetMsgType::TX;
case MSG_BLOCK: return NetMsgType::BLOCK;
case MSG_FILTERED_BLOCK: return NetMsgType::MERKLEBLOCK;
case MSG_CMPCT_BLOCK: return NetMsgType::CMPCTBLOCK;
case MSG_TXLOCK_REQUEST: return NetMsgType::TXLOCKREQUEST;
case MSG_TXLOCK_VOTE: return NetMsgType::TXLOCKVOTE;
case MSG_SPORK: return NetMsgType::SPORK;
case MSG_ZNODE_PAYMENT_VOTE: return NetMsgType::ZNODEPAYMENTVOTE;
case MSG_ZNODE_PAYMENT_BLOCK: return NetMsgType::ZNODEPAYMENTBLOCK;
case MSG_ZNODE_ANNOUNCE: return NetMsgType::MNANNOUNCE;
case MSG_ZNODE_PING: return NetMsgType::MNPING;
case MSG_DSTX: return NetMsgType::DSTX;
case MSG_ZNODE_VERIFY: return NetMsgType::MNVERIFY;
default:
LogPrintf("ERROR - UNKNOWN INV COMMAND");
return NULL;
// throw std::out_of_range(strprintf("CInv::GetCommand(): type=%d unknown type", type));
case MSG_TX: return NetMsgType::TX;
case MSG_BLOCK: return NetMsgType::BLOCK;
case MSG_FILTERED_BLOCK: return NetMsgType::MERKLEBLOCK;
case MSG_CMPCT_BLOCK: return NetMsgType::CMPCTBLOCK;
case MSG_TXLOCK_REQUEST: return NetMsgType::TXLOCKREQUEST;
case MSG_TXLOCK_VOTE: return NetMsgType::TXLOCKVOTE;
case MSG_SPORK: return NetMsgType::SPORK;
case MSG_ZNODE_PAYMENT_VOTE: return NetMsgType::ZNODEPAYMENTVOTE;
case MSG_ZNODE_PAYMENT_BLOCK: return NetMsgType::ZNODEPAYMENTBLOCK;
case MSG_ZNODE_ANNOUNCE: return NetMsgType::MNANNOUNCE;
case MSG_ZNODE_PING: return NetMsgType::MNPING;
case MSG_DSTX: return NetMsgType::DSTX;
case MSG_ZNODE_VERIFY: return NetMsgType::MNVERIFY;
default: {
LogPrintf("ERROR - UNKNOWN INV COMMAND\n");
return NetMsgType::NOTFOUND;
}
// throw std::out_of_range(strprintf("CInv::GetCommand(): type=%d unknown type", type));
}
}

Expand Down
Loading

0 comments on commit 245cc6d

Please sign in to comment.