20 #include <boost/thread.hpp> 25 static std::shared_ptr<CBlock> PrepareBlock(
const CScript& coinbase_scriptPubKey)
27 auto block = std::make_shared<CBlock>(
29 .CreateNewBlock(coinbase_scriptPubKey,
true)
39 static CTxIn MineBlock(
const CScript& coinbase_scriptPubKey)
41 auto block = PrepareBlock(coinbase_scriptPubKey);
45 assert(block->nNonce);
51 return CTxIn{block->vtx[0]->GetHash(), 0};
57 const std::vector<unsigned char> op_true{
OP_TRUE};
59 witness.
stack.push_back(op_true);
62 CSHA3().
Write(&op_true[0], op_true.size()).Finalize(witness_program.
begin());
72 boost::thread_group thread_group;
87 assert(witness_enabled);
91 constexpr
size_t NUM_BLOCKS{200};
93 for (
size_t b{0}; b < NUM_BLOCKS; ++b) {
95 tx.
vin.push_back(MineBlock(SCRIPT_PUB));
96 tx.
vin.back().scriptWitness = witness;
97 tx.
vout.emplace_back(1337, SCRIPT_PUB);
98 if (NUM_BLOCKS - b >= COINBASE_MATURITY)
99 txs.at(b) = MakeTransactionRef(tx);
104 for (
const auto& txr : txs) {
111 while (state.KeepRunning()) {
112 PrepareBlock(SCRIPT_PUB);
115 thread_group.interrupt_all();
116 thread_group.join_all();
static const std::string REGTEST
bool LoadGenesisBlock(const CChainParams &chainparams)
Ensures we have a genesis block in the block tree, possibly writing one to disk.
UniValue ret(UniValue::VARR)
std::vector< std::vector< unsigned char > > stack
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
bool ProcessNewBlock(const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock)
Process an incoming block.
std::shared_ptr< const CTransaction > CTransactionRef
bool ActivateBestChain(CValidationState &state, const CChainParams &chainparams, std::shared_ptr< const CBlock > pblock)
Find the best known block, and make it the tip of the block chain.
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
BENCHMARK(AssembleBlock, 700)
Access to the block database (blocks/index/)
An input of a transaction.
std::unique_ptr< CCoinsViewDB > pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
CMainSignals & GetMainSignals()
Generate a new block, without valid proof-of-work.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
std::vector< CTxOut > vout
int64_t GetMedianTimePast() const
A hasher class for SHA3-256.
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once) ...
Capture information about block/transaction validation.
const CChainParams & Params()
Return the currently selected parameters.
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
Serialized script, used inside transaction inputs and outputs.
CCoinsView backed by the coin database (chainstate/)
void InitScriptExecutionCache()
Initializes the script-execution cache.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
CSHA3 & Write(const unsigned char *data, size_t len)
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
bool IsWitnessEnabled(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms)
Check whether witness commitments are required for block.
A mutable version of CTransaction.
const Consensus::Params & GetConsensus() const
CCoinsView that adds a memory cache for transactions to another CCoinsView.
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).