Skip to content

Commit

Permalink
1.4.0.4-TestNet Mandatory Upgrade
Browse files Browse the repository at this point in the history
- Enhance ABN mining (allow miner to sleep if block is not late and ABN
is insufficient, ensure all miners wake up when blocks are late)
- Enable daily superblock logic
  • Loading branch information
biblepay committed Mar 28, 2019
1 parent 5ad80e2 commit 29c6cd8
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 27 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 4)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 3)
define(_CLIENT_VERSION_BUILD, 4)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2018)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand All @@ -13,7 +13,7 @@ AC_CONFIG_SRCDIR([src/validation.cpp])
AC_CONFIG_HEADERS([src/config/biblepay-config.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux/m4])

BITCOIN_DAEMON_NAME=biblepayd
BITCOIN_GUI_NAME=biblepay-qt
BITCOIN_CLI_NAME=biblepay-cli
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const std::string CLIENT_NAME("BiblePay Core");
const int BIBLEPAY_VERSION_MAJOR = 1;
const int BIBLEPAY_VERSION_MINOR = 4;
const int BIBLEPAY_VERSION_REVISION = 0;
const int BIBLEPAY_VERSION_BUILD = 3;
const int BIBLEPAY_VERSION_BUILD = 4;


const int BIBLE_VERSION = 1000000 * BIBLEPAY_VERSION_MAJOR
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define CLIENT_VERSION_MAJOR 1
#define CLIENT_VERSION_MINOR 4
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 3
#define CLIENT_VERSION_BUILD 4

//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
4 changes: 3 additions & 1 deletion src/governance-classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ bool CSuperblockManager::IsSuperblockTriggered(int nBlockHeight)

bool CSuperblockManager::GetBestSuperblock(CSuperblock_sptr& pSuperblockRet, int nBlockHeight)
{
if (!CSuperblock::IsValidBlockHeight(nBlockHeight) && !CSuperblock::IsSmartContract(nBlockHeight)) {
if (!CSuperblock::IsValidBlockHeight(nBlockHeight) && !CSuperblock::IsSmartContract(nBlockHeight))
{
LogPrintf("**GETBESTSUPERBLOCK::HEIGHT %f, Not a valid superblock height**", nBlockHeight);
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blo
bool allowSuperblockAndMNReward = deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight);

// don't allow payments to superblocks AND masternodes before spork15 activation
// BIBLEPAY NOTE: This means that before spork15, the sanctuary does not receive a payment at the superblock height, but after spork15, both the sanc and the superblock payments are included in the block
if (!voutSuperblockPaymentsRet.empty() && !allowSuperblockAndMNReward) {
txNew.vout.insert(txNew.vout.end(), voutSuperblockPaymentsRet.begin(), voutSuperblockPaymentsRet.end());
return;
Expand Down
34 changes: 32 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,25 @@ bool PeersExist()
return (iConCount > 0);
}

bool LateBlock(CBlock block)
{
// After 60 minutes, we no longer require the anti-bot-net weight (prevent the chain from freezing)
int64_t nAge = GetAdjustedTime() - block.GetBlockTime();
return nAge > (60 * 60) ? true : false;
}

bool IsMyABNSufficient(CBlock block, int nHeight)
{
const Consensus::Params& consensusParams = Params().GetConsensus();
double nMinRequiredABNWeight = GetSporkDouble("requiredabnweight", 0);
if (nHeight > consensusParams.ABNHeight && nMinRequiredABNWeight > 0 && !LateBlock(block))
{
double nABNWeight = GetABNWeight(block, true);
if (nABNWeight < nMinRequiredABNWeight) return false;
}
return true;
}

void static BibleMiner(const CChainParams& chainparams, int iThreadID, int iFeatureSet)
{
LogPrintf("BibleMiner -- started thread %f \n", (double)iThreadID);
Expand Down Expand Up @@ -1055,7 +1074,10 @@ void static BibleMiner(const CChainParams& chainparams, int iThreadID, int iFeat
LogPrint("miner", "No block to mine %f", iThreadID);
goto recover;
}
CBlock *pblock = &pblocktemplate->block;
CBlock *pblock = &pblocktemplate->block;
bool bABNOK = IsMyABNSufficient(pblocktemplate->block, pindexPrev->nHeight);
LogPrintf(" ABN OK: %f ", (double)bABNOK);

IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
nHashesDone++;
UpdateHashesPerSec(nHashesDone);
Expand Down Expand Up @@ -1151,6 +1173,8 @@ void static BibleMiner(const CChainParams& chainparams, int iThreadID, int iFeat
}
if (dMinerSleep > 0)
MilliSleep(dMinerSleep);
if (!bABNOK)
MilliSleep(1000); // ABN not sufficient; sleep unless block becomes late
}

// 0x4FFF is approximately 20 seconds, then we update hashmeter
Expand All @@ -1165,7 +1189,13 @@ void static BibleMiner(const CChainParams& chainparams, int iThreadID, int iFeat
boost::this_thread::interruption_point();
// Regtest mode doesn't require peers
iOuterLoop++;

if (!bABNOK)
{
MilliSleep(5000);
break; // Allow them to try to create a new block (the 5 second sleep is to ensure that we don't hit the user with too many new ABN transactions per minute.
// NOTE: If the block is Late (> 60 mins old), bABNOK will be true (meaning they can mine at full speed during a late block)
}

if (fPoolMiningMode && (!sPoolMiningAddress.empty()) && ((GetAdjustedTime() - nLastReadyToMine) > POOL_MAX_MINUTES))
{
LogPrint("miner", "Pool mining hard block; checking for new work; \n");
Expand Down
7 changes: 6 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
result.push_back(Pair("subsidy", block.vtx[0]->vout[0].nValue/COIN));
result.push_back(Pair("anti-botnet-weight", GetABNWeight(block)));
result.push_back(Pair("anti-botnet-weight", GetABNWeight(block, false)));
result.push_back(Pair("blockversion", GetBlockVersion(block.vtx[0]->vout[0].sTxOutMessage)));
if (block.vtx.size() > 1)
result.push_back(Pair("sanctuary_reward", block.vtx[0]->vout[1].nValue/COIN));
Expand Down Expand Up @@ -1850,6 +1850,11 @@ UniValue exec(const JSONRPCRequest& request)
results.push_back(Pair("next_superblock", iNextSuperblock));
bool fTriggered = CSuperblockManager::IsSuperblockTriggered(iNextSuperblock);
results.push_back(Pair("next_superblock_triggered", fTriggered));

std::string sReqPay = CSuperblockManager::GetRequiredPaymentsString(iNextSuperblock);
results.push_back(Pair("next_superblock_req_payments", sReqPay));


/* QT (Reserved)
std::string sSig = SignPrice(".01");
bool fSigValid = VerifyDarkSendSigner(sSig);
Expand Down
12 changes: 10 additions & 2 deletions src/rpcpog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2801,14 +2801,22 @@ CWalletTx CreateAntiBotNetTx(CBlockIndex* pindexLast, double nMinCoinAge, CReser
return wtx;
}

double GetABNWeight(const CBlock& block)
double GetABNWeight(const CBlock& block, bool fMining)
{
if (block.vtx.size() < 1) return 0;
std::string sMsg = GetTransactionMessage(block.vtx[0]);
int nABNLocator = (int)cdbl(ExtractXML(sMsg, "<abnlocator>", "</abnlocator>"), 0);
if (block.vtx.size() < nABNLocator) return 0;
CTransactionRef tx = block.vtx[nABNLocator];
CBlockIndex* pindex = mapBlockIndex[block.GetHash()];
CBlockIndex* pindex;
if (!fMining)
{
pindex = mapBlockIndex[block.GetHash()];
}
else
{
pindex=chainActive.Tip();
}
if (!pindex) return 0;
double dWeight = GetAntiBotNetWeight(pindex, tx);
return dWeight;
Expand Down
2 changes: 1 addition & 1 deletion src/rpcpog.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ std::string GetTransactionMessage(CTransactionRef tx);
bool AdvertiseChristianPublicKeypair(std::string sProjectId, std::string sNickName, bool fUnJoin, bool fForce, std::string &sError);
CWalletTx CreateAntiBotNetTx(CBlockIndex* pindexLast, double nMinCoinAge, CReserveKey& reservekey, std::string& sXML, std::string& sError);
double GetAntiBotNetWeight(CBlockIndex* pindex, CTransactionRef tx);
double GetABNWeight(const CBlock& block);
double GetABNWeight(const CBlock& block, bool fMining);
std::map<std::string, std::string> GetSporkMap(std::string sPrimaryKey, std::string sSecondaryKey);
std::map<std::string, CPK> GetGSCMap(std::string sGSCObjType, std::string sSearch, bool fRequireSig);
void WriteCacheDouble(std::string sKey, double dValue);
Expand Down
22 changes: 9 additions & 13 deletions src/smartcontract-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ bool VoteForGobject(uint256 govobj, std::string sVoteOutcome, std::string& sErro
vote_outcome_enum_t eVoteOutcome = CGovernanceVoting::ConvertVoteOutcome(sVoteOutcome);
int nSuccessful = 0;
int nFailed = 0;
uint256 hash;
int govObjType;
{
LOCK(governance.cs);
CGovernanceObject *pGovObj = governance.FindGovernanceObject(hash);
CGovernanceObject *pGovObj = governance.FindGovernanceObject(govobj);
if (!pGovObj)
{
sError = "Governance object not found";
Expand All @@ -115,7 +114,7 @@ bool VoteForGobject(uint256 govobj, std::string sVoteOutcome, std::string& sErro
return false;
}

CGovernanceVote vote(mn.outpoint, hash, eVoteSignal, eVoteOutcome);
CGovernanceVote vote(mn.outpoint, govobj, eVoteSignal, eVoteOutcome);

bool signSuccess = false;
if (deterministicMNManager->IsDeterministicMNsSporkActive()) {
Expand Down Expand Up @@ -264,7 +263,7 @@ int GetRequiredQuorumLevel(int nHeight)
return nReq;
}

bool VoteForGSCContract(int nHeight, std::string sMyContract, std::string sError)
bool VoteForGSCContract(int nHeight, std::string sMyContract, std::string& sError)
{
int iPendingVotes = 0;
uint256 uGovObjHash;
Expand Down Expand Up @@ -405,10 +404,8 @@ uint256 GetPAMHashByContract(std::string sContract)
{
std::string sAddresses = ExtractXML(sContract, "<ADDRESSES>","</ADDRESSES>");
std::string sAmounts = ExtractXML(sContract, "<PAYMENTS>","</PAYMENTS>");

uint256 u = GetPAMHash(sAddresses, sAmounts);
LogPrintf("GetPAMByContract addr %s, amounts %s, uint %s",sAddresses, sAmounts, u.GetHex());

/* LogPrintf("GetPAMByContract addr %s, amounts %s, uint %s",sAddresses, sAmounts, u.GetHex()); */
return u;
}

Expand All @@ -432,7 +429,7 @@ void GetGSCGovObjByHeight(int nHeight, uint256 uOptFilter, int& out_nVotes, uint
std::string sPAM = obj["payment_amounts"].get_str();
int iVotes = myGov->GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
uint256 uHash = GetPAMHash(sPAD, sPAM);
LogPrintf("\n Found gscgovobj2 %s with votes %f with pad %s and pam %s , pam hash %s ", myGov->GetHash().GetHex(), (double)iVotes, sPAD, sPAM, uHash.GetHex());
/* LogPrintf("\n Found gscgovobj2 %s with votes %f with pad %s and pam %s , pam hash %s ", myGov->GetHash().GetHex(), (double)iVotes, sPAD, sPAM, uHash.GetHex()); */
if (uOptFilter != uint256S("0x0") && uHash != uOptFilter) continue;
// This governance-object matches the trigger height and the optional filter
if (iVotes > iHighVotes)
Expand Down Expand Up @@ -553,7 +550,7 @@ std::string ExecuteGenericSmartContractQuorumProcess()
return "INVALID_CHAIN";
if (!ChainSynced(chainActive.Tip()))
return "CHAIN_NOT_SYNCED";
bool fQuorum = (chainActive.Tip()->nHeight % 12 == 0);
bool fQuorum = (chainActive.Tip()->nHeight % 9 == 0);
if (!fQuorum)
return "NOT_TIME_FOR_QUORUM";

Expand Down Expand Up @@ -585,7 +582,7 @@ std::string ExecuteGenericSmartContractQuorumProcess()
std::string sQuorumTrigger = SerializeSanctuaryQuorumTrigger(iLastSuperblock, iNextSuperblock, sContract);
std::string sGobjectHash;
SubmitGSCTrigger(sQuorumTrigger, sGobjectHash, sError);
LogPrintf(" ** ExecuteGenericSmartContractQuorumProcess::CreatingGSCContract Hex %s , Gobject %s, results %s **\n", sQuorumTrigger.c_str(), sGobjectHash.c_str(), sError.c_str());
LogPrintf("**ExecuteGenericSmartContractQuorumProcess::CreatingGSCContract Hex %s , Gobject %s, results %s **\n", sQuorumTrigger.c_str(), sGobjectHash.c_str(), sError.c_str());
return "CREATING_CONTRACT";
}
if (iVotes < iRequiredVotes)
Expand All @@ -595,12 +592,11 @@ std::string ExecuteGenericSmartContractQuorumProcess()
if (bResult) return "VOTED_FOR_GSC_CONTRACT";
if (!bResult)
{
LogPrintf(" **ExecuteGenericSmartContractQuorum::Unable to vote for GSC contract %s ", sError.c_str());
LogPrintf("\n**ExecuteGenericSmartContractQuorum::Unable to vote for GSC contract: Reason [%s] ", sError.c_str());
}
else
{
LogPrintf("\n ** ExecuteGenericSmartContractQuorum::Voted Successfully %f.", 1);

LogPrintf("\n**ExecuteGenericSmartContractQuorum::Voted Successfully %f.", 1);
}

return "UNABLE_TO_VOTE_FOR_GSC_CONTRACT";
Expand Down
2 changes: 1 addition & 1 deletion src/smartcontract-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ std::string GetGSCContract();
bool SubmitGSCTrigger(std::string sHex, std::string& gobjecthash, std::string& sError);
void GetGSCGovObjByHeight(int nHeight, uint256 uOptFilter, int& out_nVotes, uint256& out_uGovObjHash, std::string& out_PaymentAddresses, std::string& out_PaymentAmounts);
uint256 GetPAMHashByContract(std::string sContract);
bool VoteForGSCContract(int nHeight, std::string sMyContract, std::string sError);
bool VoteForGSCContract(int nHeight, std::string sMyContract, std::string& sError);
std::string ExecuteGenericSmartContractQuorumProcess();
UniValue GetProminenceLevels();
bool NickNameExists(std::string sNickName);
Expand Down
5 changes: 3 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,8 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
if (!fLoadingIndex)
{
MemorizeBlockChainPrayers(true, false, false, false);
ExecuteGenericSmartContractQuorumProcess();
std::string sStatus = ExecuteGenericSmartContractQuorumProcess();
LogPrintf("EGSCQP %f %s", (double)pindex->nHeight, sStatus);
}
// END BIBLEPAY

Expand Down Expand Up @@ -3487,7 +3488,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
double nMinRequiredABNWeight = GetSporkDouble("requiredabnweight", 0);
if (nHeight > consensusParams.ABNHeight && nMinRequiredABNWeight > 0 && !LateBlock(block))
{
double nABNWeight = GetABNWeight(block);
double nABNWeight = GetABNWeight(block, false);
if (nABNWeight < nMinRequiredABNWeight)
{
LogPrintf("\nContextualCheckBlock::ABN ERROR! Block %f does not meet anti-bot-net-minimum required guidelines: BlockWeight %f, RequiredWeight %f",
Expand Down

0 comments on commit 29c6cd8

Please sign in to comment.