Skip to content

Commit 4a24bb5

Browse files
authored
Feature: storage, database (#31)
* feature: in-memory storage Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: spaced storage Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: database config Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: fd limit * feature: rocksdb as spaced storage impl Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: literals for tests * feature: storage tests * feature: target all_tests * feature: chain spec * refactor: code format Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * feature: parse values with suffix Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: CI issue Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * refactor: move parsing functions to separated util-header Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * fix: review issue Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> * clean: remove migration feature Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]> --------- Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent 43a6950 commit 4a24bb5

File tree

80 files changed

+3382
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3382
-81
lines changed

CMakeLists.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ endif ()
1313

1414
set(CMAKE_CXX_STANDARD 20)
1515
set(CMAKE_CXX_STANDARD_REQUIRED ON)
16-
set(CMAKE_CXX_EXTENSIONS OFF)
16+
set(CMAKE_CXX_EXTENSIONS ON)
1717
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1818
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API ON)
1919

2020
project(cpp-jam
2121
VERSION 0.0.1
22-
LANGUAGES CXX
22+
LANGUAGES CXX C
2323
)
2424

2525
if(DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
@@ -66,7 +66,7 @@ find_package(Python3 REQUIRED)
6666
find_package(PkgConfig REQUIRED)
6767
pkg_check_modules(libb2 REQUIRED IMPORTED_TARGET GLOBAL libb2)
6868

69-
find_package(Boost CONFIG REQUIRED COMPONENTS algorithm outcome program_options)
69+
find_package(Boost CONFIG REQUIRED COMPONENTS algorithm outcome program_options property_tree)
7070
find_package(fmt CONFIG REQUIRED)
7171
find_package(yaml-cpp CONFIG REQUIRED)
7272
find_package(qdrvm-crates CONFIG REQUIRED)
@@ -75,19 +75,29 @@ find_package(soralog CONFIG REQUIRED)
7575
find_package(Boost.DI CONFIG REQUIRED)
7676
find_package(qtils CONFIG REQUIRED)
7777
find_package(prometheus-cpp CONFIG REQUIRED)
78+
find_package(RocksDB CONFIG REQUIRED)
7879

79-
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
80-
add_compile_options(-fmodules-ts)
81-
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
82-
add_compile_options(-fmodules)
83-
endif()
80+
# TODO Temporarily commented out until gcc is updated (gcc-13 crashes because of this).
81+
# if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
82+
# add_compile_options(-fmodules-ts)
83+
# elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
84+
# add_compile_options(-fmodules)
85+
# endif()
8486

8587
add_library(headers INTERFACE)
8688
target_include_directories(headers INTERFACE
87-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src_>
89+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
90+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
91+
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated>
8892
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
8993
)
9094

95+
include_directories(${CMAKE_SOURCE_DIR})
96+
include_directories(${CMAKE_SOURCE_DIR}/src)
97+
include_directories(${CMAKE_SOURCE_DIR}/src/third_party)
98+
include_directories(${CMAKE_SOURCE_DIR}/src/_TODO)
99+
include_directories(${CMAKE_BINARY_DIR}/generated)
100+
91101
add_subdirectory(src)
92102

93103
if (TESTING)

example/config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ general:
22
name: NameFromConfig
33
base_path: /tmp/jam_node
44
modules_dir: modules
5+
spec_file: jamduna-spec.json
6+
7+
database:
8+
directory: db
9+
cache_size: 1G
510

611
metrics:
712
enabled: true
@@ -33,4 +38,5 @@ logging:
3338
- name: application
3439
- name: rpc
3540
- name: metrics
36-
- name: threads
41+
- name: threads
42+
- name: storage

example/jamduna-spec.json

Lines changed: 34 additions & 0 deletions
Large diffs are not rendered by default.

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ add_subdirectory(se)
3131

3232
# Modules subsystem
3333
add_subdirectory(modules)
34+
35+
# Storage
36+
add_subdirectory(storage)
37+
38+
# Utilities
39+
add_subdirectory(utils)

src/app/CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,47 @@ add_library(build_version
2626
${CMAKE_BINARY_DIR}/generated/app/build_version.cpp
2727
)
2828

29-
add_library(app_configuration SHARED configuration.cpp)
29+
add_library(app_configuration SHARED
30+
configuration.cpp
31+
)
3032
target_link_libraries(app_configuration
3133
Boost::boost
3234
fmt::fmt
3335
)
3436

35-
add_library(app_configurator SHARED configurator.cpp)
37+
add_library(app_configurator SHARED
38+
configurator.cpp
39+
)
3640
target_link_libraries(app_configurator
3741
app_configuration
3842
yaml-cpp::yaml-cpp
3943
Boost::program_options
4044
build_version
4145
)
4246

43-
add_library(app_state_manager SHARED impl/state_manager_impl.cpp)
47+
add_library(app_state_manager SHARED
48+
impl/state_manager_impl.cpp
49+
)
4450
target_link_libraries(app_state_manager
4551
qtils::qtils
4652
logger
4753
)
4854

49-
add_library(application SHARED impl/application_impl.cpp)
55+
add_library(chain_spec SHARED
56+
impl/chain_spec_impl.cpp
57+
)
58+
target_link_libraries(chain_spec
59+
logger
60+
Boost::property_tree
61+
app_configuration
62+
)
63+
add_dependencies(chain_spec
64+
generate_common_types
65+
)
66+
67+
add_library(application SHARED
68+
impl/application_impl.cpp
69+
)
5070
target_link_libraries(application
5171
qtils::qtils
5272
app_configuration

src/app/chain_spec.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright Quadrivium LLC
3+
* All Rights Reserved
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <string>
10+
#include <vector>
11+
12+
#include <qtils/byte_vec.hpp>
13+
14+
#include "jam_types/types.tmp.hpp"
15+
16+
namespace jam {
17+
18+
using NodeAddress = Stub;
19+
20+
}
21+
22+
namespace jam::app {
23+
24+
class ChainSpec {
25+
public:
26+
virtual ~ChainSpec() = default;
27+
28+
virtual const std::string &id() const = 0;
29+
30+
virtual const std::vector<NodeAddress> &bootNodes() const = 0;
31+
32+
virtual const qtils::ByteVec &genesisHeader() const = 0;
33+
34+
virtual const std::map<qtils::ByteVec, qtils::ByteVec> &genesisState()
35+
const = 0;
36+
};
37+
38+
} // namespace jam::app

src/app/configuration.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ namespace jam::app {
1010
Configuration::Configuration()
1111
: version_("undefined"),
1212
name_("unnamed"),
13+
database_{
14+
.directory = "db",
15+
.cache_size = 1 << 30,
16+
},
1317
metrics_{
1418
.endpoint{},
1519
.enabled{},
@@ -27,10 +31,18 @@ namespace jam::app {
2731
return base_path_;
2832
}
2933

34+
const std::filesystem::path &Configuration::specFile() const {
35+
return spec_file_;
36+
}
37+
3038
const std::filesystem::path &Configuration::modulesDir() const {
3139
return modules_dir_;
3240
}
3341

42+
const Configuration::DatabaseConfig &Configuration::database() const {
43+
return database_;
44+
}
45+
3446
const Configuration::MetricsConfig &Configuration::metrics() const {
3547
return metrics_;
3648
}

src/app/configuration.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,38 @@
88
#include <filesystem>
99
#include <string>
1010

11-
#include <filesystem>
1211
#include <boost/asio/ip/tcp.hpp>
1312
#include <utils/ctor_limiters.hpp>
1413

1514
namespace jam::app {
16-
class Configuration final : Singleton<Configuration> {
15+
class Configuration : Singleton<Configuration> {
1716
public:
1817
using Endpoint = boost::asio::ip::tcp::endpoint;
1918

19+
struct DatabaseConfig {
20+
std::filesystem::path directory = "db";
21+
size_t cache_size = 1 << 30; // 1GiB
22+
};
23+
2024
struct MetricsConfig {
2125
Endpoint endpoint;
2226
std::optional<bool> enabled;
2327
};
2428

2529
Configuration();
30+
virtual ~Configuration() = default;
2631

2732
// /// Generate yaml-file with actual config
2833
// virtual void generateConfigFile() const = 0;
2934

3035
[[nodiscard]] virtual const std::string &nodeVersion() const;
3136
[[nodiscard]] virtual const std::string &nodeName() const;
3237
[[nodiscard]] virtual const std::filesystem::path &basePath() const;
38+
[[nodiscard]] virtual const std::filesystem::path &specFile() const;
3339
[[nodiscard]] virtual const std::filesystem::path &modulesDir() const;
3440

41+
[[nodiscard]] virtual const DatabaseConfig &database() const;
42+
3543
[[nodiscard]] virtual const MetricsConfig &metrics() const;
3644

3745
private:
@@ -40,8 +48,10 @@ namespace jam::app {
4048
std::string version_;
4149
std::string name_;
4250
std::filesystem::path base_path_;
51+
std::filesystem::path spec_file_;
4352
std::filesystem::path modules_dir_;
4453

54+
DatabaseConfig database_;
4555
MetricsConfig metrics_;
4656
};
4757

0 commit comments

Comments
 (0)