2020-12-31 09:48:25 +01:00
|
|
|
// Copyright (c) 2017-2020 The Bitcoin Core developers
|
2017-03-27 12:14:43 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_RPC_BLOCKCHAIN_H
|
|
|
|
#define BITCOIN_RPC_BLOCKCHAIN_H
|
|
|
|
|
2018-08-08 14:40:56 -04:00
|
|
|
#include <amount.h>
|
2019-05-02 14:34:09 -04:00
|
|
|
#include <sync.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
extern RecursiveMutex cs_main;
|
2018-08-08 14:40:56 -04:00
|
|
|
|
2017-03-27 16:12:02 +02:00
|
|
|
class CBlock;
|
2017-03-27 12:14:43 +02:00
|
|
|
class CBlockIndex;
|
2020-07-28 19:12:50 +02:00
|
|
|
class CBlockPolicyEstimator;
|
2019-02-23 11:04:20 -05:00
|
|
|
class CTxMemPool;
|
2020-04-18 09:55:57 -04:00
|
|
|
class ChainstateManager;
|
2017-03-27 16:12:02 +02:00
|
|
|
class UniValue;
|
2019-09-17 19:05:26 -04:00
|
|
|
struct NodeContext;
|
2020-04-17 11:28:45 -04:00
|
|
|
namespace util {
|
|
|
|
class Ref;
|
|
|
|
} // namespace util
|
2017-03-27 12:14:43 +02:00
|
|
|
|
2018-08-08 14:40:56 -04:00
|
|
|
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
|
|
|
|
|
2017-03-27 12:14:43 +02:00
|
|
|
/**
|
2018-09-03 09:35:41 +08:00
|
|
|
* Get the difficulty of the net wrt to the given block index.
|
2017-03-27 12:14:43 +02:00
|
|
|
*
|
|
|
|
* @return A floating point number that is a multiple of the main net minimum
|
|
|
|
* difficulty (4295032833 hashes).
|
|
|
|
*/
|
2018-05-20 14:04:15 -07:00
|
|
|
double GetDifficulty(const CBlockIndex* blockindex);
|
2017-03-27 12:14:43 +02:00
|
|
|
|
2017-03-27 16:04:31 +02:00
|
|
|
/** Callback for when block tip changed. */
|
2020-03-04 19:48:32 +02:00
|
|
|
void RPCNotifyBlockChange(const CBlockIndex*);
|
2017-03-27 16:04:31 +02:00
|
|
|
|
2017-03-27 16:12:02 +02:00
|
|
|
/** Block description to JSON */
|
2019-05-02 14:34:09 -04:00
|
|
|
UniValue blockToJSON(const CBlock& block, const CBlockIndex* tip, const CBlockIndex* blockindex, bool txDetails = false) LOCKS_EXCLUDED(cs_main);
|
2017-03-27 16:12:02 +02:00
|
|
|
|
|
|
|
/** Mempool information to JSON */
|
2019-02-23 11:04:20 -05:00
|
|
|
UniValue MempoolInfoToJSON(const CTxMemPool& pool);
|
2017-03-27 16:12:02 +02:00
|
|
|
|
|
|
|
/** Mempool to JSON */
|
Add 'sequence' zmq publisher to track all block (dis)connects, mempool deltas
Using the zmq notifications to avoid excessive mempool polling can be difficult
given the current notifications available. It announces all transactions
being added to mempool or included in blocks, but announces no evictions
and gives no indication if the transaction is in the mempool or a block.
Block notifications for zmq are also substandard, in that it only announces
block tips, while all block transactions are still announced.
This commit adds a unified stream which can be used to closely track mempool:
1) getrawmempool to fill out mempool knowledge
2) if txhash is announced, add or remove from set
based on add/remove flag
3) if blockhash is announced, get block txn list,
remove from those transactions local view of mempool
4) if we drop a sequence number, go to (1)
The mempool sequence number starts at the value 1, and
increments each time a transaction enters the mempool,
or is evicted from the mempool for any reason, including
block inclusion. The mempool sequence number is published
via ZMQ for any transaction-related notification.
These features allow for ZMQ/RPC consumer to track mempool
state in a more exacting way, without unnecesarily polling
getrawmempool. See interface_zmq.py::test_mempool_sync for
example usage.
2020-09-04 11:55:58 -04:00
|
|
|
UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose = false, bool include_mempool_sequence = false);
|
2017-03-27 16:12:02 +02:00
|
|
|
|
|
|
|
/** Block header to JSON */
|
2019-05-02 14:34:09 -04:00
|
|
|
UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex) LOCKS_EXCLUDED(cs_main);
|
2017-03-27 16:12:02 +02:00
|
|
|
|
2018-08-08 14:40:56 -04:00
|
|
|
/** Used by getblockstats to get feerates at different percentiles by weight */
|
|
|
|
void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
|
|
|
|
|
2020-04-17 11:28:45 -04:00
|
|
|
NodeContext& EnsureNodeContext(const util::Ref& context);
|
|
|
|
CTxMemPool& EnsureMemPool(const util::Ref& context);
|
2020-04-18 09:55:57 -04:00
|
|
|
ChainstateManager& EnsureChainman(const util::Ref& context);
|
2020-07-28 19:12:50 +02:00
|
|
|
CBlockPolicyEstimator& EnsureFeeEstimator(const util::Ref& context);
|
2019-11-08 10:29:41 -05:00
|
|
|
|
2017-03-27 12:14:43 +02:00
|
|
|
#endif
|