Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions src/governance-classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,47 +366,46 @@ bool CSuperblockManager::GetBestSuperblock(CSuperblock_sptr& pSuperblockRet, int
}

/**
* Create Superblock Payments
* Get Superblock Payments
*
* - Create the correct payment structure for a given superblock
* - Returns payments for superblock
*/

void CSuperblockManager::CreateSuperblock(CMutableTransaction& txNewRet, int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet)
bool CSuperblockManager::GetSuperblockPayments(int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet)
{
DBG( std::cout << "CSuperblockManager::CreateSuperblock Start" << std::endl; );
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments Start" << std::endl; );

LOCK(governance.cs);

// GET THE BEST SUPERBLOCK FOR THIS BLOCK HEIGHT

CSuperblock_sptr pSuperblock;
if(!CSuperblockManager::GetBestSuperblock(pSuperblock, nBlockHeight)) {
LogPrint("gobject", "CSuperblockManager::CreateSuperblock -- Can't find superblock for height %d\n", nBlockHeight);
DBG( std::cout << "CSuperblockManager::CreateSuperblock Failed to get superblock for height, returning" << std::endl; );
return;
LogPrint("gobject", "CSuperblockManager::GetSuperblockPayments -- Can't find superblock for height %d\n", nBlockHeight);
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments Failed to get superblock for height, returning" << std::endl; );
return false;
}

// make sure it's empty, just in case
voutSuperblockRet.clear();

// CONFIGURE SUPERBLOCK OUTPUTS
// GET SUPERBLOCK OUTPUTS

// Superblock payments are appended to the end of the coinbase vout vector
DBG( std::cout << "CSuperblockManager::CreateSuperblock Number payments: " << pSuperblock->CountPayments() << std::endl; );
// Superblock payments will be appended to the end of the coinbase vout vector
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments Number payments: " << pSuperblock->CountPayments() << std::endl; );

// TODO: How many payments can we add before things blow up?
// Consider at least following limits:
// - max coinbase tx size
// - max "budget" available
for(int i = 0; i < pSuperblock->CountPayments(); i++) {
CGovernancePayment payment;
DBG( std::cout << "CSuperblockManager::CreateSuperblock i = " << i << std::endl; );
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments i = " << i << std::endl; );
if(pSuperblock->GetPayment(i, payment)) {
DBG( std::cout << "CSuperblockManager::CreateSuperblock Payment found " << std::endl; );
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments Payment found " << std::endl; );
// SET COINBASE OUTPUT TO SUPERBLOCK SETTING

CTxOut txout = CTxOut(payment.nAmount, payment.script);
txNewRet.vout.push_back(txout);
voutSuperblockRet.push_back(txout);

// PRINT NICE LOG OUTPUT FOR SUPERBLOCK PAYMENT
Expand All @@ -417,15 +416,17 @@ void CSuperblockManager::CreateSuperblock(CMutableTransaction& txNewRet, int nBl

// TODO: PRINT NICE N.N DASH OUTPUT

DBG( std::cout << "CSuperblockManager::CreateSuperblock Before LogPrintf call, nAmount = " << payment.nAmount << std::endl; );
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments Before LogPrintf call, nAmount = " << payment.nAmount << std::endl; );
LogPrintf("NEW Superblock : output %d (addr %s, amount %d)\n", i, address2.ToString(), payment.nAmount);
DBG( std::cout << "CSuperblockManager::CreateSuperblock After LogPrintf call " << std::endl; );
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments After LogPrintf call " << std::endl; );
} else {
DBG( std::cout << "CSuperblockManager::CreateSuperblock Payment not found " << std::endl; );
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments Payment not found " << std::endl; );
}
}

DBG( std::cout << "CSuperblockManager::CreateSuperblock End" << std::endl; );
DBG( std::cout << "CSuperblockManager::GetSuperblockPayments End" << std::endl; );

return true;
}

bool CSuperblockManager::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward)
Expand Down Expand Up @@ -679,15 +680,15 @@ bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount b

int nOutputs = txNew.vout.size();
int nPayments = CountPayments();
int nMinerPayments = nOutputs - nPayments;
int nMinerAndMasternodePayments = nOutputs - nPayments;

LogPrint("gobject", "CSuperblock::IsValid nOutputs = %d, nPayments = %d, GetDataAsHexString = %s\n",
nOutputs, nPayments, GetGovernanceObject()->GetDataAsHexString());

// We require an exact match (including order) between the expected
// superblock payments and the payments actually in the block.

if(nMinerPayments < 0) {
if(nMinerAndMasternodePayments < 0) {
// This means the block cannot have all the superblock payments
// so it is not valid.
// TODO: could that be that we just hit coinbase size limit?
Expand All @@ -703,7 +704,7 @@ bool CSuperblock::IsValid(const CTransaction& txNew, int nBlockHeight, CAmount b
return false;
}

// miner should not get more than he would usually get
// miner and masternodes should not get more than they would usually get
CAmount nBlockValue = txNew.GetValueOut();
if(nBlockValue > blockReward + nPaymentsTotalAmount) {
LogPrintf("CSuperblock::IsValid -- ERROR: Block invalid, block value limit exceeded: block %lld, limit %lld\n", nBlockValue, blockReward + nPaymentsTotalAmount);
Expand Down
2 changes: 1 addition & 1 deletion src/governance-classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CSuperblockManager

static bool IsSuperblockTriggered(int nBlockHeight);

static void CreateSuperblock(CMutableTransaction& txNewRet, int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet);
static bool GetSuperblockPayments(int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet);
static void ExecuteBestSuperblock(int nBlockHeight);

static std::string GetRequiredPaymentsString(int nBlockHeight);
Expand Down
Loading