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
14 changes: 10 additions & 4 deletions src/blockassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool SolveProofOfStake(CBlock* pblock, CBlockIndex* pindexPrev, CWallet* pwallet
return true;
}

bool CreateCoinbaseTx(CBlock* pblock, const CScript& scriptPubKeyIn, CBlockIndex* pindexPrev)
CMutableTransaction CreateCoinbaseTx(const CScript& scriptPubKeyIn, CBlockIndex* pindexPrev)
{
assert(pindexPrev);
const int nHeight = pindexPrev->nHeight + 1;
Expand All @@ -128,7 +128,12 @@ bool CreateCoinbaseTx(CBlock* pblock, const CScript& scriptPubKeyIn, CBlockIndex
txCoinbase.vout[0].nValue = GetBlockValue(nHeight);
}

pblock->vtx.emplace_back(MakeTransactionRef(txCoinbase));
return txCoinbase;
}

bool CreateCoinbaseTx(CBlock* pblock, const CScript& scriptPubKeyIn, CBlockIndex* pindexPrev)
{
pblock->vtx.emplace_back(MakeTransactionRef(CreateCoinbaseTx(scriptPubKeyIn, pindexPrev)));
return true;
}

Expand Down Expand Up @@ -165,7 +170,8 @@ void BlockAssembler::resetBlock()
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn,
CWallet* pwallet,
bool fProofOfStake,
std::vector<CStakeableOutput>* availableCoins)
std::vector<CStakeableOutput>* availableCoins,
bool fNoMempoolTx)
{
resetBlock();

Expand Down Expand Up @@ -194,7 +200,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
return nullptr;
}

{
if (!fNoMempoolTx) {
// Add transactions from mempool
LOCK2(cs_main,mempool.cs);
addPriorityTxs();
Expand Down
4 changes: 3 additions & 1 deletion src/blockassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class BlockAssembler
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn,
CWallet* pwallet = nullptr,
bool fProofOfStake = false,
std::vector<CStakeableOutput>* availableCoins = nullptr);
std::vector<CStakeableOutput>* availableCoins = nullptr,
bool fNoMempoolTx = false);

private:
// utility functions
Expand Down Expand Up @@ -100,6 +101,7 @@ int32_t ComputeBlockVersion(const Consensus::Params& consensusParams, int nHeigh

// Visible for testing purposes only
bool CreateCoinbaseTx(CBlock* pblock, const CScript& scriptPubKeyIn, CBlockIndex* pindexPrev);
CMutableTransaction CreateCoinbaseTx(const CScript& scriptPubKeyIn, CBlockIndex* pindexPrev);

// Visible for testing purposes only
uint256 CalculateSaplingTreeRoot(CBlock* pblock, int nHeight, const CChainParams& chainparams);
Expand Down
40 changes: 35 additions & 5 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,23 @@ std::string GetRequiredPaymentsString(int nBlockHeight)
bool CMasternodePayments::GetMasternodeTxOuts(const CBlockIndex* pindexPrev, std::vector<CTxOut>& voutMasternodePaymentsRet) const
{
if (deterministicMNManager->LegacyMNObsolete(pindexPrev->nHeight + 1)) {
// New payment logic (!TODO)
return false;
CAmount masternodeReward = GetMasternodePayment();
auto dmnPayee = deterministicMNManager->GetListForBlock(pindexPrev).GetMNPayee();
if (!dmnPayee) {
return error("%s: Failed to get payees for block at height %d", __func__, pindexPrev->nHeight + 1);
}
CAmount operatorReward = 0;
if (dmnPayee->nOperatorReward != 0 && !dmnPayee->pdmnState->scriptOperatorPayout.empty()) {
operatorReward = (masternodeReward * dmnPayee->nOperatorReward) / 10000;
masternodeReward -= operatorReward;
}
if (masternodeReward > 0) {
voutMasternodePaymentsRet.emplace_back(masternodeReward, dmnPayee->pdmnState->scriptPayout);
}
if (operatorReward > 0) {
voutMasternodePaymentsRet.emplace_back(operatorReward, dmnPayee->pdmnState->scriptOperatorPayout);
}
return true;
}

// Legacy payment logic. !TODO: remove when transition to DMN is complete
Expand All @@ -318,7 +333,6 @@ bool CMasternodePayments::GetMasternodeTxOuts(const CBlockIndex* pindexPrev, std

bool CMasternodePayments::GetLegacyMasternodeTxOut(int nHeight, std::vector<CTxOut>& voutMasternodePaymentsRet) const
{
if (nHeight == 0) return false;
voutMasternodePaymentsRet.clear();

CScript payee;
Expand Down Expand Up @@ -622,8 +636,24 @@ bool CMasternodePayments::IsTransactionValid(const CTransaction& txNew, const CB
{
const int nBlockHeight = pindexPrev->nHeight + 1;
if (deterministicMNManager->LegacyMNObsolete(nBlockHeight)) {
// !TODO
return false;
std::vector<CTxOut> vecMnOuts;
if (!GetMasternodeTxOuts(pindexPrev, vecMnOuts)) {
// No masternode scheduled to be paid.
return true;
}

for (const CTxOut& o : vecMnOuts) {
if (std::find(txNew.vout.begin(), txNew.vout.end(), o) == txNew.vout.end()) {
CTxDestination mnDest;
const std::string& payee = ExtractDestination(o.scriptPubKey, mnDest) ? EncodeDestination(mnDest)
: HexStr(o.scriptPubKey);
LogPrint(BCLog::MASTERNODE, "%s: Failed to find expected payee %s in block at height %d (tx %s)",
__func__, payee, pindexPrev->nHeight + 1, txNew.GetHash().ToString());
return false;
}
}
// all the expected payees have been found in txNew outputs
return true;
}

// Legacy payment logic. !TODO: remove when transition to DMN is complete
Expand Down
4 changes: 2 additions & 2 deletions src/spork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ void CSporkManager::ProcessGetSporks(CNode* pfrom, std::string& strCommand, CDat

bool CSporkManager::UpdateSpork(SporkId nSporkID, int64_t nValue)
{
CSporkMessage spork = CSporkMessage(nSporkID, nValue, GetTime());
CSporkMessage spork(nSporkID, nValue, GetTime());

if(spork.Sign(strMasterPrivKey)){
if (spork.Sign(strMasterPrivKey)) {
spork.Relay();
AddOrUpdateSporkMessage(spork);
return true;
Expand Down
Loading