Load PAK arguments from config and disk on startup

This commit is contained in:
Gregory Sanders 2018-12-18 13:51:19 -05:00
parent d391782cd9
commit 5b6d767b61
2 changed files with 64 additions and 1 deletions

View file

@ -40,6 +40,7 @@ void SetupChainParamsBaseOptions()
gArgs.AddArg("-fedpegscript", "The script for the federated peg.", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-enforce_pak", "Causes standardness checks to enforce Pegout Authorization Key(PAK) validation, and miner to include PAK commitments when configured. Can not be set when acceptnonstdtx is set to true.", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-multi_data_permitted", "Allow relay of multiple OP_RETURN outputs. (default: true)", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-pak", "Entries in the PAK list. Order of entries matter.", false, OptionsCategory::ELEMENTS);
}
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

View file

@ -63,6 +63,8 @@
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <primitives/pak.h> // CPAKList
#if ENABLE_ZMQ
#include <zmq/zmqnotificationinterface.h>
#include <zmq/zmqrpc.h>
@ -1760,7 +1762,67 @@ bool AppInitMain()
return false;
}
// ********************************************************* Step 13: finished
// ********************************************************* Step 13: Load PAK List
//Entire list of PAK entries from conf must be of valid format
std::vector<std::string> pak_list_str = gArgs.GetArgs("-pak");
bool valid_paklist = true;
bool is_reject = false;
std::vector<std::vector<unsigned char> > offline_keys;
std::vector<std::vector<unsigned char> > online_keys;
for (unsigned int i = 0; i < pak_list_str.size(); i++) {
if (pak_list_str[i] == "reject") {
is_reject = true;
continue;
}
size_t colon_index = pak_list_str[i].find(":");
if (colon_index == std::string::npos) {
valid_paklist = false;
break;
}
std::string offline = pak_list_str[i].substr(0, colon_index);
std::string online = pak_list_str[i].substr(colon_index + 1);
if (!IsHex(offline) || !IsHex(online) || offline.size() != 66 || online.size() != 66) {
valid_paklist = false;
break;
}
online_keys.push_back(ParseHex(online));
offline_keys.push_back(ParseHex(offline));
}
// pak=reject must be alone
if (is_reject && offline_keys.size() > 0)
valid_paklist = false;
if (!valid_paklist)
return InitError(_("ERROR: Invalid PAK entries given in conf file."));
if (is_reject || offline_keys.size() > 0) {
CPAKList paklist;
if(CPAKList::FromBytes(paklist, offline_keys, online_keys, is_reject)) {
g_paklist_config = paklist;
} else {
return InitError(_("ERROR: Invalid PAK entries given in conf file."));
}
} else {
g_paklist_config = boost::none;
}
// Read and parse committed pak list from disk
CPAKList paklist;
offline_keys.resize(0);
online_keys.resize(0);
bool reject;
if (pblocktree->ReadPAKList(offline_keys, online_keys, reject)) {
if (CPAKList::FromBytes(paklist, offline_keys, online_keys, reject)) {
g_paklist_blockchain = paklist;
} else {
return InitError(_("ERROR: Read invalid PAK list."));
}
}
// ********************************************************* Step 14: finished
SetRPCWarmupFinished();