Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable fundamental node #67

Open
wants to merge 2 commits into
base: update-upstream-v3.2.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/activefundamentalnode.cpp
Expand Up @@ -86,6 +86,12 @@ void CActiveFundamentalnode::ManageStatus()
CKey keyCollateralAddress;

if (GetFundamentalNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress)) {
if(! isVinValidFundamentalNode(vin)) {
status = ACTIVE_FUNDAMENTALNODE_NEW_NODE_DISABLED;
notCapableReason = strprintf("%s", GetStatus());
LogPrintf("CActiveFundamentalnode::ManageStatus() - %s\n", notCapableReason);
return;
}
if (GetInputAge(vin) < FUNDAMENTALNODE_MIN_CONFIRMATIONS) {
status = ACTIVE_FUNDAMENTALNODE_INPUT_TOO_NEW;
notCapableReason = strprintf("%s - %d confirmations", GetStatus(), GetInputAge(vin));
Expand Down Expand Up @@ -151,6 +157,8 @@ std::string CActiveFundamentalnode::GetStatus()
return "Not capable fundamentalnode: " + notCapableReason;
case ACTIVE_FUNDAMENTALNODE_STARTED:
return "Fundamentalnode successfully started";
case ACTIVE_FUNDAMENTALNODE_NEW_NODE_DISABLED:
return "New fundamentalnode is disabled";
default:
return "unknown";
}
Expand Down
1 change: 1 addition & 0 deletions src/activefundamentalnode.h
Expand Up @@ -20,6 +20,7 @@
#define ACTIVE_FUNDAMENTALNODE_INPUT_TOO_NEW 2
#define ACTIVE_FUNDAMENTALNODE_NOT_CAPABLE 3
#define ACTIVE_FUNDAMENTALNODE_STARTED 4
#define ACTIVE_FUNDAMENTALNODE_NEW_NODE_DISABLED 5

// Responsible for activating the Fundamentalnode and pinging the network
class CActiveFundamentalnode
Expand Down
10 changes: 10 additions & 0 deletions src/fundamentalnode-payments.cpp
Expand Up @@ -583,6 +583,11 @@ void CFundamentalnodePayments::ProcessMessageFundamentalnodePayments(CNode* pfro
if (!locked || chainActive.Tip() == NULL) return;
nHeight = chainActive.Tip()->nHeight;
}

if(! isVinValidFundamentalNode(winner.vinFundamentalnode)) {
LogPrint("mnpayments", "fnw - new fundamentalnode is disabled\n");
return;
}

if (fundamentalnodePayments.mapFundamentalnodePayeeVotes.count(winner.GetHash())) {
LogPrint("mnpayments", "fnw - Already seen - %s bestHeight %d\n", winner.GetHash().ToString().c_str(), nHeight);
Expand Down Expand Up @@ -692,6 +697,11 @@ bool CFundamentalnodePayments::IsScheduled(CFundamentalnode& mn, int nNotBlockHe

bool CFundamentalnodePayments::AddWinningFundamentalnode(CFundamentalnodePaymentWinner& winnerIn)
{
if(! isVinValidFundamentalNode(winnerIn.vinFundamentalnode)) {
LogPrint("mnpayments", "AddWinningFundamentalnode - new fundamentalnode is disabled\n");
return false;
}

uint256 blockHash = 0;
if (!GetBlockHash(blockHash, winnerIn.nBlockHeight - 100)) {
return false;
Expand Down
21 changes: 21 additions & 0 deletions src/fundamentalnode.cpp
Expand Up @@ -9,6 +9,7 @@
#include "obfuscation.h"
#include "sync.h"
#include "util.h"
#include "spork.h"

// keep track of the scanning errors I've seen
map<uint256, int> mapSeenFundamentalnodeScanningErrors;
Expand Down Expand Up @@ -56,6 +57,18 @@ bool GetBlockHash(uint256& hash, int nBlockHeight)
return false;
}

bool isVinValidFundamentalNode(CTxIn& vin)
{
if(GetSporkValue(SPORK_25_DISABLE_NEW_FUNDAMENTALNODE) > 0) {
int blockHeight = GetInputHeight(vin);
if(blockHeight < 0 || blockHeight > GetSporkValue(SPORK_25_DISABLE_NEW_FUNDAMENTALNODE)) {
return false;
}
}

return true;
}

CFundamentalnode::CFundamentalnode()
{
LOCK(cs);
Expand Down Expand Up @@ -572,6 +585,14 @@ bool CFundamentalnodeBroadcast::CheckInputsAndAdd(int& nDoS)
// incorrect ping or its sigTime
if(lastPing == CFundamentalnodePing() || !lastPing.CheckAndUpdate(nDoS, false, true)) return false;

if(GetSporkValue(SPORK_25_DISABLE_NEW_FUNDAMENTALNODE) > 0) {
int blockHeight = GetInputHeight(vin);
if(blockHeight < 0 || blockHeight > GetSporkValue(SPORK_25_DISABLE_NEW_FUNDAMENTALNODE)) {
LogPrintf("CheckInputsAndAdd: New fundamentalnode is disabled \n");
return false;
}
}

// search existing Fundamentalnode list
CFundamentalnode* pmn = mnodeman.Find(vin);

Expand Down
1 change: 1 addition & 0 deletions src/fundamentalnode.h
Expand Up @@ -33,6 +33,7 @@ class CFundamentalnodePing;
extern map<int64_t, uint256> mapCacheBlockHashes;

bool GetBlockHash(uint256& hash, int nBlockHeight);
bool isVinValidFundamentalNode(CTxIn& vin);


//
Expand Down
19 changes: 19 additions & 0 deletions src/main.cpp
Expand Up @@ -910,6 +910,25 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
return nSigOps;
}

int GetInputHeight(CTxIn& vin)
{
CCoinsView viewDummy;
CCoinsViewCache view(&viewDummy);
{
LOCK(mempool.cs);
CCoinsViewMemPool viewMempool(pcoinsTip, mempool);
view.SetBackend(viewMempool); // temporarily switch cache backend to db+mempool view

const CCoins* coins = view.AccessCoins(vin.prevout.hash);

if (coins && coins->nHeight >= 0) {
return coins->nHeight;
}

return -1;
}
}

int GetInputAge(CTxIn& vin)
{
CCoinsView viewDummy;
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Expand Up @@ -268,6 +268,7 @@ bool AcceptableInputs(CTxMemPool& pool, CValidationState& state, const CTransact

bool AcceptableFundamentalTxn(CTxMemPool& pool, CValidationState& state, const CTransaction& tx);

int GetInputHeight(CTxIn& vin);
int GetInputAge(CTxIn& vin);
int GetInputAgeIX(uint256 nTXHash, CTxIn& vin);
int GetIXConfirmations(uint256 nTXHash);
Expand Down
5 changes: 5 additions & 0 deletions src/rpcfundamentalnode.cpp
Expand Up @@ -15,6 +15,7 @@
#include "fundamentalnodeman.h"
#include "rpcserver.h"
#include "utilmoneystr.h"
#include "spork.h"

#include "masternode-pos.h"
#include "masternodeconfig.h"
Expand Down Expand Up @@ -1437,6 +1438,10 @@ UniValue startfundamentalnode (const UniValue& params, bool fHelp)

UniValue createfundamentalnodekey (const UniValue& params, bool fHelp)
{
if(GetSporkValue(SPORK_25_DISABLE_NEW_FUNDAMENTALNODE) > 0) {
throw runtime_error("Fundamental node creation is disabled.");
}

if (fHelp || (params.size() != 0))
throw runtime_error(
"createfundamentalnodekey\n"
Expand Down
3 changes: 3 additions & 0 deletions src/spork.cpp
Expand Up @@ -141,6 +141,7 @@ int64_t GetSporkValue(int nSporkID)
if (nSporkID == SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES) r = SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES_DEFAULT;
if (nSporkID == SPORK_20_ZEROCOIN_MAINTENANCE_MODE) r = SPORK_20_ZEROCOIN_MAINTENANCE_MODE_DEFAULT;
if (nSporkID == SPORK_21_MASTERNODE_PAY_UPDATED_NODES) r = SPORK_21_MASTERNODE_PAY_UPDATED_NODES_DEFAULT;
if (nSporkID == SPORK_25_DISABLE_NEW_FUNDAMENTALNODE) r = SPORK_25_DISABLE_NEW_FUNDAMENTALNODE_DEFAULT;

if (r == -1) LogPrintf("%s : Unknown Spork %d\n", __func__, nSporkID);
}
Expand Down Expand Up @@ -293,6 +294,7 @@ int CSporkManager::GetSporkIDByName(std::string strName)
if (strName == "SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES") return SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES;
if (strName == "SPORK_20_ZEROCOIN_MAINTENANCE_MODE") return SPORK_20_ZEROCOIN_MAINTENANCE_MODE;
if (strName == "SPORK_21_MASTERNODE_PAY_UPDATED_NODES") return SPORK_21_MASTERNODE_PAY_UPDATED_NODES;
if (strName == "SPORK_25_DISABLE_NEW_FUNDAMENTALNODE") return SPORK_25_DISABLE_NEW_FUNDAMENTALNODE;

return -1;
}
Expand All @@ -315,6 +317,7 @@ std::string CSporkManager::GetSporkNameByID(int id)
if (id == SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES) return "SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES";
if (id == SPORK_20_ZEROCOIN_MAINTENANCE_MODE) return "SPORK_20_ZEROCOIN_MAINTENANCE_MODE";
if (id == SPORK_21_MASTERNODE_PAY_UPDATED_NODES) return "SPORK_21_MASTERNODE_PAY_UPDATED_NODES";
if (id == SPORK_25_DISABLE_NEW_FUNDAMENTALNODE) return "SPORK_25_DISABLE_NEW_FUNDAMENTALNODE";

return "Unknown";
}
4 changes: 3 additions & 1 deletion src/spork.h
Expand Up @@ -28,7 +28,7 @@ using namespace boost;
Sporks 11,12, and 16 to be removed with 1st zerocoin release
*/
#define SPORK_START 10001
#define SPORK_END 10021
#define SPORK_END 10022

#define SPORK_2_SWIFTTX 10001
#define SPORK_3_SWIFTTX_BLOCK_FILTERING 10002
Expand All @@ -48,6 +48,7 @@ using namespace boost;
#define SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES 10018
#define SPORK_20_ZEROCOIN_MAINTENANCE_MODE 10019
#define SPORK_21_MASTERNODE_PAY_UPDATED_NODES 10020
#define SPORK_25_DISABLE_NEW_FUNDAMENTALNODE 10021

#define SPORK_2_SWIFTTX_DEFAULT 978307200 //2001-1-1
#define SPORK_3_SWIFTTX_BLOCK_FILTERING_DEFAULT 1424217600 //2015-2-18
Expand All @@ -66,6 +67,7 @@ using namespace boost;
#define SPORK_19_FUNDAMENTALNODE_PAY_UPDATED_NODES_DEFAULT 4070908800 //OFF
#define SPORK_20_ZEROCOIN_MAINTENANCE_MODE_DEFAULT 4070908800 //OFF
#define SPORK_21_MASTERNODE_PAY_UPDATED_NODES_DEFAULT 4070908800 //OFF
#define SPORK_25_DISABLE_NEW_FUNDAMENTALNODE_DEFAULT 0 //OFF, 0 if off, other value is the block height

class CSporkMessage;
class CSporkManager;
Expand Down