32 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 33 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "Validators" 44 MGINFO(
"Loading Validator List...");
47 std::vector<std::string> testnet_vl_publicKeys = {
"443ED0A8172A8A79E606771679F06BD5A9AAFC65F01C8BB94A1A01257393A96E",
48 "9C2F74BE7292BD9DE1DBF15667E48778F3971EEBB85FFCB265B8D03356A5F9C2",
49 "171BE7497D81281C36E62D865BFDA8C86CC76171580CB50FDA4C64C14C184773"};
51 std::vector<std::string> mainnet_vl_publicKeys = {
"814A92F191735D989FFD3A2A7B33A2EE3ED6AD746B1530AED8E91E3B259DCD4B",
52 "38BBE01388170750FAF8FE9B9C31DF6432987283F49171DA86039566C3288BF9",
53 "8BC9D71CE4CD0DE0D50F45C8619257399B108D35C8CBB72FC29B38DFE3847769"};
55 std::vector<std::string> vl_publicKeys = this->testnet ? testnet_vl_publicKeys : mainnet_vl_publicKeys;
58 if (
res.pubkeys.size() != vl_publicKeys.size()) {
63 if (
res.signatures.size() != vl_publicKeys.size()) {
69 if (
res.pubkeys != vl_publicKeys) {
70 LOG_PRINT_L1(
"Validator list has one or more invalid public keys.");
75 for (
unsigned int i = 0; i < vl_publicKeys.size(); ++i){
77 LOG_PRINT_L1(
"Validator list has an invalid signature and will be ignored.");
86 all_of(this->list.begin(), this->list.end(), [&v_counter](std::unique_ptr<Validator> &v) {
87 LOG_PRINT_L2(
"Validator " << v_counter <<
" (" << v->getName() <<
") :: PublicKey=" << v->getPublicKey() <<
",\n FromHeight=" << v->getStartHeight() <<
", ToHeight=" << v->getEndHeight());
95 if(obj.list_timestamp < this->current_list_timestamp) {
97 this->last_updated =
time(
nullptr);
100 LOG_PRINT_L1(
"Validator list received is older than our local list.");
102 if(isEmergencyUpdate && (
std::time(
nullptr) - obj.list_timestamp < 18000)){
107 }
else if(obj.list_timestamp == this->current_list_timestamp) {
109 this->last_updated =
time(
nullptr);
112 LOG_PRINT_L1(
"Validator list received has the same timestamp than our local list.");
113 if(isEmergencyUpdate && (
std::time(
nullptr) - obj.list_timestamp < 18000)){
121 for (
const auto &v : obj.validators) {
122 this->addOrUpdate(v.validation_public_key, v.valid_from_height, v.valid_to_height, v.name, v.domain, v.page_link);
124 if(!v.name.empty()) {
125 MGINFO(v.name <<
" | Public Key: " << v.validation_public_key);
134 all_of(this->list.begin(), this->list.end(), [&v_counter](std::unique_ptr<Validator> &v) {
135 LOG_PRINT_L2(
"Validator " << v_counter <<
" (" << v->getName() <<
") :: PublicKey=" << v->getPublicKey() <<
",\n FromHeight=" << v->getStartHeight() <<
", ToHeight=" << v->getEndHeight());
142 this->last_updated =
time(
nullptr);
143 this->current_list_timestamp = obj.list_timestamp;
153 if (isEmergencyUpdate && (
std::time(
nullptr) - obj.list_timestamp < 18000)){
159 void Validators::add(
const string &
key,
uint64_t startHeight,
uint64_t endHeight,
string name,
string domain,
string page_link) {
160 if (!this->exists(
key)) this->list.emplace_back(std::unique_ptr<Validator>(
new Validator(
key, startHeight, endHeight,
name, domain, page_link)));
163 void Validators::addOrUpdate(
const string &
key,
uint64_t startHeight,
uint64_t endHeight,
string name,
string domain,
string page_link) {
164 this->exists(
key) ? this->update(
key, endHeight,
name, domain, page_link) : this->list.emplace_back(
165 std::unique_ptr<Validator>(new Validator(
key, startHeight, endHeight,
name, domain, page_link)));
168 std::unique_ptr<Validator> Validators::find(
const string &
key) {
169 auto it = find_if(this->list.begin(), this->list.end(), [&
key](std::unique_ptr<Validator> &v) {
170 return v->getPublicKey() ==
key;
175 bool Validators::exists(
const string &
key) {
177 all_of(this->list.begin(), this->list.end(), [&
key, &found](std::unique_ptr<Validator> &v) {
178 if (v->getPublicKey() ==
key) {
187 void Validators::update(
const string &
key,
uint64_t endHeight,
string name,
string domain,
string page_link) {
188 find_if(this->list.begin(), this->list.end(), [&
key, &endHeight, &
name, &domain, &page_link](std::unique_ptr<Validator> &v) {
189 if (v->getPublicKey() ==
key) {
190 v->setEndHeight(endHeight);
192 v->setDomain(domain);
193 v->setPageLink(page_link);
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
bool load_t_from_json(t_struct &out, const std::string &json_buff)
bool verify_signature(const std::string &message, const std::string &publicKey, const std::string &signature)
unsigned __int64 uint64_t
std::string base64_decode(const std::string &val)
const T & move(const T &t)
virtual void set_validator_list(std::string, uint32_t expiration_date)=0
#define MGINFO_MAGENTA(x)
std::string to_string(t_connection_type type)