-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathservice.hpp
99 lines (78 loc) · 2.56 KB
/
service.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <string>
#include "primitives/common.hpp"
namespace kagome::telemetry {
/**
* Possible block origins enumeration
*
* https://github.com/paritytech/substrate/blob/42b2d623d058197aebc3c737fb44fbbf278a85b4/primitives/consensus/common/src/lib.rs#L64
*/
enum class BlockOrigin : uint8_t {
/// Genesis block built into the client.
kGenesis,
/// Block is part of the initial sync with the network.
kNetworkInitialSync,
/// Block was broadcasted on the network.
kNetworkBroadcast,
/// Block that was received from the network and validated in the consensus
/// process.
kConsensusBroadcast,
/// Block that was collated by this node.
kOwn,
/// Block was imported from a file.
kFile,
};
/**
* Telemetry service interface
*/
class TelemetryService {
public:
virtual ~TelemetryService() = default;
/**
* Used to initially inform the service about the genesis hash.
* @param hash genesis hash for the network
*
* Allows to avoid circular references in classes dependency tree
*/
virtual void setGenesisBlockHash(const primitives::BlockHash &hash) = 0;
/**
* Let the telemetry service know that the node has been in a synchronized
* state at least once.
*
* After this call all kNetworkInitialSync events will be treated as
* kNetworkBroadcast
*/
virtual void notifyWasSynchronized() = 0;
/**
* Inform about last known block
* @param info - block info
* @param origin - source of the block
*/
virtual void notifyBlockImported(const primitives::BlockInfo &info,
BlockOrigin origin) = 0;
/**
* Inform about the last finalized block
* @param info - block info
*/
virtual void notifyBlockFinalized(const primitives::BlockInfo &info) = 0;
/**
* Send imported+finalized blocks info immediately and reset periodic timer
*/
virtual void pushBlockStats() = 0;
/**
* Telemetry service status
* @return true - when application configured to broadcast telemetry
*/
virtual bool isEnabled() const = 0;
};
using Telemetry = std::shared_ptr<TelemetryService>;
/// Sets an instance of telemetry service for latter usage by reporters
void setTelemetryService(Telemetry service);
/// Returns preliminary initialized instance of telemetry service
Telemetry createTelemetryService();
} // namespace kagome::telemetry