Files
thehub/libs/server/miner.h
T
TomZ 2aa462f8bb Replace SigOps with SigChecks
This is part of the protocol upgrade for 2020-05-15, and in general it
seems to go the direction of "we did this before, lets do this again".

The spec is clear enough, but there is still a lack of questioning and
testing. The problem this attempts to fix has been neutered for years[1].

The spec states:
> The essential idea of SigChecks is to perform counting solely in the
> spending transaction, and count actual executed signature check
> operations.

This, however nobel and logical, ignores that the
check-for-being-too-costly just pulled in a UTXO lookup and the loading
of the output script from the historical chain.
The goal that we protect against CPU over-use may be reached, but the
price is a total system slowdown. You can have multiple CPUs, but the
bus to permanent storage has one, max 2 parallel pipes.

To ensure theHub stays the number one scalable node, I didn't blindly
follow the spec, while making sure that the Hub is correctly going to
follow/reject consensus violations of newly mined blocks.

As a result the implementation in Flowee the Hub:

* does not check sigcheck-counts on historical blocks (more than 1000
  blocks in the past).

  This may increase the risk of chain-splits ever so slightly, but the cost
  of disk-IO would be too high.

* No longer stores the value in the mempool, nor uses it for the
  CPU-miner.

* Ties the sigcheck-limits to the user-set block-size-accept-limit.

  This is contrary to the spec which mistakenly thinks that BCH has a
  max block-size in the consensus rules. The effect is the same, though.

* The per-intput standardness suggestion is not implemented because
  standardness checks don't currently fetch the previous outputs and
  that would be too expensive to add.

* Standardness rules for the whole transaction are moved to the
  mempool-acceptance logic instead. The cost would be too great
  otherwise, similar to the previous point.
  Again, the effect is the same as likely intented.

---
1) since the intro of the CachingTransactionSignatureChecker
2020-04-13 15:57:42 +02:00

86 lines
2.5 KiB
C++

/*
* This file is part of the Flowee project
* Copyright (C) 2009-2010 Satoshi Nakamoto
* Copyright (C) 2009-2015 The Bitcoin Core developers
* Copyright (C) 2016 Tom Zander <tomz@freedommail.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FLOWEE_MINER_H
#define FLOWEE_MINER_H
#include "primitives/block.h"
#include <mutex>
#include <boost/thread.hpp>
class CBlockIndex;
namespace Validation { class Engine; }
class CChainParams;
class CReserveKey;
class CScript;
class CWallet;
namespace Consensus { struct Params; }
struct CBlockTemplate
{
CBlock block;
std::vector<CAmount> vTxFees;
};
class Mining
{
public:
/**
* parse /a the public address and return a script used to make it
* a coinbase.
* @throws runtime_error when the input is not usable
*/
static CScript ScriptForCoinbase(const std::string &publicAddress);
/** Run the miner threads */
static void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams& chainparams, const std::string &GetCoinbase);
static void Stop();
static Mining *instance();
Mining();
~Mining();
/**
* Generate a new block, without valid proof-of-work, using the global settings
*/
CBlockTemplate* CreateNewBlock() const;
/** Generate a new block, without valid proof-of-work */
CBlockTemplate* CreateNewBlock(Validation::Engine &validationEngine) const;
/** Modify the extranonce in a block */
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
static int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
CScript GetCoinbase() const;
void SetCoinbase(const CScript &coinbase);
private:
boost::thread_group* m_minerThreads;
static Mining *s_instance;
mutable std::mutex m_lock;
CScript m_coinbase;
std::vector<unsigned char> m_coinbaseComment;
uint256 m_hashPrevBlock;
};
#endif