38 : publicKey(publicKey), startHeight(startHeight), endHeight(endHeight), name(name), domain(domain), page_link(page_link) {}
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 LOG_PRINT_L1(
"Validator list received is older than our local list.");
99 if(isEmergencyUpdate && (std::time(
nullptr) - obj.list_timestamp < 18000)){
104 }
else if(obj.list_timestamp == this->current_list_timestamp) {
106 this->last_updated =
time(
nullptr);
109 LOG_PRINT_L1(
"Validator list received has the same timestamp than our local list.");
110 if(isEmergencyUpdate && (std::time(
nullptr) - obj.list_timestamp < 18000)){
118 for (
const auto &v : obj.validators) {
119 this->addOrUpdate(v.validation_public_key, v.valid_from_height, v.valid_to_height, v.name, v.domain, v.page_link);
121 if(!v.name.empty()) {
122 MGINFO(v.name <<
" | Public Key: " << v.validation_public_key);
131 all_of(this->list.begin(), this->list.end(), [&v_counter](std::unique_ptr<Validator> &v) {
132 LOG_PRINT_L2(
"Validator " << v_counter <<
" (" << v->getName() <<
") :: PublicKey=" << v->getPublicKey() <<
",\n FromHeight=" << v->getStartHeight() <<
", ToHeight=" << v->getEndHeight());
139 this->last_updated =
time(
nullptr);
140 this->current_list_timestamp = obj.list_timestamp;
144 m_db.set_validator_list(this->serialized_v_list, this->last_updated + this->timeout);
150 if (isEmergencyUpdate && (std::time(
nullptr) - obj.list_timestamp < 18000)){
156 void Validators::add(
const string &
key,
uint64_t startHeight,
uint64_t endHeight,
string name,
string domain,
string page_link) {
157 if (!this->exists(
key)) this->list.emplace_back(std::unique_ptr<Validator>(
new Validator(
key, startHeight, endHeight, name, domain, page_link)));
160 void Validators::addOrUpdate(
const string &
key,
uint64_t startHeight,
uint64_t endHeight,
string name,
string domain,
string page_link) {
161 this->exists(
key) ? this->update(
key, endHeight, name, domain, page_link) : this->list.emplace_back(
162 std::unique_ptr<Validator>(new Validator(
key, startHeight, endHeight,
name, domain, page_link)));
165 std::unique_ptr<Validator> Validators::find(
const string &
key) {
166 auto it = find_if(this->list.begin(), this->list.end(), [&
key](std::unique_ptr<Validator> &v) {
167 return v->getPublicKey() == key;
169 return std::move(*it);
172 bool Validators::exists(
const string &
key) {
174 all_of(this->list.begin(), this->list.end(), [&
key, &found](std::unique_ptr<Validator> &v) {
175 if (v->getPublicKey() == key) {
184 void Validators::update(
const string &
key,
uint64_t endHeight,
string name,
string domain,
string page_link) {
185 find_if(this->list.begin(), this->list.end(), [&
key, &endHeight, &name, &domain, &page_link](std::unique_ptr<Validator> &v) {
186 if (v->getPublicKey() == key) {
187 v->setEndHeight(endHeight);
189 v->setDomain(domain);
190 v->setPageLink(page_link);
198 if((
time(
nullptr) - this->last_updated) >= this->timeout && this->status == ValidatorsState::Valid) {
199 this->status = ValidatorsState::NeedsUpdate;
202 if((
time(
nullptr) - this->last_updated) >= this->timeout + this->timeout_grace_period && this->status == ValidatorsState::NeedsUpdate) {
203 this->status = ValidatorsState::Expired;