Cache transaction validation successes
Conflicts: src/main.cpp src/test/test_bitcoin.cpp Github-Pull: #6077 Rebased-From: 17b11428c135203342aff38cabc8047e673f38ac 517e6dd25618522c716e64859554b0f29c6e65d0
This commit is contained in:
committed by
Wladimir J. van der Laan
parent
92401c2d90
commit
bc484ef8db
@@ -6,8 +6,13 @@
|
||||
|
||||
#include "test_bitcoin.h"
|
||||
|
||||
#include "chainparams.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "key.h"
|
||||
#include "main.h"
|
||||
#include "miner.h"
|
||||
#include "pubkey.h"
|
||||
#include "random.h"
|
||||
#include "txdb.h"
|
||||
#include "ui_interface.h"
|
||||
@@ -27,20 +32,22 @@ CWallet* pwalletMain;
|
||||
extern bool fPrintToConsole;
|
||||
extern void noui_connect();
|
||||
|
||||
BasicTestingSetup::BasicTestingSetup()
|
||||
BasicTestingSetup::BasicTestingSetup(CBaseChainParams::Network network)
|
||||
{
|
||||
ECC_Start();
|
||||
SetupEnvironment();
|
||||
fPrintToDebugLog = false; // don't want to write to debug.log file
|
||||
fCheckBlockIndex = true;
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
SelectParams(network);
|
||||
noui_connect();
|
||||
}
|
||||
|
||||
BasicTestingSetup::~BasicTestingSetup()
|
||||
{
|
||||
ECC_Stop();
|
||||
}
|
||||
|
||||
TestingSetup::TestingSetup()
|
||||
TestingSetup::TestingSetup(CBaseChainParams::Network network) : BasicTestingSetup(network)
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
bitdb.MakeMock();
|
||||
@@ -86,6 +93,51 @@ TestingSetup::~TestingSetup()
|
||||
boost::filesystem::remove_all(pathTemp);
|
||||
}
|
||||
|
||||
TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
|
||||
{
|
||||
// Generate a 100-block chain:
|
||||
coinbaseKey.MakeNewKey(true);
|
||||
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
||||
for (int i = 0; i < COINBASE_MATURITY; i++)
|
||||
{
|
||||
std::vector<CMutableTransaction> noTxns;
|
||||
CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey);
|
||||
coinbaseTxns.push_back(b.vtx[0]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Create a new block with just given transactions, coinbase paying to
|
||||
// scriptPubKey, and try to add it to the current chain.
|
||||
//
|
||||
CBlock
|
||||
TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
|
||||
{
|
||||
CBlockTemplate *pblocktemplate = CreateNewBlock(scriptPubKey);
|
||||
CBlock& block = pblocktemplate->block;
|
||||
|
||||
// Replace mempool-selected txns with just coinbase plus passed-in txns:
|
||||
block.vtx.resize(1);
|
||||
BOOST_FOREACH(const CMutableTransaction& tx, txns)
|
||||
block.vtx.push_back(tx);
|
||||
// IncrementExtraNonce creates a valid coinbase and merkleRoot
|
||||
unsigned int extraNonce = 0;
|
||||
IncrementExtraNonce(&block, chainActive.Tip(), extraNonce);
|
||||
|
||||
while (!CheckProofOfWork(block.GetHash(), block.nBits, Params(CBaseChainParams::REGTEST).GetConsensus())) ++block.nNonce;
|
||||
|
||||
CValidationState state;
|
||||
ProcessNewBlock(state, NULL, &block, true, NULL);
|
||||
|
||||
CBlock result = block;
|
||||
delete pblocktemplate;
|
||||
return result;
|
||||
}
|
||||
|
||||
TestChain100Setup::~TestChain100Setup()
|
||||
{
|
||||
}
|
||||
|
||||
void Shutdown(void* parg)
|
||||
{
|
||||
exit(0);
|
||||
|
||||
Reference in New Issue
Block a user