Skip to content

Commit

Permalink
Memory pool cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BLOCXTECH committed Feb 12, 2024
1 parent c5a4c65 commit 24b12fa
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ BLOCX. is released under the terms of the MIT license.

# Documentation

https://docs.blocx.info/
https://docs.blocx.info/
2 changes: 2 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ class CMainParams : public CChainParams {
{62541, uint256S("0x0000000000000050fd89facd5f17a48b70d188d899483eb0ab5b14cc6e67ece5")},
{74985, uint256S("0x000000000000004cfec6a72a8770d741a06b02532851c46a9e8a587433406f06")},
{85330, uint256S("0x000000000000002e87c0b53d5ce7ea2d27b794330076d2a03555d46cfc46d973")},
{90281, uint256S("0x000000000000001ce9851e375bc022afb673ad82882a2fb1caa1479e1b7c92fd")},
{95194, uint256S("0x000000000000002518c37c688a48aaddcdb6db52ab3a19c9efdf7bb70ee82ae8")},
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
allowEmptyTxInOut = true;
}

/* The Masternode update service has been temporarily disabled.
User can spend the MN collateral and create Masternode again to start receiving rewards.*/
if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
return false;
}

// Basic checks that don't depend on any context
if (!allowEmptyTxInOut && tx.vin.empty())
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty");
Expand Down
42 changes: 42 additions & 0 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,48 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(int
return result;
}

std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayeesTierOne(int nCount) const
{
if (nCount > GetValidMNsCount()) {
nCount = GetValidMNsCount();
}

std::vector<CDeterministicMNCPtr> result;
result.reserve(nCount);

ForEachMNTierOne(true, [&](const CDeterministicMNCPtr& dmn) {
result.emplace_back(dmn);
});
std::sort(result.begin(), result.end(), [&](const CDeterministicMNCPtr& a, const CDeterministicMNCPtr& b) {
return CompareByLastPaid(a, b);
});

result.resize(nCount);

return result;
}

std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayeesTierTwo(int nCount) const
{
if (nCount > GetValidMNsCount()) {
nCount = GetValidMNsCount();
}

std::vector<CDeterministicMNCPtr> result;
result.reserve(nCount);

ForEachMNTierTwo(true, [&](const CDeterministicMNCPtr& dmn) {
result.emplace_back(dmn);
});
std::sort(result.begin(), result.end(), [&](const CDeterministicMNCPtr& a, const CDeterministicMNCPtr& b) {
return CompareByLastPaid(a, b);
});

result.resize(nCount);

return result;
}

std::vector<CDeterministicMNCPtr> CDeterministicMNList::CalculateQuorum(size_t maxSize, const uint256& modifier) const
{
auto scores = CalculateScores(modifier);
Expand Down
24 changes: 24 additions & 0 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,28 @@ class CDeterministicMNList
return tierTwo.size();
}

size_t GetValidStandardMNsCount() const
{
size_t count = 0;
for (const auto& p : tierOne) {
if (IsMNValid(p.second)) {
count++;
}
}
return count;
}

size_t GetValidLiteMNsCount() const
{
size_t count = 0;
for (const auto& p : tierTwo) {
if (IsMNValid(p.second)) {
count++;
}
}
return count;
}

template <typename Callback>
void ForEachMN(bool onlyValid, Callback&& cb) const
{
Expand Down Expand Up @@ -481,6 +503,8 @@ class CDeterministicMNList
* @return
*/
std::vector<CDeterministicMNCPtr> GetProjectedMNPayees(int nCount) const;
std::vector<CDeterministicMNCPtr> GetProjectedMNPayeesTierOne(int nCount) const;
std::vector<CDeterministicMNCPtr> GetProjectedMNPayeesTierTwo(int nCount) const;

/**
* Calculate a quorum based on the modifier. The resulting list is deterministically sorted by score
Expand Down
54 changes: 37 additions & 17 deletions src/qt/forms/debugwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
<item row="9" column="0">
<widget class="QLabel" name="masternodeCountLabel">
<property name="text">
<string>Number of Masternodes</string>
<string>Number of Standard Masternodes</string>
</property>
</widget>
</item>
Expand All @@ -297,21 +297,41 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="10" column="0">
<widget class="QLabel" name="liteCountLabel">
<property name="text">
<string>Number of Lite Masternodes</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QLabel" name="liteCount">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="text">
<string>N/A</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Block chain</string>
</property>
</widget>
</item>
<item row="11" column="0">
<item row="12" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Current number of blocks</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<item row="12" column="1" colspan="2">
<widget class="QLabel" name="numberOfBlocks">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -327,14 +347,14 @@
</property>
</widget>
</item>
<item row="12" column="0">
<item row="13" column="0">
<widget class="QLabel" name="labelLastBlockTime">
<property name="text">
<string>Last block time</string>
</property>
</widget>
</item>
<item row="12" column="1" colspan="2">
<item row="13" column="1" colspan="2">
<widget class="QLabel" name="lastBlockTime">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -350,14 +370,14 @@
</property>
</widget>
</item>
<item row="13" column="0">
<item row="14" column="0">
<widget class="QLabel" name="lastBlockHashLabel">
<property name="text">
<string>Last block hash</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="14" column="1">
<widget class="QLabel" name="lastBlockHash">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -373,21 +393,21 @@
</property>
</widget>
</item>
<item row="14" column="0">
<item row="15" column="0">
<widget class="QLabel" name="labelMempoolTitle">
<property name="text">
<string>Memory Pool</string>
</property>
</widget>
</item>
<item row="15" column="0">
<item row="16" column="0">
<widget class="QLabel" name="labelNumberOfTransactions">
<property name="text">
<string>Current number of transactions</string>
</property>
</widget>
</item>
<item row="15" column="1">
<item row="16" column="1">
<widget class="QLabel" name="mempoolNumberTxs">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand All @@ -403,14 +423,14 @@
</property>
</widget>
</item>
<item row="16" column="0">
<item row="17" column="0">
<widget class="QLabel" name="labelMemoryUsage">
<property name="text">
<string>Memory usage</string>
</property>
</widget>
</item>
<item row="16" column="1">
<item row="17" column="1">
<widget class="QLabel" name="mempoolSize">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand Down Expand Up @@ -466,7 +486,7 @@
</item>
</layout>
</item>
<item row="18" column="0">
<item row="19" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -479,14 +499,14 @@
</property>
</spacer>
</item>
<item row="17" column="0">
<item row="18" column="0">
<widget class="QLabel" name="labelInstantSendLockCount">
<property name="text">
<string>InstantSend locks</string>
</property>
</widget>
</item>
<item row="17" column="1">
<item row="18" column="1">
<widget class="QLabel" name="instantSendLockCount">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
Expand Down Expand Up @@ -1586,4 +1606,4 @@
</customwidgets>
<resources/>
<connections/>
</ui>
</ui>
31 changes: 23 additions & 8 deletions src/qt/masternodelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,18 @@ void MasternodeList::updateDIP3List()

nTimeUpdatedDIP3 = GetTime();

auto projectedPayees = mnList.GetProjectedMNPayees(mnList.GetValidMNsCount());
std::map<uint256, int> nextPayments;
for (size_t i = 0; i < projectedPayees.size(); i++) {
const auto& dmn = projectedPayees[i];
nextPayments.emplace(dmn->proTxHash, mnList.GetHeight() + (int)i + 1);
auto projectedPayeesTierOne = mnList.GetProjectedMNPayeesTierOne(mnList.GetAllTierOneMNCount());
std::map<uint256, int> nextPaymentsOne;
for (size_t i = 0; i < projectedPayeesTierOne.size(); i++) {
const auto& dmn = projectedPayeesTierOne[i];
nextPaymentsOne.emplace(dmn->proTxHash, mnList.GetHeight() + (int)i + 1);
}

auto projectedPayeesTierTwo = mnList.GetProjectedMNPayeesTierTwo(mnList.GetAllTierTwoMNCount());
std::map<uint256, int> nextPaymentsTwo;
for (size_t i = 0; i < projectedPayeesTierTwo.size(); i++) {
const auto& dmn = projectedPayeesTierTwo[i];
nextPaymentsTwo.emplace(dmn->proTxHash, mnList.GetHeight() + (int)i + 1);
}

std::set<COutPoint> setOutpts;
Expand Down Expand Up @@ -240,9 +247,17 @@ void MasternodeList::updateDIP3List()

QString strNextPayment = "UNKNOWN";
int nNextPayment = 0;
if (nextPayments.count(dmn->proTxHash)) {
nNextPayment = nextPayments[dmn->proTxHash];
strNextPayment = QString::number(nNextPayment);

if (dmn->nType == MnType::Standard_Masternode) {
if (nextPaymentsOne.count(dmn->proTxHash)) {
nNextPayment = nextPaymentsOne[dmn->proTxHash];
strNextPayment = QString::number(nNextPayment);
}
} else {
if (nextPaymentsTwo.count(dmn->proTxHash)) {
nNextPayment = nextPaymentsTwo[dmn->proTxHash];
strNextPayment = QString::number(nNextPayment);
}
}
QTableWidgetItem* nextPaymentItem = new CMasternodeListWidgetItem<int>(strNextPayment, nNextPayment);

Expand Down
12 changes: 10 additions & 2 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,10 +977,18 @@ void RPCConsole::updateMasternodeCount()
return;
}
auto mnList = clientModel->getMasternodeList();
size_t total_Standard_mn_count = mnList.GetAllTierOneMNCount();
size_t total_enabled_Standard_mn_count = mnList.GetValidStandardMNsCount();
size_t total_lite_mn_count = mnList.GetAllTierTwoMNCount();
size_t total_enabled_lite_mn_count = mnList.GetValidLiteMNsCount();
QString strMasternodeCount = tr("Total: %1 (Enabled: %2)")
.arg(QString::number(mnList.GetAllMNsCount()))
.arg(QString::number(mnList.GetValidMNsCount()));
.arg(QString::number(total_Standard_mn_count))
.arg(QString::number(total_enabled_Standard_mn_count));
ui->masternodeCount->setText(strMasternodeCount);
QString strLiteCount = tr("Total: %1 (Enabled: %2)")
.arg(QString::number(total_lite_mn_count))
.arg(QString::number(total_enabled_lite_mn_count));
ui->liteCount->setText(strLiteCount);
}

void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)
Expand Down
22 changes: 22 additions & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,28 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
result.pushKV("superblocks_started", pindexPrev->nHeight + 1 > consensusParams.nSuperblockStartBlock);
result.pushKV("superblocks_enabled", AreSuperblocksEnabled());

{
CScript devPayoutScript = GetScriptForDestination(DecodeDestination(consensusParams.DevelopmentFundAddress));
CAmount devPayoutValue;

int nHeight = pindexPrev->nHeight + 1;

if (nHeight > 18000 && nHeight <= 24000) {
devPayoutValue = (GetBlockSubsidy(0, nHeight, consensusParams) * 18) / 100;
} else if (nHeight <= consensusParams.V3ForkHeight) {
devPayoutValue = (GetBlockSubsidy(0, nHeight, consensusParams) * consensusParams.DevelopementFundShare) / 100;
} else {
devPayoutValue = (GetBlockSubsidy(0, nHeight, consensusParams) * (300.0 / 95.0)) / 100;
}

UniValue obj(UniValue::VOBJ);
obj.pushKV("payee", (consensusParams.DevelopmentFundAddress).c_str());
obj.pushKV("script", HexStr(devPayoutScript));
obj.pushKV("amount", devPayoutValue);
result.pushKV("devfee", obj);
}


result.pushKV("coinbase_payload", HexStr(pblock->vtx[0]->vExtraPayload));

return result;
Expand Down

0 comments on commit 24b12fa

Please sign in to comment.