From de87e1b82cfc147d7a4082d65f7a4c6046567d04 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Wed, 12 Jan 2022 16:55:45 -0600 Subject: [PATCH] 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. --- libraries/app/application.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index d0da6de6..80248fc6 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -321,9 +321,8 @@ namespace detail { ilog("Initializing database..."); if( _options->count("genesis-json") ) { - std::string genesis_str; - fc::read_file_contents( _options->at("genesis-json").as(), genesis_str ); - genesis_state_type genesis = fc::json::from_string( genesis_str ).as( 20 ); + genesis_state_type genesis = fc::json::from_file( _options->at("genesis-json").as()).as( 20 ); + std::string genesis_str = fc::json::to_string(genesis) + "\n"; bool modified_genesis = false; if( _options->count("genesis-timestamp") ) {