1616#include < gsl/util>
1717#include < nlohmann/json.hpp>
1818
19- #include < silkworm/buildinfo.h>
2019#include < silkworm/core/chain/config.hpp>
2120#include < silkworm/core/execution/call_tracer.hpp>
2221#include < silkworm/core/execution/execution.hpp>
2625#include < silkworm/db/blocks/transactions/txn_to_block_index.hpp>
2726#include < silkworm/db/buffer.hpp>
2827#include < silkworm/db/capi/component.hpp>
29- #include < silkworm/db/datastore/kvdb/mdbx_version.hpp>
3028#include < silkworm/db/datastore/snapshots/index_builder.hpp>
3129#include < silkworm/db/datastore/snapshots/segment/segment_reader.hpp>
3230#include < silkworm/db/stages.hpp>
4644
4745#include " common/parse_path.hpp"
4846#include " instance.hpp"
49- #include " make_log_settings.hpp"
5047
5148using namespace std ::chrono_literals;
5249using namespace silkworm ;
@@ -68,18 +65,6 @@ struct ExecutionProgress {
6865 float batch_progress_perc{0.0 };
6966};
7067
71- // ! Generate log arguments for Silkworm library version
72- static log::Args log_args_for_version () {
73- const auto build_info{silkworm_get_buildinfo ()};
74- return {
75- " git_branch" ,
76- std::string (build_info->git_branch ),
77- " git_tag" ,
78- std::string (build_info->project_version ),
79- " git_commit" ,
80- std::string (build_info->git_commit_hash )};
81- }
82-
8368// ! Generate log arguments for execution flush at specified block
8469static log::Args log_args_for_exec_flush (const db::Buffer& state_buffer, uint64_t max_batch_size, uint64_t current_block) {
8570 return {
@@ -159,78 +144,6 @@ class SignalHandlerGuard {
159144 ~SignalHandlerGuard () { SignalHandler::reset (); }
160145};
161146
162- static bool is_initialized{false };
163-
164- SILKWORM_EXPORT int silkworm_init (SilkwormHandle* handle, const struct SilkwormSettings * settings) SILKWORM_NOEXCEPT {
165- using namespace datastore ::kvdb;
166-
167- if (!handle) {
168- return SILKWORM_INVALID_HANDLE;
169- }
170- if (!settings) {
171- return SILKWORM_INVALID_SETTINGS;
172- }
173- if (std::strlen (settings->data_dir_path ) == 0 ) {
174- return SILKWORM_INVALID_PATH;
175- }
176- if (!is_compatible_mdbx_version (settings->libmdbx_version , silkworm_libmdbx_version (), MdbxVersionCheck::kExact )) {
177- return SILKWORM_INCOMPATIBLE_LIBMDBX;
178- }
179- if (is_initialized) {
180- return SILKWORM_TOO_MANY_INSTANCES;
181- }
182-
183- is_initialized = true ;
184-
185- log::Settings log_settings{make_log_settings (settings->log_verbosity )};
186- log::init (log_settings);
187-
188- auto data_dir_path = parse_path (settings->data_dir_path );
189-
190- silkworm::capi::CommonComponent common{
191- .log_settings = std::move (log_settings),
192- .context_pool_settings = {
193- .num_contexts = settings->num_contexts > 0 ? settings->num_contexts : silkworm::concurrency::kDefaultNumContexts ,
194- },
195- .data_dir_path = data_dir_path,
196- };
197-
198- auto snapshots_dir_path = DataDirectory{data_dir_path}.snapshots ().path ();
199- auto blocks_repository = db::blocks::make_blocks_repository (
200- snapshots_dir_path,
201- /* open = */ false ,
202- settings->blocks_repo_index_salt );
203- auto state_repository_latest = db::state::make_state_repository_latest (
204- snapshots_dir_path,
205- /* open = */ false ,
206- settings->state_repo_index_salt );
207- auto state_repository_historical = db::state::make_state_repository_historical (
208- snapshots_dir_path,
209- /* open = */ false ,
210- settings->state_repo_index_salt );
211- db::capi::Component db{
212- .blocks_repository = std::move (blocks_repository),
213- .state_repository_latest = std::move (state_repository_latest),
214- .state_repository_historical = std::move (state_repository_historical),
215- .chaindata = {},
216- };
217-
218- // NOLINTNEXTLINE(bugprone-unhandled-exception-at-new)
219- *handle = new ::SilkwormInstance{};
220- (*handle)->common = std::move (common);
221- (*handle)->db = std::make_unique<db::capi::Component>(std::move (db));
222-
223- log::Info{" Silkworm build info" , log_args_for_version ()}; // NOLINT(*-unused-raii)
224-
225- log::Debug{" [1/12] Silkworm initialized" , // NOLINT(*-unused-raii)
226- {" data_dir" , data_dir_path.string (),
227- " snapshots_dir" , snapshots_dir_path.string (),
228- " blocks_repo_index_salt" , std::to_string (settings->blocks_repo_index_salt ),
229- " state_repo_index_salt" , std::to_string (settings->state_repo_index_salt )}};
230-
231- return SILKWORM_OK;
232- }
233-
234147class BlockProvider {
235148 static constexpr size_t kTxnRefreshThreshold {100 };
236149
@@ -742,14 +655,3 @@ SILKWORM_EXPORT int silkworm_block_exec_end(SilkwormHandle handle, MDBX_txn* mdb
742655
743656 return SILKWORM_OK;
744657}
745-
746- SILKWORM_EXPORT int silkworm_fini (SilkwormHandle handle) SILKWORM_NOEXCEPT {
747- if (!handle) {
748- return SILKWORM_INVALID_HANDLE;
749- }
750- delete handle;
751-
752- is_initialized = false ;
753-
754- return SILKWORM_OK;
755- }
0 commit comments