Skip to content

Commit

Permalink
initialize minting thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Hilali committed Sep 24, 2019
1 parent 8025e22 commit e012861
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <index/txindex.h>
#include <interfaces/chain.h>
#include <key.h>
#include <key_io.h>
#include <miner.h>
#include <net.h>
#include <net_permissions.h>
Expand Down Expand Up @@ -54,6 +55,7 @@
#include <validation.h>
#include <validationinterface.h>
#include <walletinitinterface.h>
#include <wallet/wallet.h>

#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -1823,5 +1825,37 @@ bool AppInitMain(InitInterfaces& interfaces)
g_banman->DumpBanlist();
}, DUMP_BANS_INTERVAL * 1000);


// ********************************************************* Step 14: start minter thread
pos::ThreadStaker::Args stakerParams{};
{
CTxDestination destination = DecodeDestination(gArgs.GetArg("-minterAddress", ""));
if (!IsValidDestination(destination)) {
LogPrintf("coinstake destination is invalid");
return false;
}

CKey key;
std::vector<std::shared_ptr<CWallet>> wallets = GetWallets();
if (wallets.size() == 0 || !wallets[0]->GetKey( CKeyID(*boost::get<PKHash>(&destination)), key)) {
LogPrintf("priv key not found");
return false;
}

stakerParams.coinbaseScript = GetScriptForDestination(destination);
stakerParams.minterKey = key;
}

// Mint proof-of-stake blocks in background
threadGroup.create_thread([=]() {
TraceThread("CoinStaker", [=]() {
// Fill Staker Args

// Run ThreadStaker
pos::ThreadStaker threadStaker{};
threadStaker(stakerParams, chainparams);
});
});

return true;
}
5 changes: 3 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
int64_t nTime;
CAddress addrMe;
CAddress addrFrom;
uint64_t nNonce = 1;
uint64_t nServiceInt;
ServiceFlags nServices;
int nVersion;
Expand Down Expand Up @@ -1951,7 +1952,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
}

if (!vRecv.empty())
vRecv >> addrFrom;
vRecv >> addrFrom >> nNonce;
if (!vRecv.empty()) {
std::string strSubVer;
vRecv >> LIMITED_STRING(strSubVer, MAX_SUBVERSION_LENGTH);
Expand All @@ -1963,7 +1964,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
if (!vRecv.empty())
vRecv >> fRelay;
// Disconnect if we connected to ourself
if (pfrom->fInbound) // TODO: (SS) && !connman->CheckIncomingNonce(nNonce)
if (pfrom->fInbound && !connman->CheckIncomingNonce(nNonce))
{
LogPrintf("connected to self at %s, disconnecting\n", pfrom->addr.ToString());
pfrom->fDisconnect = true;
Expand Down
2 changes: 1 addition & 1 deletion src/test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
{
auto block = PrepareBlock(coinbase_scriptPubKey);

// while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) { // TODO: (SS)
// while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) { // TODO: (SS) I broke this
// ++block->nNonce;
// assert(block->nNonce);
// }
Expand Down

0 comments on commit e012861

Please sign in to comment.