Skip to content
Open
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
62 changes: 62 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Generated from CLion C/C++ Code Style settings
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: true
AlignTrailingComments: false
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Allman
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ContinuationIndentWidth: 0
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '^".*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 4
InsertNewlineAtEOF: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
TabWidth: 4
PointerAlignment: Right
AlignAfterOpenBracket: DontAlign
AllowShortLambdasOnASingleLine: None
BinPackArguments: false
...
61 changes: 24 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,51 +125,38 @@ if (NOT COMPILER_SUPPORTS_AVX2)
message(WARNING "AVX2 not supported by the compiler")
endif ()

# --- Project Sources ---
SET(FILES
${CMAKE_SOURCE_DIR}/connection/connection.cpp
${CMAKE_SOURCE_DIR}/connection/connectionPool.cpp
${CMAKE_SOURCE_DIR}/connection/NodeIntroducer.cpp
${CMAKE_SOURCE_DIR}/database/db.cpp
${CMAKE_SOURCE_DIR}/database/garbageCleaner.cpp
${CMAKE_SOURCE_DIR}/Logger.cpp
${CMAKE_SOURCE_DIR}/DataProcessors.cpp
${CMAKE_SOURCE_DIR}/IOProcessor.cpp
${CMAKE_SOURCE_DIR}/LoggingEventProcessor.cpp
${CMAKE_SOURCE_DIR}/QubicServer.cpp
${CMAKE_SOURCE_DIR}/QubicIndexer.cpp
${CMAKE_SOURCE_DIR}/Config.cpp
${CMAKE_SOURCE_DIR}/bob.cpp
${CMAKE_SOURCE_DIR}/GlobalVar.cpp
${CMAKE_SOURCE_DIR}/LogEvent.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/bobAPI.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/ApiHelpers.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/querySmartContract.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/RESTServer.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/LogSubscriptionManager.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/LogWebSocket.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcMapper.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcWebSocket.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcMethods.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicSubscriptionManager.cpp
${CMAKE_SOURCE_DIR}/RESTAPI/QubicRpcHandler.cpp
)
# --- Collect sources from src/ and exclude executables/tools ---
file(GLOB_RECURSE ALL_SRC CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/src/*.c ${CMAKE_SOURCE_DIR}/src/*.cpp)

set(LIB_SOURCES)
foreach(_f IN LISTS ALL_SRC)
# exclude main executables and optional single-file tools
if(_f MATCHES "/main\\.cpp$" OR _f MATCHES "/pop10\\.cpp$" OR _f MATCHES "/migrator\\.cpp$")
continue()
endif()
list(APPEND LIB_SOURCES ${_f})
endforeach()

# Fallback: if explicit sources are required, ensure at least some files exist
if(NOT LIB_SOURCES)
message(FATAL_ERROR "No library sources found under src/.")
endif()

add_library(XKCP_avx2 STATIC XKCP/KangarooTwelve.c
XKCP/KeccakP-1600-AVX2.s
XKCP/KeccakP-1600-times4-AVX2.c
XKCP/TurboSHAKE.c
add_library(XKCP_avx2 STATIC external/XKCP/KangarooTwelve.c
external/XKCP/KeccakP-1600-AVX2.s
external/XKCP/KeccakP-1600-times4-AVX2.c
external/XKCP/TurboSHAKE.c
)

# Create a library from the source files to be shared between the main executable and tests
add_library(bob_lib STATIC ${FILES})
add_library(bob_lib STATIC ${LIB_SOURCES})
target_link_libraries(bob_lib PRIVATE redis++_static hiredis spdlog::spdlog cxxopts::cxxopts
${ZSTD_TARGET} XKCP_avx2 drogon ${JSONCPP_TARGET})


# --- Executable and Linking ---
ADD_EXECUTABLE(bob main.cpp)
ADD_EXECUTABLE(pop10 pop10.cpp)
ADD_EXECUTABLE(bob src/main.cpp)
ADD_EXECUTABLE(pop10 src/pop10.cpp)
target_link_libraries(bob PRIVATE bob_lib)
target_link_libraries(pop10 PRIVATE bob_lib)

Expand All @@ -196,6 +183,6 @@ add_custom_command(
add_custom_command(
TARGET bob POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/RESTAPI/openapi.json
${CMAKE_SOURCE_DIR}/src/rest_api/openapi.json
${CMAKE_BINARY_DIR}/openapi.json
)
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ sudo apt install -y vim net-tools tmux cmake git libjsoncpp-dev \

#### 2. Install KeyDB

KeyDB is a Redis-compatible database required by Bob. Follow the [KeyDB installation guide](KEYDB_INSTALL.md).
KeyDB is a Redis-compatible database required by Bob. Follow the [KeyDB installation guide](doc/KEYDB_INSTALL.md).

Optionally, install KVRocks for additional disk-based persistence: [KVRocks installation guide](KVROCKS_INSTALL.MD).
Optionally, install KVRocks for additional disk-based persistence: [KVRocks installation guide](doc/KVROCKS_INSTALL.MD).

#### 3. Build Bob

Expand Down Expand Up @@ -181,13 +181,13 @@ curl -s -X POST http://localhost:40420/qubic \
## Useful Resources

### Using Bob
- [Ethereum-like JSON-RPC (HTTP/WS)](QUBIC_JSON_RPC.md)
- [REST API Endpoints](REST_API.md)
- [What is a Logging Event in Qubic?](LOGGING_IN_QUBIC.MD)
- [Mastering the findlog Method](FINDLOG.MD)
- [Dealing with Transactions and Logging](DEAL_WITH_TX.MD)
- [Improve Stability via Kernel Buffer Size](KERN_BUF_SIZE.MD)
- [Ethereum-like JSON-RPC (HTTP/WS)](doc/QUBIC_JSON_RPC.md)
- [REST API Endpoints](doc/REST_API.md)
- [What is a Logging Event in Qubic?](doc/LOGGING_IN_QUBIC.MD)
- [Mastering the findlog Method](doc/FINDLOG.MD)
- [Dealing with Transactions and Logging](doc/DEAL_WITH_TX.MD)
- [Improve Stability via Kernel Buffer Size](doc/KERN_BUF_SIZE.MD)

### Inside Bob
- [Anatomy of Bob](ANATOMY_OF_BOB.MD)
- [How the Indexer Indexes Qubic Data](INDEXER_INDEXING_DATA.MD)
- [Anatomy of Bob](doc/ANATOMY_OF_BOB.MD)
- [How the Indexer Indexes Qubic Data](doc/INDEXER_INDEXING_DATA.MD)
12 changes: 0 additions & 12 deletions commonFunctions.h

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion QUBIC_JSON_RPC.md → doc/QUBIC_JSON_RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This guide is for exchange developers and integrators who want to connect to Qub
> [!NOTE]
> This documentation covers the Qubic JSON-RPC 2.0 API including WebSocket subscriptions.

To have a playground, you can open [rpc_playground.html](rpc_playground.html) in your browser. Or use the published version [here on github gist](https://gistpreview.github.io/?6912d613bc27ae75126859447fca8acf).
To have a playground, you can open [rpc_playground.html](../web/rpc_playground.html) in your browser. Or use the published version [here on github gist](https://gistpreview.github.io/?6912d613bc27ae75126859447fca8acf).

## Table of Contents

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 27 additions & 31 deletions bob.cpp → src/bob.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
#include "Config.h"
#include "bob.h"
#include "src/core/k12_and_key_util.h"
#include "src/profiler/profiler.h"
#include "config.h"
#include "connection/connection.h"
#include "structs.h"
#include "Logger.h"
#include "GlobalVar.h"
#include "core/structs.h"
#include "database/db.h"
#include "Profiler.h"
#include "global_var.h"
#include "logger/logger.h"
#include "shim.h"
#include "version.h"
#include <algorithm> // std::max
#include <chrono>
#include <cstring> // memcpy
#include <cstdlib> // strtoull
#include <cstring> // memcpy
#include <limits> // std::numeric_limits
#include <algorithm> // std::max
#include <random> // std::random_device, std::mt19937
#include "K12AndKeyUtil.h"
#include <pthread.h> // thread naming on POSIX
#include "shim.h"
#include "bob.h"
#include "Version.h"
void IOVerifyThread();
void IORequestThread(ConnectionPool& conn_pool, std::chrono::milliseconds requestCycle, uint32_t futureOffset);
void EventRequestFromTrustedNode(ConnectionPool& connPoolWithPwd, std::chrono::milliseconds request_logging_cycle_ms);
#include <random> // std::random_device, std::mt19937

void tickingVerifyThread();
void tickingDataRequestThread(ConnectionPool& conn_pool, std::chrono::milliseconds requestCycle, uint32_t futureOffset);
void eventRequestFromTrustedNode(ConnectionPool& connPoolWithPwd, std::chrono::milliseconds request_logging_cycle_ms);
void connReceiver(QCPtr conn, const bool isTrustedNode);
void DataProcessorThread();
void RequestProcessorThread();
void dataProcessorThread();
void requestProcessorThread();
void verifyLoggingEvent();
void indexVerifiedTicks();
void querySmartContractThread(ConnectionPool& connPoolAll);
// Public helpers from QubicServer.cpp
bool StartQubicServer(ConnectionPool* cp, uint16_t port = 21842);
void StopQubicServer();
bool startQubicServer(ConnectionPool* cp, uint16_t port = 21842);
void stopQubicServer();
void garbageCleaner();



static inline void set_this_thread_name(const char* name_in) {
// Linux allows up to 16 bytes including null terminator
char buf[16];
Expand Down Expand Up @@ -108,7 +107,6 @@ int runBob(int argc, char *argv[])
// Put redis_url in REDIS_CONNECTION_STRING
std::string KEYDB_CONNECTION_STRING = cfg.keydb_url;


// Read server flags
const bool run_server = cfg.run_server;
unsigned int server_port_u = cfg.server_port;
Expand Down Expand Up @@ -150,14 +148,13 @@ int runBob(int argc, char *argv[])
return -1;
}
const uint16_t server_port = static_cast<uint16_t>(server_port_u);
if (!StartQubicServer(&connPool, server_port)) {
if (!startQubicServer(&connPool, server_port)) {
Logger::get()->critical("Failed to start embedded server on port {}", server_port);
return -1;
}
Logger::get()->info("Embedded server enabled on port {}", server_port);
}


uint32_t initTick = 0;
uint16_t initEpoch = 0;
uint32_t endEpochTick = 0;
Expand Down Expand Up @@ -206,11 +203,10 @@ int runBob(int argc, char *argv[])
}
}


auto request_thread = std::thread(
[&](){
set_this_thread_name("io-req");
IORequestThread(
tickingDataRequestThread(
std::ref(connPool),
std::chrono::milliseconds(request_cycle_ms),
static_cast<uint32_t>(future_offset)
Expand All @@ -219,11 +215,11 @@ int runBob(int argc, char *argv[])
);
auto verify_thread = std::thread([&](){
set_this_thread_name("verify");
IOVerifyThread();
tickingVerifyThread();
});
auto log_request_trusted_nodes_thread = std::thread([&](){
set_this_thread_name("trusted-log-req");
EventRequestFromTrustedNode(std::ref(connPool),
eventRequestFromTrustedNode(std::ref(connPool),
std::chrono::milliseconds(request_logging_cycle_ms));
});
auto indexer_thread = std::thread([&](){
Expand Down Expand Up @@ -263,13 +259,13 @@ int runBob(int argc, char *argv[])
{
v_data_thread.emplace_back([&](){
set_this_thread_name("data");
DataProcessorThread();
dataProcessorThread();
});
v_data_thread.emplace_back([&, i](){
char nm[16];
std::snprintf(nm, sizeof(nm), "reqp-%d", i);
set_this_thread_name(nm);
RequestProcessorThread();
requestProcessorThread();
});
}
std::thread log_event_verifier_thread;
Expand Down Expand Up @@ -403,7 +399,7 @@ int runBob(int argc, char *argv[])

if (run_server)
{
StopQubicServer();
stopQubicServer();
Logger::get()->info("Closed Qubic server at port 21842");
}

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions Config.cpp → src/config.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "Config.h"
#include "config.h"
#include "json/reader.h"
#include <json/json.h>
#include <fstream>
#include <json/json.h>
#include <memory>
#include <sstream>
#include <string>
#include <memory>
#include <thread>

bool LoadConfig(const std::string& path, AppConfig& out, std::string& error) {
Expand Down
4 changes: 2 additions & 2 deletions Config.h → src/config.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "core/m256i.h"
#include <map>
#include <string>
#include <vector>
#include <map>
#include "m256i.h"

// Add tick storage mode enum
enum class TickStorageMode {
Expand Down
21 changes: 11 additions & 10 deletions connection/connection.cpp → src/connection/connection.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#include "structs.h"
#include <memory>
#include <stdexcept>
#include <algorithm> // For std::min
#include <thread>

#include <sys/socket.h>
#include <netinet/in.h>
#include "connection.h"
#include <arpa/inet.h>
#include <unistd.h>
#include <cerrno> // for errno
#include <cstring>
#include <cerrno> // for errno
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include "database/db.h"
#include "connection.h"
#include "Logger.h"
#include "GlobalVar.h"
#include "shim.h"
#include <sys/socket.h>
#include <unistd.h>

#include "src/database/db.h"
#include "src/global_var.h"
#include "src/shim.h"

#include <src/logger/logger.h>
static int do_connect(const char* nodeIp, int nodePort)
{
int serverSocket = socket(AF_INET, SOCK_STREAM, 0);
Expand Down
Loading