Skip to content

Commit 342cdd2

Browse files
committed
Fix getblocktemplate when running a fluid mint transaction
- Adds fluid mint to superblock payments for block template - Make sure YIIMP and other mining pools support this change
1 parent 965ba7a commit 342cdd2

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/rpcmining.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "consensus/params.h"
1515
#include "consensus/validation.h"
1616
#include "core_io.h"
17+
#include "fluid/fluid.h"
18+
#include "fluid/fluiddb.h"
19+
#include "fluid/fluidmint.h"
1720
#include "init.h"
1821
#include "miner/miner.h"
1922
#include "net.h"
@@ -838,11 +841,12 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
838841
// Note that this can probably also be removed entirely after the first BIP9 non-force deployment (ie, probably segwit) gets activated
839842
aMutable.push_back("version/force");
840843
}
841-
844+
int64_t nHeight = (int64_t)(pindexPrev->nHeight + 1);
845+
CAmount nCoinbaseValue = pblock->vtx[0]->GetValueOut();
842846
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
843847
result.push_back(Pair("transactions", transactions));
844848
result.push_back(Pair("coinbaseaux", aux));
845-
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0]->GetValueOut()));
849+
result.push_back(Pair("coinbasevalue", (int64_t)nCoinbaseValue));
846850
result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
847851
result.push_back(Pair("target", hashTarget.GetHex()));
848852
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast() + 1));
@@ -852,7 +856,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
852856
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
853857
result.push_back(Pair("curtime", pblock->GetBlockTime()));
854858
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
855-
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight + 1)));
859+
result.push_back(Pair("height", nHeight));
856860

857861
UniValue dynodeObj(UniValue::VOBJ);
858862
if (pblocktemplate->txoutDynode != CTxOut()) {
@@ -880,9 +884,36 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
880884
superblockObjArray.push_back(entry);
881885
}
882886
}
887+
CFluidMint fluidMint;
888+
bool areWeMinting = GetMintingInstructions(nHeight, fluidMint);
889+
CScript scriptMint;
890+
if (areWeMinting) {
891+
// Add minting output to superblock payments
892+
CAmount fluidIssuance = nCoinbaseValue - GetFluidDynodeReward(nHeight) - GetFluidMiningReward(nHeight);
893+
if (fluidIssuance > 0) {
894+
UniValue entry(UniValue::VOBJ);
895+
CDynamicAddress mintAddress = fluidMint.GetDestinationAddress();
896+
if (!mintAddress.IsScript()) {
897+
scriptMint = GetScriptForDestination(mintAddress.Get());
898+
} else {
899+
CScriptID fluidScriptID = boost::get<CScriptID>(mintAddress.Get());
900+
scriptMint = CScript() << OP_HASH160 << ToByteVector(fluidScriptID) << OP_EQUAL;
901+
}
902+
entry.push_back(Pair("payee", mintAddress.ToString().c_str()));
903+
entry.push_back(Pair("script", HexStr(scriptMint.begin(), scriptMint.end())));
904+
entry.push_back(Pair("amount", (int64_t)fluidIssuance));
905+
superblockObjArray.push_back(entry);
906+
}
907+
}
883908
result.push_back(Pair("superblock", superblockObjArray));
884-
result.push_back(Pair("superblocks_started", pindexPrev->nHeight + 1 > Params().GetConsensus().nSuperblockStartBlock));
885-
result.push_back(Pair("superblocks_enabled", sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED)));
909+
if (areWeMinting) {
910+
result.push_back(Pair("superblocks_started", true));
911+
result.push_back(Pair("superblocks_enabled", true));
912+
}
913+
else {
914+
result.push_back(Pair("superblocks_started", pindexPrev->nHeight + 1 > Params().GetConsensus().nSuperblockStartBlock));
915+
result.push_back(Pair("superblocks_enabled", sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED)));
916+
}
886917

887918
return result;
888919
}

0 commit comments

Comments
 (0)