Electroneum
Loading...
Searching...
No Matches
electroneum::basic::Validators Class Reference

#include <validators.h>

Public Member Functions

 Validators (cryptonote::BlockchainDB &db, cryptonote::i_cryptonote_protocol *pprotocol, bool testnet)
vector< string > getApplicablePublicKeys (uint64_t height, bool convert_to_byte=false)
Validator getValidatorByKey (string key)
bool loadValidatorsList ()
string getSerializedValidatorList ()
list_update_outcome setValidatorsList (const string &v_list, bool saveToDB, bool isEmergencyUpdate=false)
bool isValid ()
bool isEnabled ()
void enable ()
void on_idle ()

Detailed Description

Definition at line 139 of file validators.h.

Constructor & Destructor Documentation

◆ Validators()

electroneum::basic::Validators::Validators ( cryptonote::BlockchainDB & db,
cryptonote::i_cryptonote_protocol * pprotocol,
bool testnet )
inlineexplicit

Definition at line 169 of file validators.h.

169 : m_db(db), current_list_timestamp(0) {
170 testnet ? this->http_client.set_server(this->testnet_endpoint_addr, this->testnet_endpoint_port, boost::none) :
171 this->http_client.set_server(this->endpoint_addr, this->endpoint_port, boost::none);
172 this->testnet = testnet;
173 this->m_p2p = pprotocol;
174 };
Here is the call graph for this function:

Member Function Documentation

◆ enable()

void electroneum::basic::Validators::enable ( )
inline

Definition at line 274 of file validators.h.

◆ getApplicablePublicKeys()

vector< string > electroneum::basic::Validators::getApplicablePublicKeys ( uint64_t height,
bool convert_to_byte = false )
inline

Definition at line 176 of file validators.h.

176 {
177 vector<string> keys;
178 all_of(this->list.begin(), this->list.end(), [&height, &keys, &convert_to_byte](std::unique_ptr<Validator> &v) {
179 if (v->isWithinRange(height)) {
180 const string k = convert_to_byte ? unhex(v->getPublicKey()) : v->getPublicKey();
181 keys.push_back(k);
182 }
183 return true;
184 });
185 return keys;
186 }
uint64_t height

◆ getSerializedValidatorList()

string electroneum::basic::Validators::getSerializedValidatorList ( )
inline

Definition at line 250 of file validators.h.

250 {
251
252 if(this->status == ValidatorsState::NeedsUpdate || this->status == ValidatorsState::Expired) {
253 return string("");
254 }
255
256 return this->serialized_v_list;
257 }
::std::string string

◆ getValidatorByKey()

Validator electroneum::basic::Validators::getValidatorByKey ( string key)
inline

Definition at line 188 of file validators.h.

188 {
189 Validator result;
190 all_of(this->list.begin(), this->list.end(), [&key, &result](std::unique_ptr<Validator> &v) {
191 if (v->getPublicKey() == key) {
192 result = v->getValidatorInfo();
193 }
194 return true;
195 });
196 return result;
197 }
const char * key

◆ isEnabled()

bool electroneum::basic::Validators::isEnabled ( )
inline

Definition at line 270 of file validators.h.

270 {
271 return this->status != ValidatorsState::Disabled;
272 }

◆ isValid()

bool electroneum::basic::Validators::isValid ( )
inline

Definition at line 266 of file validators.h.

266 {
267 return this->status == ValidatorsState::Valid || this->status == ValidatorsState::NeedsUpdate;
268 }

◆ loadValidatorsList()

bool electroneum::basic::Validators::loadValidatorsList ( )
inline

Definition at line 199 of file validators.h.

199 {
200
201 v_list_struct_request req = AUTO_VAL_INIT(req);
202 v_list_struct res = AUTO_VAL_INIT(res);
203
204 // Try fetching list of validators from JSON endpoint
205 if(this->status == ValidatorsState::Invalid || this->status == ValidatorsState::Expired || this->status == ValidatorsState::NeedsUpdate) {
206 if (!get_http_json("/", res, this->http_client)) {
207 LOG_PRINT_L1("Unable to get validator_list json from " << this->endpoint_addr << ":" << this->endpoint_port);
208 }
209
210 this->timeout = 60*60*24;
211 list_update_outcome isJsonValid = validate_and_update(res, true);
212
213 if(isJsonValid == list_update_outcome::Success || isJsonValid == list_update_outcome::Same_List) {
214 MGINFO("Validators list loaded from JSON endpoint! Refresh in 12 hours");
215 return true;
216 }
217
218 //If the list was old, invalid, or had an invalid public key, try getting list of validators from peers
219 if(m_p2p->request_validators_list_to_all() && this->status == ValidatorsState::Valid) {
220 this->timeout = 60*60*1;
221 MGINFO("Validators list loaded from peers! Refresh in 1 hour");
222 return true;
223 }
224
225 //Keep returning true during the grace period
226 if(this->status == ValidatorsState::NeedsUpdate) {
227 LOG_PRINT_L1("Validator List Grace Period");
228 return true;
229 }
230
231 // If we there was an issue with getting the list from peers, try getting list of validators from db.
232 // This code will only be reached at the daemon start if both endpoint & p2p list are unavailable.
233 string v = m_db.get_validator_list();
234 if(!v.empty()) {
235 this->timeout = 60*60*1;
236 list_update_outcome isDBListValid = setValidatorsList(v, true);
238 MGINFO("Validators list loaded from database! Refresh in 1 hour");
239 return true;
240 }
241 }
242
243
244 return false;
245 }
246
247 return true;
248 }
list_update_outcome setValidatorsList(const string &v_list, bool saveToDB, bool isEmergencyUpdate=false)
Definition validators.h:259
const char * res
#define AUTO_VAL_INIT(v)
#define LOG_PRINT_L1(x)
#define MGINFO(x)
Definition misc_log_ex.h:80
bool get_http_json(const boost::string_ref uri, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_idle()

void electroneum::basic::Validators::on_idle ( )
inline

Definition at line 278 of file validators.h.

278 {
279 if(this->status != ValidatorsState::Disabled) {
280 if(validate_expiration() != ValidatorsState::Valid) {
281 m_load_validators_interval.do_call(boost::bind(&Validators::loadValidatorsList, this));
282 }
283 }
284 }
Here is the call graph for this function:

◆ setValidatorsList()

list_update_outcome electroneum::basic::Validators::setValidatorsList ( const string & v_list,
bool saveToDB,
bool isEmergencyUpdate = false )
inline

Definition at line 259 of file validators.h.

259 {
260 v_list_struct res = AUTO_VAL_INIT(res);
261 load_t_from_json(res, v_list);
262
263 return validate_and_update(res, saveToDB, isEmergencyUpdate);
264 }
bool load_t_from_json(t_struct &out, const std::string &json_buff)
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/cryptonote_basic/validators.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/cryptonote_basic/validators.cpp