Skip to content

Commit

Permalink
some debug changes (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Jul 12, 2023
1 parent bd5563f commit 5aba960
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/evo/creditpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ bool CCreditPoolDiff::setTarget(const CTransaction& tx, TxValidationState& state
CAmount blockReward = 0;
for (const CTxOut& txout : tx.vout) {
blockReward += txout.nValue;
LogPrintf("CreditPool: next output in tx: %lld\n", txout.nValue);
}
masternodeReward = GetMasternodePayment(cbTx.nHeight, blockReward, params.BRRHeight);
masternodeReward = 0.375 * GetMasternodePayment(cbTx.nHeight, blockReward, params.BRRHeight);
LogPrintf("CreditPool: set target to %lld with MN reward %lld\n", *targetLocked, masternodeReward);

return true;
Expand Down
3 changes: 2 additions & 1 deletion src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(int

auto remaining_hpmn_payments = 0;
CDeterministicMNCPtr hpmn_to_be_skipped = nullptr;
bool isMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pIndex);
// TODO GetProjectedMNPayees should work correctly for v20+ too - no quadruple Evo MN
bool isMNRewardReallocated = false ; // llmq::utils::IsMNRewardReallocationActive(pIndex);
ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
if (dmn->pdmnState->nLastPaidHeight == nHeight) {
// We found the last MN Payee.
Expand Down
11 changes: 7 additions & 4 deletions src/masternode/payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,18 @@ bool CMasternodePayments::GetBlockTxOuts(int nBlockHeight, CAmount blockReward,

CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward, Params().GetConsensus().BRRHeight);

bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(::ChainActive().Tip());
const CBlockIndex* pindex = WITH_LOCK(cs_main, return ::ChainActive()[nBlockHeight - 1]);
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindex);

if (fMNRewardReallocated) {
LogPrintf("CMasternodePayments::%s -- MN reward %lld reallocated to credit pool\n", __func__, masternodeReward);
constexpr double platformShare = 0.375;
CAmount platformReward = masternodeReward * platformShare;
assert(MoneyRange(platformReward));
masternodeReward -= platformReward;
LogPrintf("CMasternodePayments::%s -- MN reward %lld goes to credit pool, %lld to masternode\n", __func__, platformReward, masternodeReward);
voutMasternodePaymentsRet.emplace_back(masternodeReward, CScript() << OP_RETURN);
return true;
}

const CBlockIndex* pindex = WITH_LOCK(cs_main, return ::ChainActive()[nBlockHeight - 1]);
auto dmnPayee = deterministicMNManager->GetListForBlock(pindex).GetMNPayee(pindex);
if (!dmnPayee) {
return false;
Expand Down
11 changes: 9 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,21 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
assert(creditPoolDiff);

bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindexPrev);
if (fMNRewardReallocated) {
if (true || fMNRewardReallocated) {
if (!CMasternodePayments::GetMasternodeTxOuts(nHeight, blockReward, pblocktemplate->voutMasternodePayments)) {
LogPrint(BCLog::MNPAYMENTS, "%s -- no masternode to pay (MN list probably empty)\n", __func__);
// LogPrint(BCLog::MNPAYMENTS, "%s -- no masternode to pay (MN list probably empty)\n", __func__);
}
LogPrintf("CreateNewBlock() %d realloc: %lld\n", fMNRewardReallocated, blockReward * 0.375);
if (pblocktemplate->voutMasternodePayments.size() > 2) {
/*
for (const auto& txout : pblocktemplate->voutMasternodePayments) {
LogPrintf("CreateNewBlock() add MN reward %lld to credit pool\n", txout.nValue);
creditPoolDiff->addRewardRealloced(txout.nValue);
}
*/
LogPrintf("CreateNewBlock() realloc: %lld\n", blockReward * 0.375);
creditPoolDiff->addRewardRealloced(blockReward * 0.375);
}
}
cbTx.assetLockedAmount = creditPoolDiff->getTotalLocked();
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/block_reward_reallocation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
#include <llmq/blockprocessor.h>
#include <llmq/chainlocks.h>
#include <llmq/context.h>
#include <llmq/utils.h>
#include <llmq/instantsend.h>
#include <util/enumerate.h>
#include <util/irange.h>

#include <boost/test/unit_test.hpp>

#include <logging.h>
#include <map>
#include <vector>

Expand Down Expand Up @@ -248,6 +250,11 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
for ([[maybe_unused]] auto i : irange::range(10)) {
for ([[maybe_unused]] auto k : irange::range(10)) {
CreateAndProcessBlock({}, coinbaseKey);
bool isv19Active = llmq::utils::IsV19Active(::ChainActive().Tip());
bool isv20Active = llmq::utils::IsV20Active(::ChainActive().Tip());
bool isMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(::ChainActive().Tip());
LogPrintf("height: %lld feature activation: v19: %d v20: %d mnrr: %d\n",::ChainActive().Height(),
isv19Active, isv20Active, isMNRewardReallocated);
}
LOCK(cs_main);
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), consensus_params), 2500);
Expand Down

0 comments on commit 5aba960

Please sign in to comment.