Canonicalize chain ID calculation

When using an external genesis file, it doesn't make sense to calculate
the chain ID as the literal text contents of the file, which are quite
volatile. Rather, it should be calculated based on the logical content
of the file. Serialize the genesis object to get a canonical
representation, and calculate the chain ID off of that.
This commit is contained in:
Nathaniel 2022-01-12 16:55:45 -06:00
parent c833ca646f
commit de87e1b82c
No known key found for this signature in database
GPG key ID: B4344309A110851E

View file

@ -321,9 +321,8 @@ namespace detail {
ilog("Initializing database..."); ilog("Initializing database...");
if( _options->count("genesis-json") ) if( _options->count("genesis-json") )
{ {
std::string genesis_str; genesis_state_type genesis = fc::json::from_file( _options->at("genesis-json").as<boost::filesystem::path>()).as<genesis_state_type>( 20 );
fc::read_file_contents( _options->at("genesis-json").as<boost::filesystem::path>(), genesis_str ); std::string genesis_str = fc::json::to_string(genesis) + "\n";
genesis_state_type genesis = fc::json::from_string( genesis_str ).as<genesis_state_type>( 20 );
bool modified_genesis = false; bool modified_genesis = false;
if( _options->count("genesis-timestamp") ) if( _options->count("genesis-timestamp") )
{ {