Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
Loading...
Searching...
No Matches
event_projector.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <optional>
7#include <string>
8#include <string_view>
9
10#include "native.h"
11#include <asio.hpp>
12
13namespace dcn::events
14{
15 constexpr std::string_view FEED_PROJECTOR_ID = "feed";
16 constexpr std::string_view REGISTRY_PROJECTOR_ID = "registry";
17
18 // Bits in normalized_events_hot.dead_letter. A projector sets its bit when it
19 // exhausts its retry budget on a row and advances its cursor past it. Rows with
20 // any bit set are exempt from pruning, so the raw chain evidence is retained
21 // until every marking projector resolves the row and clears its bit.
22 constexpr int FEED_DEAD_LETTER_BIT = 1 << 0;
23 constexpr int REGISTRY_DEAD_LETTER_BIT = 1 << 1;
24
25 // Retry/quarantine tuning shared by the projectors.
27 {
28 // Consecutive failing passes on the same row before it is dead-lettered and
29 // the cursor advances past it. Values <= 1 dead-letter on the first failure.
30 std::size_t max_attempts = 5;
31
32 // Minimum time between idle-time dead-letter retry sweeps; dead letters are
33 // rare, so a slow cadence keeps the recovery path cheap.
34 std::int64_t sweep_interval_ms = 60'000;
35 };
36
38 {
39 int chain_id = 0;
40 std::string block_hash;
41 std::int64_t log_index = 0;
42 std::int64_t change_seq = 0;
43 std::string event_type;
44 std::string state;
45 std::string name;
46 std::string owner;
47 std::string tx_hash;
48 std::optional<std::int64_t> block_time;
49 std::string data_hex;
50 std::array<std::optional<std::string>, 4> topics;
51 std::int64_t block_number = 0;
52 std::int64_t tx_index = 0;
53 };
54
56 {
57 public:
58 virtual ~IEventProjector() = default;
59 virtual std::string_view id() const = 0;
60 virtual std::int64_t cursor() const = 0;
61 virtual asio::awaitable<std::size_t> projectBatch(std::size_t limit, std::int64_t now_ms) = 0;
62 };
63}
Definition event_projector.hpp:56
virtual asio::awaitable< std::size_t > projectBatch(std::size_t limit, std::int64_t now_ms)=0
virtual std::int64_t cursor() const =0
virtual std::string_view id() const =0
virtual ~IEventProjector()=default
Definition decoded_event.hpp:11
constexpr std::string_view FEED_PROJECTOR_ID
Definition event_projector.hpp:15
constexpr std::string_view REGISTRY_PROJECTOR_ID
Definition event_projector.hpp:16
constexpr int FEED_DEAD_LETTER_BIT
Definition event_projector.hpp:22
constexpr int REGISTRY_DEAD_LETTER_BIT
Definition event_projector.hpp:23
Definition event_projector.hpp:38
std::int64_t block_number
Definition event_projector.hpp:51
std::int64_t change_seq
Definition event_projector.hpp:42
std::string name
Definition event_projector.hpp:45
std::string block_hash
Definition event_projector.hpp:40
std::string event_type
Definition event_projector.hpp:43
std::optional< std::int64_t > block_time
Definition event_projector.hpp:48
std::array< std::optional< std::string >, 4 > topics
Definition event_projector.hpp:50
std::string tx_hash
Definition event_projector.hpp:47
std::string state
Definition event_projector.hpp:44
std::int64_t log_index
Definition event_projector.hpp:41
int chain_id
Definition event_projector.hpp:39
std::int64_t tx_index
Definition event_projector.hpp:52
std::string owner
Definition event_projector.hpp:46
std::string data_hex
Definition event_projector.hpp:49
Definition event_projector.hpp:27
std::size_t max_attempts
Definition event_projector.hpp:30
std::int64_t sweep_interval_ms
Definition event_projector.hpp:34