Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Improve error handling when writing out protocol features #7167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/fc
48 changes: 28 additions & 20 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,28 +486,31 @@ protocol_feature_set initialize_protocol_features( const fc::path& p, bool popul
auto output_protocol_feature = [&p]( const builtin_protocol_feature& f, const digest_type& feature_digest ) {
static constexpr int max_tries = 10;

string filename_base( "BUILTIN-" );
filename_base += builtin_protocol_feature_codename( f.get_codename() );

string filename = filename_base+ ".json";
int i = 0;
for( ;
i < max_tries && fc::exists( p / filename );
++i, filename = filename_base + "-" + std::to_string(i) + ".json" )
;
string filename( "BUILTIN-" );
filename += builtin_protocol_feature_codename( f.get_codename() );
filename += ".json";

auto file_path = p / filename;

EOS_ASSERT( i < max_tries, plugin_exception,
"Could not save builtin protocol feature with codename '${codename}' due to file name conflicts",
EOS_ASSERT( !fc::exists( file_path ), plugin_exception,
"Could not save builtin protocol feature with codename '${codename}' because a file at the following path already exists: ${path}",
("codename", builtin_protocol_feature_codename( f.get_codename() ))
("path", file_path.generic_string())
);

fc::json::save_to_file( f, p / filename );

ilog( "Saved default specification for builtin protocol feature '${codename}' (with digest of '${digest}') to: ${path}",
("codename", builtin_protocol_feature_codename(f.get_codename()))
("digest", feature_digest)
("path", (p / filename).generic_string())
);
if( fc::json::save_to_file( f, file_path ) ) {
ilog( "Saved default specification for builtin protocol feature '${codename}' (with digest of '${digest}') to: ${path}",
("codename", builtin_protocol_feature_codename(f.get_codename()))
("digest", feature_digest)
("path", file_path.generic_string())
);
} else {
elog( "Error occurred while writing default specification for builtin protocol feature '${codename}' (with digest of '${digest}') to: ${path}",
("codename", builtin_protocol_feature_codename(f.get_codename()))
("digest", feature_digest)
("path", file_path.generic_string())
);
}
};

std::function<digest_type(builtin_protocol_feature_t)> add_missing_builtins =
Expand Down Expand Up @@ -693,8 +696,13 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
p = bfs::current_path() / p;
}

fc::json::save_to_file( gs, p, true );
ilog( "Saved genesis JSON to '${path}'", ("path", p.generic_string()));
EOS_ASSERT( fc::json::save_to_file( gs, p, true ),
misc_exception,
"Error occurred while writing genesis JSON to '${path}'",
("path", p.generic_string())
);

ilog( "Saved genesis JSON to '${path}'", ("path", p.generic_string()) );
}

EOS_THROW( extract_genesis_state_exception, "extracted genesis state from blocks.log" );
Expand Down