From 27d049b3b18feabfc220584d671c7e86b58c2c58 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 7 Jun 2023 10:52:11 -0500 Subject: [PATCH] GH-1217 Fix process of state-history-log-retain-blocks option --- .../state_history_plugin.cpp | 2 +- .../tests/plugin_config_test.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/state_history_plugin/state_history_plugin.cpp b/plugins/state_history_plugin/state_history_plugin.cpp index 16a5d56379..7d301f30df 100644 --- a/plugins/state_history_plugin/state_history_plugin.cpp +++ b/plugins/state_history_plugin/state_history_plugin.cpp @@ -463,7 +463,7 @@ void state_history_plugin::plugin_initialize(const variables_map& options) { state_history_log_config ship_log_conf; if (options.count("state-history-log-retain-blocks")) { - auto ship_log_prune_conf = ship_log_conf.emplace(); + auto& ship_log_prune_conf = ship_log_conf.emplace(); ship_log_prune_conf.prune_blocks = options.at("state-history-log-retain-blocks").as(); //the arbitrary limit of 1000 here is mainly so that there is enough buffer for newly applied forks to be delivered to clients // before getting pruned out. ideally pruning would have been smart enough to know not to prune reversible blocks diff --git a/plugins/state_history_plugin/tests/plugin_config_test.cpp b/plugins/state_history_plugin/tests/plugin_config_test.cpp index b369e9c9d3..48bf085757 100644 --- a/plugins/state_history_plugin/tests/plugin_config_test.cpp +++ b/plugins/state_history_plugin/tests/plugin_config_test.cpp @@ -20,4 +20,21 @@ BOOST_AUTO_TEST_CASE(state_history_plugin_default_tests) { auto* config = std::get_if(&plugin.trace_log()->config()); BOOST_REQUIRE(config); BOOST_CHECK_EQUAL(config->max_retained_files, UINT32_MAX); +} + +BOOST_AUTO_TEST_CASE(state_history_plugin_retain_blocks_tests) { + fc::temp_directory tmp; + appbase::scoped_app app; + + auto tmp_path = tmp.path().string(); + std::array args = {"test_state_history", "--trace-history", "--state-history-log-retain-blocks", "4242", + "--disable-replay-opts", "--data-dir", tmp_path.c_str()}; + + BOOST_CHECK(app->initialize(args.size(), const_cast(args.data()))); + auto& plugin = app->get_plugin(); + + BOOST_REQUIRE(plugin.trace_log()); + auto* config = std::get_if(&plugin.trace_log()->config()); + BOOST_REQUIRE(config); + BOOST_CHECK_EQUAL(config->prune_blocks, 4242); } \ No newline at end of file