Resolve #59: Add witnesses to default genesis in witness_node

This commit is contained in:
Nathan Hourt 2015-06-19 10:23:32 -04:00
parent be5a8c6365
commit 6fc11bb5fd
2 changed files with 30 additions and 3 deletions

View file

@ -150,6 +150,18 @@ namespace detail {
auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan"))); auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
genesis_state_type initial_state; genesis_state_type initial_state;
secret_hash_type::encoder enc;
fc::raw::pack(enc, nathan_key);
fc::raw::pack(enc, secret_hash_type());
for( int i = 0; i < 10; ++i )
{
initial_state.allocation_targets.emplace_back("init"+fc::to_string(i), nathan_key.get_public_key(), 0, true);
initial_state.initial_committee.push_back({"init"+fc::to_string(i)});
}
initial_state.initial_witnesses = vector<genesis_state_type::initial_witness_type>(10, {"committee-account",
nathan_key.get_public_key(),
secret_hash_type::hash(enc.result())});
initial_state.allocation_targets.emplace_back("nathan", address(public_key_type(nathan_key.get_public_key())), 1); initial_state.allocation_targets.emplace_back("nathan", address(public_key_type(nathan_key.get_public_key())), 1);
if( _options->count("genesis-json") ) if( _options->count("genesis-json") )
initial_state = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()).as<genesis_state_type>(); initial_state = fc::json::from_file(_options->at("genesis-json").as<boost::filesystem::path>()).as<genesis_state_type>();

View file

@ -19,6 +19,7 @@
#include <graphene/chain/database.hpp> #include <graphene/chain/database.hpp>
#include <graphene/chain/witness_object.hpp> #include <graphene/chain/witness_object.hpp>
#include <graphene/chain/key_object.hpp>
#include <graphene/time/time.hpp> #include <graphene/time/time.hpp>
#include <fc/thread/thread.hpp> #include <fc/thread/thread.hpp>
@ -36,7 +37,7 @@ void witness_plugin::plugin_set_program_options(
("witness-id,w", bpo::value<vector<string>>()->composing()->multitoken(), ("witness-id,w", bpo::value<vector<string>>()->composing()->multitoken(),
"ID of witness controlled by this node (e.g. \"1.7.0\", quotes are required, may specify multiple times)") "ID of witness controlled by this node (e.g. \"1.7.0\", quotes are required, may specify multiple times)")
("private-key", bpo::value<vector<string>>()->composing()->multitoken()-> ("private-key", bpo::value<vector<string>>()->composing()->multitoken()->
DEFAULT_VALUE_VECTOR(std::make_pair(chain::key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("null_key"))))), DEFAULT_VALUE_VECTOR(std::make_pair(chain::key_id_type(), fc::ecc::private_key::regenerate(fc::sha256::hash(std::string("nathan"))))),
"Tuple of [key ID, private key] (may specify multiple times)") "Tuple of [key ID, private key] (may specify multiple times)")
; ;
config_file_options.add(command_line_options); config_file_options.add(command_line_options);
@ -63,9 +64,23 @@ void witness_plugin::plugin_startup()
graphene::time::now(); graphene::time::now();
for( auto wit : _witnesses ) for( auto wit : _witnesses )
{ {
auto key = wit(database()).signing_key; auto signing_key = wit(database()).signing_key;
if( !_private_keys.count(key) ) if( !_private_keys.count(signing_key) )
{ {
// Check if it's a duplicate key of one I do have
bool found_duplicate = false;
for( const auto& private_key : _private_keys )
if( chain::public_key_type(private_key.second.get_public_key()) == signing_key(database()).key_address() )
{
ilog("Found duplicate key: ${k1} matches ${k2}; using this key to sign for ${w}",
("k1", private_key.first)("k2", signing_key)("w", wit));
_private_keys[signing_key] = private_key.second;
found_duplicate = true;
break;
}
if( found_duplicate )
continue;
elog("Unable to find key for witness ${w}. Removing it from my witnesses.", ("w", wit)); elog("Unable to find key for witness ${w}. Removing it from my witnesses.", ("w", wit));
bad_wits.insert(wit); bad_wits.insert(wit);
} }