|
5 | 5 |
|
6 | 6 | #include "application/impl/app_configuration_impl.hpp"
|
7 | 7 |
|
8 |
| -#include <fstream> |
9 | 8 | #include <limits>
|
10 | 9 | #include <regex>
|
11 | 10 | #include <string>
|
|
18 | 17 | #include <boost/uuid/uuid_io.hpp>
|
19 | 18 | #include <charconv>
|
20 | 19 | #include <libp2p/layer/websocket/wss_adaptor.hpp>
|
21 |
| -#include "filesystem/common.hpp" |
22 | 20 |
|
23 | 21 | #include "api/transport/tuner.hpp"
|
24 | 22 | #include "application/build_version.hpp"
|
|
27 | 25 | #include "chain_spec_impl.hpp"
|
28 | 26 | #include "common/hexutil.hpp"
|
29 | 27 | #include "common/uri.hpp"
|
| 28 | +#include "filesystem/common.hpp" |
30 | 29 | #include "filesystem/directories.hpp"
|
31 | 30 | #include "utils/read_file.hpp"
|
32 | 31 |
|
@@ -248,7 +247,8 @@ namespace kagome::application {
|
248 | 247 | offchain_worker_mode_{def_offchain_worker_mode},
|
249 | 248 | enable_offchain_indexing_{def_enable_offchain_indexing},
|
250 | 249 | recovery_state_{def_block_to_recover},
|
251 |
| - db_cache_size_{def_db_cache_size} { |
| 250 | + db_cache_size_{def_db_cache_size}, |
| 251 | + state_pruning_depth_{} { |
252 | 252 | SL_INFO(logger_, "Soramitsu Kagome started. Version: {} ", buildVersion());
|
253 | 253 | }
|
254 | 254 |
|
@@ -790,6 +790,7 @@ namespace kagome::application {
|
790 | 790 | ("db-cache", po::value<uint32_t>()->default_value(def_db_cache_size), "Limit the memory the database cache can use <MiB>")
|
791 | 791 | ("enable-offchain-indexing", po::value<bool>(), "enable Offchain Indexing API, which allow block import to write to offchain DB)")
|
792 | 792 | ("recovery", po::value<std::string>(), "recovers block storage to state after provided block presented by number or hash, and stop after that")
|
| 793 | + ("state-pruning", po::value<std::string>()->default_value("archive"), "state pruning policy. 'archive' or the number of finalized blocks to keep.") |
793 | 794 | ;
|
794 | 795 |
|
795 | 796 | po::options_description network_desc("Network options");
|
@@ -1445,6 +1446,27 @@ namespace kagome::application {
|
1445 | 1446 | return false;
|
1446 | 1447 | }
|
1447 | 1448 |
|
| 1449 | + if (auto state_pruning_opt = |
| 1450 | + find_argument<std::string>(vm, "state-pruning"); |
| 1451 | + state_pruning_opt.has_value()) { |
| 1452 | + const auto& val = state_pruning_opt.value(); |
| 1453 | + if (val == "archive") { |
| 1454 | + state_pruning_depth_ = std::nullopt; |
| 1455 | + } else { |
| 1456 | + uint32_t depth{}; |
| 1457 | + auto [_, err] = std::from_chars(&*val.begin(), &*val.end(), depth); |
| 1458 | + if (err == std::errc{}) { |
| 1459 | + state_pruning_depth_ = depth; |
| 1460 | + } else { |
| 1461 | + SL_ERROR(logger_, |
| 1462 | + "Failed to parse state-pruning param (which should be " |
| 1463 | + "either 'archive' or an integer): {}", |
| 1464 | + err); |
| 1465 | + return false; |
| 1466 | + } |
| 1467 | + } |
| 1468 | + } |
| 1469 | + |
1448 | 1470 | // if something wrong with config print help message
|
1449 | 1471 | if (not validate_config()) {
|
1450 | 1472 | std::cout << desc << std::endl;
|
|
0 commit comments