Validation of fork blocks against tnxs in file (AcceptBlock); Final Cleanup
This commit is contained in:
parent
dbe41f28e3
commit
352b0c6cf6
18
configure.ac
18
configure.ac
|
@ -82,6 +82,13 @@ AC_ARG_ENABLE([wallet],
|
|||
[enable_wallet=$enableval],
|
||||
[enable_wallet=yes])
|
||||
|
||||
# Enable fork mining
|
||||
AC_ARG_ENABLE([fork],
|
||||
[AS_HELP_STRING([--enable-fork],
|
||||
[enable fork (default is yes)])],
|
||||
[enable_fork=$enableval],
|
||||
[enable_fork=yes])
|
||||
|
||||
AC_ARG_ENABLE([mining],
|
||||
[AS_HELP_STRING([--enable-mining],
|
||||
[enable mining (default is yes)])],
|
||||
|
@ -856,6 +863,16 @@ else
|
|||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
dnl enable fork_mining
|
||||
AC_MSG_CHECKING([if fork mining should be enabled])
|
||||
if test x$enable_fork != xno; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(FORK_CB_INPUT, 1, [Define to 1 to enable fork mining functions])
|
||||
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
dnl enable mining
|
||||
AC_MSG_CHECKING([if mining should be enabled])
|
||||
if test x$enable_mining != xno; then
|
||||
|
@ -931,6 +948,7 @@ AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
|
|||
AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
|
||||
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
|
||||
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
|
||||
AM_CONDITIONAL([FORK_CB_INPUT],[test x$enable_fork = xyes])
|
||||
AM_CONDITIONAL([ENABLE_MINING],[test x$enable_mining = xyes])
|
||||
AM_CONDITIONAL([ENABLE_RUST],[test x$enable_rust = xyes])
|
||||
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
|
||||
|
|
29
src/main.cpp
29
src/main.cpp
|
@ -1383,7 +1383,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::M
|
|||
|
||||
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos
|
||||
#ifdef FORK_CB_INPUT
|
||||
, int nHeight = -1
|
||||
, int nHeight
|
||||
#endif
|
||||
)
|
||||
{
|
||||
|
@ -1403,7 +1403,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos
|
|||
}
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (!isFork(nHeight)) { //when block is un fork region - don't check Solution and PoW
|
||||
if (!isForkBlock(nHeight)) { //when block is in fork region - don't check Solution and PoW
|
||||
#endif
|
||||
|
||||
// Check the header
|
||||
|
@ -1415,7 +1415,6 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1934,12 +1933,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
|
|||
|
||||
int nNonCBIdx = 0;
|
||||
// restore inputs
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (isFork(pindex->nHeight)){ //when block in forking region - all transcations are coinbase
|
||||
nNonCBIdx = forkCBPerBlock;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
// Check that all outputs are available and match the outputs in the block itself
|
||||
// exactly.
|
||||
{
|
||||
|
@ -1968,6 +1962,11 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (isForkBlock(pindex->nHeight)){ //when block in forking region - all transcations are coinbase
|
||||
nNonCBIdx = forkCBPerBlock;
|
||||
}
|
||||
#endif
|
||||
if (i > nNonCBIdx) { // not coinbases
|
||||
const CTxUndo &txundo = blockUndo.vtxundo[i-1];
|
||||
if (txundo.vprevout.size() != tx.vin.size())
|
||||
|
@ -2243,7 +2242,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001);
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (!isFork(pindex->nHeight)){ //when block is in forking region - don't check coinbase amount
|
||||
if (!isForkBlock(pindex->nHeight)){ //when block is in forking region - don't check coinbase amount
|
||||
#endif
|
||||
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
|
||||
if (block.vtx[0].GetValueOut() > blockReward)
|
||||
|
@ -3031,7 +3030,7 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool f
|
|||
REJECT_INVALID, "version-too-low");
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (!isFork()) { //when in FORK mode (tip is in forking region) - don't check Solution and PoW
|
||||
if (!isTipInForkRange()) { //when in FORK mode (tip is in forking region) - don't check Solution and PoW
|
||||
#endif
|
||||
|
||||
// Check Equihash solution is valid
|
||||
|
@ -3098,7 +3097,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state,
|
|||
REJECT_INVALID, "bad-cb-missing");
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (isFork()) { //when in FORK mode (tip is in forking region) blocks might have up to fork pre-defined value coinbases
|
||||
if (isTipInForkRange()) { //when in FORK mode (tip is in forking region) blocks might have up to fork pre-defined value coinbases
|
||||
if (block.vtx.size() > forkCBPerBlock)
|
||||
return state.DoS(100, error("CheckBlock(): it is forking block but there are more than %d coinbase txns", forkCBPerBlock),
|
||||
REJECT_INVALID, "bad-cb-multiple");
|
||||
|
@ -3143,7 +3142,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
|
|||
|
||||
// Check proof of work
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (!isFork(nHeight)) { //If current block is FORK, don't check work required
|
||||
if (!isForkBlock(nHeight)) { //If current block is FORK, don't check work required
|
||||
#endif
|
||||
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
|
||||
return state.DoS(100, error("%s: incorrect proof of work", __func__),
|
||||
|
@ -3297,7 +3296,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
|
|||
int nHeight = pindex->nHeight;
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (isFork(nHeight)) { //if block is in forking region validate it agains file records
|
||||
if (isForkBlock(nHeight)) { //if block is in forking region validate it agains file records
|
||||
if (!fCalledFromMiner && !forkUtxoPath.empty()) {
|
||||
|
||||
std::string utxo_file_path = GetUTXOFileName(nHeight);
|
||||
|
@ -3315,7 +3314,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
|
|||
char term = 0;
|
||||
char coin[8] = {};
|
||||
if (!if_utxo.read(coin, 8)) {
|
||||
LogPrintf("AcceptBlock(): FORK Block - UTXO file corrupted? - No more data (Amount)\n");
|
||||
LogPrintf("AcceptBlock(): FORK Block - No more data in the file \n");
|
||||
break;
|
||||
}
|
||||
uint64_t amount = bytes2uint64(coin);
|
||||
|
|
14
src/main.h
14
src/main.h
|
@ -37,10 +37,6 @@
|
|||
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#ifndef FORK_CB_INPUT
|
||||
#define FORK_CB_INPUT
|
||||
#endif
|
||||
|
||||
class CBlockIndex;
|
||||
class CBlockTreeDB;
|
||||
class CBloomFilter;
|
||||
|
@ -557,17 +553,17 @@ extern int64_t forkCBPerBlock;
|
|||
|
||||
std::string GetUTXOFileName(int nHeight);
|
||||
|
||||
inline bool isFork(int nHeight)
|
||||
inline bool isForkBlock(int nHeight)
|
||||
{
|
||||
return (nHeight >= forkStartHeight && nHeight < forkStartHeight + forkHeightRange);
|
||||
}
|
||||
inline bool isFork()
|
||||
inline bool isTipInForkRange()
|
||||
{
|
||||
return chainActive.Tip()? isFork(chainActive.Tip()->nHeight): false;
|
||||
return chainActive.Tip()? isForkBlock(chainActive.Tip()->nHeight): false;
|
||||
}
|
||||
inline bool isNextFork()
|
||||
inline bool isNextTipInForkRange()
|
||||
{
|
||||
return chainActive.Tip()? isFork(chainActive.Tip()->nHeight+1): false;
|
||||
return chainActive.Tip()? isForkBlock(chainActive.Tip()->nHeight + 1): false;
|
||||
}
|
||||
inline uint64_t bytes2uint64(char *array)
|
||||
{
|
||||
|
|
|
@ -194,7 +194,7 @@ CBlockTemplate* CreateNewForkBlock(bool& bFileNotFound)
|
|||
|
||||
|
||||
txNew.vout[0].nValue = amount;
|
||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
txNew.vin[0].scriptSig = CScript() << nHeight+nBlockTx << OP_0;
|
||||
|
||||
unsigned int nTxSize = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
|
||||
if (nBlockSize + nTxSize >= nBlockMaxSize)
|
||||
|
@ -594,7 +594,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
|||
#endif // ENABLE_WALLET
|
||||
{
|
||||
#ifdef FORK_CB_INPUT
|
||||
if (!isNextFork()) {
|
||||
if (!isNextTipInForkRange()) {
|
||||
#endif
|
||||
LogPrintf("%s\n", pblock->ToString());
|
||||
#ifdef FORK_CB_INPUT
|
||||
|
@ -678,7 +678,6 @@ void static BitcoinMiner()
|
|||
|
||||
try {
|
||||
while (true) {
|
||||
#ifndef FORK_CB_INPUT ///!!!! this is only for TESTING
|
||||
if (chainparams.MiningRequiresPeers()) {
|
||||
// Busy-wait for the network to come online so we don't waste time mining
|
||||
// on an obsolete chain. In regtest mode we expect to fly solo.
|
||||
|
@ -695,7 +694,6 @@ void static BitcoinMiner()
|
|||
} while (true);
|
||||
miningTimer.start();
|
||||
}
|
||||
#endif
|
||||
|
||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||
CBlock *pblock = nullptr;
|
||||
|
@ -707,7 +705,7 @@ void static BitcoinMiner()
|
|||
unique_ptr<CBlockTemplate> pblocktemplate;
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
bool isNextBlockFork = isFork(pindexPrev->nHeight+1);
|
||||
bool isNextBlockFork = isForkBlock(pindexPrev->nHeight+1);
|
||||
if (isNextBlockFork) {
|
||||
if (!bForkModeStarted) {
|
||||
LogPrintf("BTCPrivate Miner: switching into fork mode\n");
|
||||
|
|
|
@ -49,10 +49,6 @@ void GenerateBitcoins(bool fGenerate, int nThreads);
|
|||
|
||||
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
|
||||
|
||||
#ifndef FORK_CB_INPUT
|
||||
#define FORK_CB_INPUT
|
||||
#endif
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
CBlockTemplate* CreateNewForkBlock();
|
||||
#endif
|
||||
|
|
|
@ -13,10 +13,6 @@
|
|||
|
||||
#include <univalue.h>
|
||||
|
||||
#ifndef FORK_CB_INPUT
|
||||
#define FORK_CB_INPUT
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CRPCConvertParam
|
||||
|
@ -116,11 +112,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||
{ "z_getoperationstatus", 0},
|
||||
{ "z_getoperationresult", 0},
|
||||
{ "z_importkey", 2 },
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
{ "startfork", 0 },
|
||||
{ "startforkat", 1 },
|
||||
#endif
|
||||
};
|
||||
|
||||
class CRPCConvertTable
|
||||
|
|
|
@ -157,29 +157,6 @@ UniValue getgenerate(const UniValue& params, bool fHelp)
|
|||
return GetBoolArg("-gen", false);
|
||||
}
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
UniValue startfork(const UniValue& params, bool fHelp)
|
||||
{
|
||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||
forkStartHeight = pindexPrev->nHeight;
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
UniValue startforkat(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (params.size() == 1) {
|
||||
forkStartHeight = params[0].get_int();
|
||||
} else {
|
||||
throw runtime_error(
|
||||
"startfork at chain height\n"
|
||||
+ HelpExampleCli("startforkat", "100")
|
||||
);
|
||||
}
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
UniValue generate(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 1)
|
||||
|
|
|
@ -309,11 +309,6 @@ static const CRPCCommand vRPCCommands[] =
|
|||
{ "generating", "generate", &generate, true },
|
||||
#endif
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
{ "generating", "startfork", &startfork, true },
|
||||
{ "generating", "startforkat", &startforkat, true },
|
||||
#endif
|
||||
|
||||
/* Raw transactions */
|
||||
{ "rawtransactions", "createrawtransaction", &createrawtransaction, true },
|
||||
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, true },
|
||||
|
|
|
@ -20,10 +20,6 @@
|
|||
|
||||
#include <univalue.h>
|
||||
|
||||
#ifndef FORK_CB_INPUT
|
||||
#define FORK_CB_INPUT
|
||||
#endif
|
||||
|
||||
class AsyncRPCQueue;
|
||||
class CRPCCommand;
|
||||
|
||||
|
@ -196,10 +192,6 @@ extern UniValue importwallet(const UniValue& params, bool fHelp);
|
|||
extern UniValue getgenerate(const UniValue& params, bool fHelp); // in rpcmining.cpp
|
||||
extern UniValue setgenerate(const UniValue& params, bool fHelp);
|
||||
extern UniValue generate(const UniValue& params, bool fHelp);
|
||||
#ifdef FORK_CB_INPUT
|
||||
extern UniValue startfork(const UniValue& params, bool fHelp);
|
||||
extern UniValue startforkat(const UniValue& params, bool fHelp);
|
||||
#endif
|
||||
extern UniValue getlocalsolps(const UniValue& params, bool fHelp);
|
||||
extern UniValue getnetworksolps(const UniValue& params, bool fHelp);
|
||||
extern UniValue getnetworkhashps(const UniValue& params, bool fHelp);
|
||||
|
|
|
@ -68,10 +68,6 @@ public:
|
|||
bool WriteFlag(const std::string &name, bool fValue);
|
||||
bool ReadFlag(const std::string &name, bool &fValue);
|
||||
|
||||
#ifndef FORK_CB_INPUT
|
||||
#define FORK_CB_INPUT
|
||||
#endif
|
||||
|
||||
#ifdef FORK_CB_INPUT
|
||||
bool LoadBlockIndexGuts(int64_t forkStart, int64_t forkStop);
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue