mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 11:13:02 +02:00
txgraph: Introduce BlockBuilder interface (feature)
This interface lets one iterate efficiently over the chunks of the main graph in a TxGraph, in the same order as CompareMainOrder. Each chunk can be marked as "included" or "skipped" (and in the latter case, dependent chunks will be skipped).
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <compare>
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include <util/feefrac.h>
|
||||
|
||||
@@ -168,6 +170,29 @@ public:
|
||||
* usable without type-conversion. */
|
||||
virtual std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>> GetMainStagingDiagrams() noexcept = 0;
|
||||
|
||||
/** Interface returned by GetBlockBuilder. */
|
||||
class BlockBuilder
|
||||
{
|
||||
protected:
|
||||
/** Make constructor non-public (use TxGraph::GetBlockBuilder()). */
|
||||
BlockBuilder() noexcept = default;
|
||||
public:
|
||||
/** Support safe inheritance. */
|
||||
virtual ~BlockBuilder() = default;
|
||||
/** Get the chunk that is currently suggested to be included, plus its feerate, if any. */
|
||||
virtual std::optional<std::pair<std::vector<Ref*>, FeePerWeight>> GetCurrentChunk() noexcept = 0;
|
||||
/** Mark the current chunk as included, and progress to the next one. */
|
||||
virtual void Include() noexcept = 0;
|
||||
/** Mark the current chunk as skipped, and progress to the next one. Further chunks from
|
||||
* the same cluster as the current one will not be reported anymore. */
|
||||
virtual void Skip() noexcept = 0;
|
||||
};
|
||||
|
||||
/** Construct a block builder, drawing chunks in order, from the main graph, which cannot be
|
||||
* oversized. While the returned object exists, no mutators on the main graph are allowed.
|
||||
* The BlockBuilder object must not outlive the TxGraph it was created with. */
|
||||
virtual std::unique_ptr<BlockBuilder> GetBlockBuilder() noexcept = 0;
|
||||
|
||||
/** Perform an internal consistency check on this object. */
|
||||
virtual void SanityCheck() const = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user