forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCP.h
136 lines (106 loc) · 4.21 KB
/
SCP.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#pragma once
// Copyright 2014 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include <chrono>
#include <functional>
#include <map>
#include <memory>
#include <set>
#include "crypto/SecretKey.h"
#include "lib/json/json-forwards.h"
#include "scp/SCPDriver.h"
namespace stellar
{
class Node;
class Slot;
class LocalNode;
typedef std::shared_ptr<SCPQuorumSet> SCPQuorumSetPtr;
class SCP
{
SCPDriver& mDriver;
public:
SCP(SCPDriver& driver, NodeID const& nodeID, bool isValidator,
SCPQuorumSet const& qSetLocal);
SCPDriver&
getDriver()
{
return mDriver;
}
SCPDriver const&
getDriver() const
{
return mDriver;
}
enum EnvelopeState
{
INVALID, // the envelope is considered invalid
VALID // the envelope is valid
};
// this is the main entry point of the SCP library
// it processes the envelope, updates the internal state and
// invokes the appropriate methods
EnvelopeState receiveEnvelope(SCPEnvelope const& envelope);
// Submit a value to consider for slotIndex
// previousValue is the value from slotIndex-1
bool nominate(uint64 slotIndex, Value const& value,
Value const& previousValue);
// stops nomination for a slot
void stopNomination(uint64 slotIndex);
// Local QuorumSet interface (can be dynamically updated)
void updateLocalQuorumSet(SCPQuorumSet const& qSet);
SCPQuorumSet const& getLocalQuorumSet();
// Local nodeID getter
NodeID const& getLocalNodeID();
// returns the local node descriptor
std::shared_ptr<LocalNode> getLocalNode();
Json::Value getJsonInfo(size_t limit, bool fullKeys = false);
// summary: only return object counts
// index = 0 for returning information for all slots
Json::Value getJsonQuorumInfo(NodeID const& id, bool summary,
bool fullKeys = false, uint64 index = 0);
// Purges all data relative to all the slots whose slotIndex is smaller
// than the specified `maxSlotIndex`.
void purgeSlots(uint64 maxSlotIndex);
// Returns whether the local node is a validator.
bool isValidator();
// returns the validation state of the given slot
bool isSlotFullyValidated(uint64 slotIndex);
// Helpers for monitoring and reporting the internal memory-usage of the SCP
// protocol to system metric reporters.
size_t getKnownSlotsCount() const;
size_t getCumulativeStatemtCount() const;
// returns the latest messages sent for the given slot
std::vector<SCPEnvelope> getLatestMessagesSend(uint64 slotIndex);
// forces the state to match the one in the envelope
// this is used when rebuilding the state after a crash for example
void setStateFromEnvelope(uint64 slotIndex, SCPEnvelope const& e);
// check if we are holding some slots
bool empty() const;
// return lowest slot index value
uint64 getLowSlotIndex() const;
// return highest slot index value
uint64 getHighSlotIndex() const;
// returns all messages for the slot
std::vector<SCPEnvelope> getCurrentState(uint64 slotIndex);
// returns the latest message from a node
// or nullptr if not found
SCPEnvelope const* getLatestMessage(NodeID const& id);
// returns messages that contributed to externalizing the slot
// (or empty if the slot didn't externalize)
std::vector<SCPEnvelope> getExternalizingState(uint64 slotIndex);
// ** helper methods to stringify ballot for logging
std::string getValueString(Value const& v) const;
std::string ballotToStr(SCPBallot const& ballot) const;
std::string ballotToStr(std::unique_ptr<SCPBallot> const& ballot) const;
std::string envToStr(SCPEnvelope const& envelope,
bool fullKeys = false) const;
std::string envToStr(SCPStatement const& st, bool fullKeys = false) const;
protected:
std::shared_ptr<LocalNode> mLocalNode;
std::map<uint64, std::shared_ptr<Slot>> mKnownSlots;
// Slot getter
std::shared_ptr<Slot> getSlot(uint64 slotIndex, bool create);
friend class TestSCP;
};
}