提交 959d0c1e 编写于 作者: B Brian Johnson

Reverted manipulating genesis file in script and added flag to launcher to...

Reverted manipulating genesis file in script and added flag to launcher to edit genesis file. GH #5674
上级 a10b3468
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <fc/crypto/private_key.hpp> #include <fc/crypto/private_key.hpp>
#include <fc/crypto/public_key.hpp> #include <fc/crypto/public_key.hpp>
#include <fc/io/json.hpp> #include <fc/io/json.hpp>
#include <fc/optional.hpp>
#include <fc/network/ip.hpp> #include <fc/network/ip.hpp>
#include <fc/reflect/variant.hpp> #include <fc/reflect/variant.hpp>
#include <fc/log/logger_config.hpp> #include <fc/log/logger_config.hpp>
...@@ -387,63 +388,64 @@ string producer_names::producer_name(unsigned int producer_number) { ...@@ -387,63 +388,64 @@ string producer_names::producer_name(unsigned int producer_number) {
} }
struct launcher_def { struct launcher_def {
bool force_overwrite; bool force_overwrite;
size_t total_nodes; size_t total_nodes;
size_t prod_nodes; size_t prod_nodes;
size_t producers; size_t producers;
size_t next_node; size_t next_node;
string shape; string shape;
p2p_plugin p2p; p2p_plugin p2p;
allowed_connection allowed_connections = PC_NONE; allowed_connection allowed_connections = PC_NONE;
bfs::path genesis; bfs::path genesis;
bfs::path output; bfs::path output;
bfs::path host_map_file; bfs::path host_map_file;
bfs::path server_ident_file; bfs::path server_ident_file;
bfs::path stage; bfs::path stage;
string erd; string erd;
bfs::path config_dir_base; bfs::path config_dir_base;
bfs::path data_dir_base; bfs::path data_dir_base;
bool skip_transaction_signatures = false; bool skip_transaction_signatures = false;
string eosd_extra_args; string eosd_extra_args;
std::map<uint,string> specific_nodeos_args; std::map<uint,string> specific_nodeos_args;
testnet_def network; testnet_def network;
string gelf_endpoint; string gelf_endpoint;
vector <string> aliases; vector <string> aliases;
vector <host_def> bindings; vector <host_def> bindings;
int per_host = 0; int per_host = 0;
last_run_def last_run; last_run_def last_run;
int start_delay = 0; int start_delay = 0;
bool gelf_enabled; bool gelf_enabled;
bool nogen; bool nogen;
bool boot; bool boot;
bool add_enable_stale_production = false; bool add_enable_stale_production = false;
string launch_name; string launch_name;
string launch_time; string launch_time;
server_identities servers; server_identities servers;
producer_set_def producer_set; producer_set_def producer_set;
vector<string> genesis_block;
string start_temp; string start_temp;
string start_script; string start_script;
fc::optional<uint32_t> max_block_cpu_usage;
eosio::chain::genesis_state genesis_from_file;
void assign_name (eosd_def &node, bool is_bios); void assign_name (eosd_def &node, bool is_bios);
void set_options (bpo::options_description &cli); void set_options (bpo::options_description &cli);
void initialize (const variables_map &vmap); void initialize (const variables_map &vmap);
void init_genesis (); void init_genesis ();
void load_servers (); void load_servers ();
bool generate (); bool generate ();
void define_network (); void define_network ();
void bind_nodes (); void bind_nodes ();
host_def *find_host (const string &name); host_def *find_host (const string &name);
host_def *find_host_by_name_or_address (const string &name); host_def *find_host_by_name_or_address (const string &name);
host_def *deploy_config_files (tn_node_def &node); host_def *deploy_config_files (tn_node_def &node);
string compose_scp_command (const host_def &host, const bfs::path &source, string compose_scp_command (const host_def &host, const bfs::path &source,
const bfs::path &destination); const bfs::path &destination);
void write_config_file (tn_node_def &node); void write_config_file (tn_node_def &node);
void write_logging_config_file (tn_node_def &node); void write_logging_config_file (tn_node_def &node);
void write_genesis_file (tn_node_def &node); void write_genesis_file (tn_node_def &node);
void write_setprods_file (); void write_setprods_file ();
void write_bios_boot (); void write_bios_boot ();
bool is_bios_ndx (size_t ndx); bool is_bios_ndx (size_t ndx);
...@@ -451,25 +453,25 @@ struct launcher_def { ...@@ -451,25 +453,25 @@ struct launcher_def {
bool next_ndx(size_t &ndx); bool next_ndx(size_t &ndx);
size_t skip_ndx (size_t from, size_t offset); size_t skip_ndx (size_t from, size_t offset);
void make_ring (); void make_ring ();
void make_star (); void make_star ();
void make_mesh (); void make_mesh ();
void make_custom (); void make_custom ();
void write_dot_file (); void write_dot_file ();
void format_ssh (const string &cmd, const string &host_name, string &ssh_cmd_line); void format_ssh (const string &cmd, const string &host_name, string &ssh_cmd_line);
void do_command(const host_def& host, const string& name, vector<pair<string, string>> env_pairs, const string& cmd); void do_command(const host_def& host, const string& name, vector<pair<string, string>> env_pairs, const string& cmd);
bool do_ssh (const string &cmd, const string &host_name); bool do_ssh (const string &cmd, const string &host_name);
void prep_remote_config_dir (eosd_def &node, host_def *host); void prep_remote_config_dir (eosd_def &node, host_def *host);
void launch (eosd_def &node, string &gts); void launch (eosd_def &node, string &gts);
void kill (launch_modes mode, string sig_opt); void kill (launch_modes mode, string sig_opt);
static string get_node_num(uint16_t node_num); static string get_node_num(uint16_t node_num);
pair<host_def, eosd_def> find_node(uint16_t node_num); pair<host_def, eosd_def> find_node(uint16_t node_num);
vector<pair<host_def, eosd_def>> get_nodes(const string& node_number_list); vector<pair<host_def, eosd_def>> get_nodes(const string& node_number_list);
void bounce (const string& node_numbers); void bounce (const string& node_numbers);
void down (const string& node_numbers); void down (const string& node_numbers);
void roll (const string& host_names); void roll (const string& host_names);
void start_all (string &gts, launch_modes mode); void start_all (string &gts, launch_modes mode);
void ignite (); void ignite ();
}; };
void void
...@@ -498,6 +500,7 @@ launcher_def::set_options (bpo::options_description &cfg) { ...@@ -498,6 +500,7 @@ launcher_def::set_options (bpo::options_description &cfg) {
("gelf-endpoint",bpo::value<string>(&gelf_endpoint)->default_value("10.160.11.21:12201"),"hostname:port or ip:port of GELF endpoint") ("gelf-endpoint",bpo::value<string>(&gelf_endpoint)->default_value("10.160.11.21:12201"),"hostname:port or ip:port of GELF endpoint")
("template",bpo::value<string>(&start_temp)->default_value("testnet.template"),"the startup script template") ("template",bpo::value<string>(&start_temp)->default_value("testnet.template"),"the startup script template")
("script",bpo::value<string>(&start_script)->default_value("bios_boot.sh"),"the generated startup script name") ("script",bpo::value<string>(&start_script)->default_value("bios_boot.sh"),"the generated startup script name")
("max-block-cpu-usage",bpo::value<uint32_t>(),"")
; ;
} }
...@@ -529,6 +532,10 @@ launcher_def::initialize (const variables_map &vmap) { ...@@ -529,6 +532,10 @@ launcher_def::initialize (const variables_map &vmap) {
} }
} }
if (vmap.count("max-block-cpu-usage")) {
max_block_cpu_usage = vmap["max-block-cpu-usage"].as<uint32_t>();
}
if (vmap.count("specific-num")) { if (vmap.count("specific-num")) {
const auto specific_nums = vmap["specific-num"].as<vector<uint>>(); const auto specific_nums = vmap["specific-num"].as<vector<uint>>();
const auto specific_args = vmap["specific-nodeos"].as<vector<string>>(); const auto specific_args = vmap["specific-nodeos"].as<vector<string>>();
...@@ -1157,27 +1164,18 @@ launcher_def::write_logging_config_file(tn_node_def &node) { ...@@ -1157,27 +1164,18 @@ launcher_def::write_logging_config_file(tn_node_def &node) {
void void
launcher_def::init_genesis () { launcher_def::init_genesis () {
bfs::path genesis_path = genesis.is_complete() ? genesis : bfs::current_path() / genesis; const bfs::path genesis_path = genesis.is_complete() ? genesis : bfs::current_path() / genesis;
bfs::ifstream src(genesis_path); if (!bfs::exists(genesis_path)) {
if (!src.good()) {
cout << "generating default genesis file " << genesis_path << endl; cout << "generating default genesis file " << genesis_path << endl;
eosio::chain::genesis_state default_genesis; eosio::chain::genesis_state default_genesis;
fc::json::save_to_file( default_genesis, genesis_path, true ); fc::json::save_to_file( default_genesis, genesis_path, true );
src.open(genesis_path);
} }
string bioskey = string(network.nodes["bios"].keys[0].get_public_key()); string bioskey = string(network.nodes["bios"].keys[0].get_public_key());
string str;
string prefix("initial_key"); fc::json::from_file(genesis_path).as<eosio::chain::genesis_state>(genesis_from_file);
while(getline(src,str)) { genesis_from_file.initial_key = public_key_type(bioskey);
size_t pos = str.find(prefix); if (max_block_cpu_usage)
if (pos != string::npos) { genesis_from_file.initial_configuration.max_block_cpu_usage = *max_block_cpu_usage;
size_t cut = str.find("EOS",pos);
genesis_block.push_back(str.substr(0,cut) + bioskey + "\",");
}
else {
genesis_block.push_back(str);
}
}
} }
void void
...@@ -1191,10 +1189,7 @@ launcher_def::write_genesis_file(tn_node_def &node) { ...@@ -1191,10 +1189,7 @@ launcher_def::write_genesis_file(tn_node_def &node) {
} }
filename = dd / "genesis.json"; filename = dd / "genesis.json";
bfs::ofstream gf ( dd / "genesis.json"); fc::json::save_to_file( genesis_from_file, dd / "genesis.json", true );
for (auto &line : genesis_block) {
gf << line << "\n";
}
} }
void void
......
...@@ -171,22 +171,8 @@ class Cluster(object): ...@@ -171,22 +171,8 @@ class Cluster(object):
cmdArr.append("--specific-nodeos") cmdArr.append("--specific-nodeos")
cmdArr.append(arg) cmdArr.append(arg)
genesisFile=open("./genesis.json", "r") cmdArr.append("--max-block-cpu-usage")
genesisJsonStr=genesisFile.read() cmdArr.append(str(2000000))
genesisFile.close()
genesisObject=json.loads(genesisJsonStr)
initialConfiguration=genesisObject["initial_configuration"]
maxBlockCpuUsage=initialConfiguration.get("max_block_cpu_usage",200000)
initialConfiguration["max_block_cpu_usage"]=maxBlockCpuUsage*10
tempGenesisFileName="./tempGenesis.json"
genesisFile=open(tempGenesisFileName,"w")
genesisFile.write(json.dumps(genesisObject, indent=2))
genesisFile.close()
self.filesToCleanup.append(tempGenesisFileName)
cmdArr.append("--genesis")
cmdArr.append(tempGenesisFileName)
# must be last cmdArr.append before subprocess.call, so that everything is on the command line # must be last cmdArr.append before subprocess.call, so that everything is on the command line
# before constructing the shape.json file for "bridge" # before constructing the shape.json file for "bridge"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册