Merge remote-tracking branch 'origin/master' into deposit

# Conflicts:
#	flake.lock
#	flake.nix
This commit is contained in:
Daniel 2026-06-17 17:48:24 +02:00
commit 01940f9adb
4 changed files with 98 additions and 116 deletions

View File

@ -103,10 +103,10 @@ namespace {
uint16_t blend_port_val;
std::string http_addr_data;
std::string external_address_data;
bool no_public_ip_check_val;
std::string custom_deployment_config_path_data;
Deployment deployment_val{};
std::string state_path_data;
bool ibd_val;
std::string log_filter_data;
std::string kms_file_data;
// The FFI struct with pointers into owned data
GenerateConfigArgs ffi_args{};
@ -171,39 +171,6 @@ namespace {
ffi_args.external_address = nullptr;
}
// no_public_ip_check (bool -> const bool*)
if (args.contains("no_public_ip_check") && args["no_public_ip_check"].is_boolean()) {
no_public_ip_check_val = args["no_public_ip_check"].get<bool>();
ffi_args.no_public_ip_check = &no_public_ip_check_val;
} else {
ffi_args.no_public_ip_check = nullptr;
}
// deployment (const struct Deployment*)
// Expected format: { "deployment": { "well_known_deployment": "devnet" } }
// OR: { "deployment": { "config_path": "/path/to/config" } }
if (args.contains("deployment") && args["deployment"].is_object()) {
const auto& deployment = args["deployment"];
if (deployment.contains("well_known_deployment") && deployment["well_known_deployment"].is_string()) {
deployment_val.deployment_type = DeploymentType::WellKnown;
const std::string wellknown = deployment["well_known_deployment"].get<std::string>();
if (wellknown == "devnet") {
deployment_val.well_known_deployment = WellKnownDeployment::Devnet;
}
deployment_val.custom_deployment_config_path = nullptr;
} else if (deployment.contains("config_path") && deployment["config_path"].is_string()) {
deployment_val.deployment_type = DeploymentType::Custom;
deployment_val.well_known_deployment = static_cast<WellKnownDeployment>(0);
custom_deployment_config_path_data = deployment["config_path"].get<std::string>();
deployment_val.custom_deployment_config_path = custom_deployment_config_path_data.c_str();
}
ffi_args.deployment = &deployment_val;
} else {
ffi_args.deployment = nullptr;
}
// state_path (string -> const char*)
if (args.contains("state_path") && args["state_path"].is_string()) {
state_path_data = args["state_path"].get<std::string>();
@ -211,6 +178,30 @@ namespace {
} else {
ffi_args.state_path = nullptr;
}
// ibd (bool -> const bool*)
if (args.contains("ibd") && args["ibd"].is_boolean()) {
ibd_val = args["ibd"].get<bool>();
ffi_args.ibd = &ibd_val;
} else {
ffi_args.ibd = nullptr;
}
// log_filter (string -> const char*)
if (args.contains("log_filter") && args["log_filter"].is_string()) {
log_filter_data = args["log_filter"].get<std::string>();
ffi_args.log_filter = log_filter_data.c_str();
} else {
ffi_args.log_filter = nullptr;
}
// kms_file (string -> const char*)
if (args.contains("kms_file") && args["kms_file"].is_string()) {
kms_file_data = args["kms_file"].get<std::string>();
ffi_args.kms_file = kms_file_data.c_str();
} else {
ffi_args.kms_file = nullptr;
}
}
};
} // namespace
@ -268,13 +259,13 @@ LogosBlockchainModule::~LogosBlockchainModule() {
// Lifecycle
int LogosBlockchainModule::generate_user_config(const std::string& json_args) {
std::string LogosBlockchainModule::generate_user_config(const std::string& json_args) {
json parsed_args;
try {
parsed_args = json::parse(json_args);
} catch (const json::parse_error& e) {
fprintf(stderr, "Failed to parse JSON args: %s\n", e.what());
return 1;
return "1";
}
const OwnedGenerateConfigArgs owned_args(parsed_args);
@ -282,16 +273,16 @@ int LogosBlockchainModule::generate_user_config(const std::string& json_args) {
const OperationStatus status = ::generate_user_config(owned_args.ffi_args);
if (!is_ok(&status)) {
fprintf(stderr, "Failed to generate user config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::start(const std::string& config_path, const std::string& deployment) {
std::string LogosBlockchainModule::start(const std::string& config_path, const std::string& deployment) {
if (node) {
fprintf(stderr, "Could not execute the operation: The node is already running.\n");
return 1;
return "1";
}
const char* module_path_env = std::getenv("LOGOS_MODULE_PATH");
@ -310,7 +301,7 @@ int LogosBlockchainModule::start(const std::string& config_path, const std::stri
fprintf(stderr, "Using config from LB_CONFIG_PATH: %s\n", effective_config_path.c_str());
} else {
fprintf(stderr, "Config path was not specified and LB_CONFIG_PATH is not set.\n");
return 3;
return "3";
}
}
@ -324,7 +315,7 @@ int LogosBlockchainModule::start(const std::string& config_path, const std::stri
fprintf(stderr, "Start node returned with value and error.\n");
if (!is_ok(&error)) {
fprintf(stderr, "Failed to start the node. Error: %d\n", error);
return 4;
return "4";
}
node = value;
@ -332,23 +323,23 @@ int LogosBlockchainModule::start(const std::string& config_path, const std::stri
if (!node) {
fprintf(stderr, "Could not subscribe to block events: The node is not running.\n");
return 4;
return "4";
}
s_instance = this;
const OperationStatus subscribe_status = subscribe_to_new_blocks(node, on_new_block_callback);
if (!is_ok(&subscribe_status)) {
fprintf(stderr, "Failed to subscribe to new blocks. Error: %d\n", subscribe_status);
return 5;
return "5";
}
return 0;
return "0";
}
int LogosBlockchainModule::stop() {
std::string LogosBlockchainModule::stop() {
if (!node) {
fprintf(stderr, "Could not execute the operation: The node is not running.\n");
return 1;
return "1";
}
s_instance = nullptr;
@ -361,36 +352,36 @@ int LogosBlockchainModule::stop() {
}
node = nullptr;
return 0;
return "0";
}
// Config management
int LogosBlockchainModule::update_user_config(const std::string& user_config_path, const std::string& keystore_path) {
std::string LogosBlockchainModule::update_user_config(const std::string& user_config_path, const std::string& keystore_path) {
const std::string config = localPathFromFileUrl(user_config_path);
const std::string keystore = localPathFromFileUrl(keystore_path);
const OperationStatus status = ::update_user_config(config.c_str(), keystore.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to update user config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::migrate_user_config(const std::string& output_path, const std::string& keystore_path) {
std::string LogosBlockchainModule::migrate_user_config(const std::string& output_path, const std::string& keystore_path) {
const std::string output = localPathFromFileUrl(output_path);
const std::string keystore = localPathFromFileUrl(keystore_path);
const OperationStatus status = ::migrate_user_config(output.c_str(), keystore.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to migrate user config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::migrate_user_config_0_1_2(
std::string LogosBlockchainModule::migrate_user_config_0_1_2(
const std::string& new_config_path,
const std::string& old_config_path,
const std::string& keystore_path
@ -403,12 +394,12 @@ int LogosBlockchainModule::migrate_user_config_0_1_2(
::migrate_user_config_0_1_2(new_config.c_str(), old_config.c_str(), keystore.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to migrate 0.1.2 config. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::participate(
std::string LogosBlockchainModule::participate(
const std::string& config_path,
const std::string& keystore_path,
const std::string& output_dir,
@ -423,9 +414,9 @@ int LogosBlockchainModule::participate(
::participate(config.c_str(), keystore.c_str(), output.c_str(), external_address_ptr);
if (!is_ok(&status)) {
fprintf(stderr, "Failed to generate participation data. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
// Keystore
@ -459,7 +450,7 @@ std::string LogosBlockchainModule::generate_key(
return result;
}
int LogosBlockchainModule::add_key(
std::string LogosBlockchainModule::add_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_type,
@ -469,7 +460,7 @@ int LogosBlockchainModule::add_key(
KeyType type{};
if (!parse_key_type(key_type, type)) {
fprintf(stderr, "Invalid key_type (expected \"ed25519\" or \"zk\").\n");
return 1;
return "1";
}
const std::string config = localPathFromFileUrl(user_config_path);
@ -480,12 +471,12 @@ int LogosBlockchainModule::add_key(
::add_key(config.c_str(), keystore.c_str(), type, key_hex.c_str(), key_title_ptr);
if (!is_ok(&status)) {
fprintf(stderr, "Failed to add key. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
int LogosBlockchainModule::remove_key(
std::string LogosBlockchainModule::remove_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_title
@ -496,9 +487,9 @@ int LogosBlockchainModule::remove_key(
const OperationStatus status = ::remove_key(config.c_str(), keystore.c_str(), key_title.c_str());
if (!is_ok(&status)) {
fprintf(stderr, "Failed to remove key. Error: %d\n", status);
return 1;
return "1";
}
return 0;
return "0";
}
// Identity

View File

@ -22,19 +22,19 @@ public:
// ---- Node ----
// Lifecycle
int generate_user_config(const std::string& json_args);
int start(const std::string& config_path, const std::string& deployment);
int stop();
std::string generate_user_config(const std::string& json_args);
std::string start(const std::string& config_path, const std::string& deployment);
std::string stop();
// Config management
int update_user_config(const std::string& user_config_path, const std::string& keystore_path);
int migrate_user_config(const std::string& output_path, const std::string& keystore_path);
int migrate_user_config_0_1_2(
std::string update_user_config(const std::string& user_config_path, const std::string& keystore_path);
std::string migrate_user_config(const std::string& output_path, const std::string& keystore_path);
std::string migrate_user_config_0_1_2(
const std::string& new_config_path,
const std::string& old_config_path,
const std::string& keystore_path
);
int participate(
std::string participate(
const std::string& config_path,
const std::string& keystore_path,
const std::string& output_dir,
@ -49,14 +49,14 @@ public:
const std::string& key_type,
const std::string& key_title
);
int add_key(
std::string add_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_type,
const std::string& key_hex,
const std::string& key_title
);
int remove_key(
std::string remove_key(
const std::string& user_config_path,
const std::string& keystore_path,
const std::string& key_title

View File

@ -24,23 +24,12 @@ typedef struct LogosBlockchainNode LogosBlockchainNode;
// Operation status (0 = OK)
typedef int OperationStatus;
// Deployment enums
typedef enum { WellKnown, Custom } DeploymentType;
typedef enum { Devnet } WellKnownDeployment;
// Consensus state enum
typedef enum { Bootstrapping, Online } State;
// Key type for generate_key / add_key
typedef enum { Ed25519, Zk } KeyType;
// Deployment configuration
typedef struct {
DeploymentType deployment_type;
WellKnownDeployment well_known_deployment;
const char* custom_deployment_config_path;
} Deployment;
// Arguments for generate_user_config
typedef struct {
const char** initial_peers;
@ -50,9 +39,10 @@ typedef struct {
const uint16_t* blend_port;
const char* http_addr;
const char* external_address;
const bool* no_public_ip_check;
const Deployment* deployment;
const char* state_path;
const bool* ibd;
const char* log_filter;
const char* kms_file;
} GenerateConfigArgs;
// Arguments for transfer_funds

View File

@ -59,8 +59,8 @@ static LogosBlockchainModule* createStartedModule(LogosTestContext& t, TempDir&
t.mockCFunction("start_lb_node").returns(1);
t.mockCFunction("subscribe_to_new_blocks").returns(0);
int rc = module->start(tmpDir.filePath("config.json"), "");
if (rc != 0) {
std::string rc = module->start(tmpDir.filePath("config.json"), "");
if (rc != "0") {
delete module;
return nullptr;
}
@ -77,7 +77,7 @@ LOGOS_TEST(generate_user_config_returns_0_on_success) {
t.mockCFunction("generate_user_config").returns(0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/test-config.json"})"), 0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/test-config.json"})"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("generate_user_config"));
}
@ -87,7 +87,7 @@ LOGOS_TEST(generate_user_config_returns_1_on_failure) {
t.mockCFunction("generate_user_config").returns(1);
LOGOS_ASSERT_EQ(module.generate_user_config("{}"), 1);
LOGOS_ASSERT_EQ(module.generate_user_config("{}"), std::string("1"));
}
LOGOS_TEST(generate_user_config_from_json_string) {
@ -96,7 +96,7 @@ LOGOS_TEST(generate_user_config_from_json_string) {
t.mockCFunction("generate_user_config").returns(0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/out.json"})"), 0);
LOGOS_ASSERT_EQ(module.generate_user_config(R"({"output":"/tmp/out.json"})"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("generate_user_config"));
}
@ -113,12 +113,13 @@ LOGOS_TEST(generate_user_config_with_all_fields) {
"blend_port": 9001,
"http_addr": "0.0.0.0:8080",
"external_address": "1.2.3.4",
"no_public_ip_check": true,
"deployment": { "well_known_deployment": "devnet" },
"state_path": "/tmp/state"
"state_path": "/tmp/state",
"ibd": true,
"log_filter": "warn,logos_blockchain=debug",
"kms_file": "/tmp/kms.yaml"
})";
LOGOS_ASSERT_EQ(module.generate_user_config(args), 0);
LOGOS_ASSERT_EQ(module.generate_user_config(args), std::string("0"));
}
// ============================================================================
@ -128,7 +129,7 @@ LOGOS_TEST(generate_user_config_with_all_fields) {
LOGOS_TEST(stop_without_node_returns_1) {
auto t = LogosTestContext("blockchain_module");
LogosBlockchainModule module;
LOGOS_ASSERT_EQ(module.stop(), 1);
LOGOS_ASSERT_EQ(module.stop(), std::string("1"));
}
LOGOS_TEST(wallet_get_balance_without_node_returns_error) {
@ -240,7 +241,7 @@ LOGOS_TEST(start_returns_1_when_already_running) {
auto* module = createStartedModule(t, tmpDir);
LOGOS_ASSERT_TRUE(module != nullptr);
LOGOS_ASSERT_EQ(module->start("/tmp/config.json", ""), 1);
LOGOS_ASSERT_EQ(module->start("/tmp/config.json", ""), std::string("1"));
delete module;
}
@ -250,7 +251,7 @@ LOGOS_TEST(stop_succeeds_with_running_node) {
auto* module = createStartedModule(t, tmpDir);
LOGOS_ASSERT_TRUE(module != nullptr);
LOGOS_ASSERT_EQ(module->stop(), 0);
LOGOS_ASSERT_EQ(module->stop(), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("stop_node"));
delete module;
}
@ -1062,7 +1063,7 @@ LOGOS_TEST(update_user_config_returns_0_on_success) {
t.mockCFunction("update_user_config").returns(0);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), 0);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("update_user_config"));
}
@ -1072,7 +1073,7 @@ LOGOS_TEST(update_user_config_returns_1_on_failure) {
t.mockCFunction("update_user_config").returns(1);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), 1);
LOGOS_ASSERT_EQ(module.update_user_config("/tmp/config.yaml", "/tmp/keystore.yaml"), std::string("1"));
}
LOGOS_TEST(migrate_user_config_returns_0_on_success) {
@ -1081,7 +1082,7 @@ LOGOS_TEST(migrate_user_config_returns_0_on_success) {
t.mockCFunction("migrate_user_config").returns(0);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), 0);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("migrate_user_config"));
}
@ -1091,7 +1092,7 @@ LOGOS_TEST(migrate_user_config_returns_1_on_failure) {
t.mockCFunction("migrate_user_config").returns(1);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), 1);
LOGOS_ASSERT_EQ(module.migrate_user_config("/tmp/out.yaml", "/tmp/keystore.yaml"), std::string("1"));
}
LOGOS_TEST(migrate_user_config_0_1_2_returns_0_on_success) {
@ -1100,7 +1101,7 @@ LOGOS_TEST(migrate_user_config_0_1_2_returns_0_on_success) {
t.mockCFunction("migrate_user_config_0_1_2").returns(0);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), 0);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("migrate_user_config_0_1_2"));
}
@ -1110,7 +1111,7 @@ LOGOS_TEST(migrate_user_config_0_1_2_returns_1_on_failure) {
t.mockCFunction("migrate_user_config_0_1_2").returns(1);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), 1);
LOGOS_ASSERT_EQ(module.migrate_user_config_0_1_2("/tmp/new.yaml", "/tmp/old.yaml", "/tmp/keystore.yaml"), std::string("1"));
}
LOGOS_TEST(participate_returns_0_on_success) {
@ -1119,7 +1120,7 @@ LOGOS_TEST(participate_returns_0_on_success) {
t.mockCFunction("participate").returns(0);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", ""), 0);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", ""), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("participate"));
}
@ -1129,7 +1130,7 @@ LOGOS_TEST(participate_returns_1_on_failure) {
t.mockCFunction("participate").returns(1);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", "1.2.3.4"), 1);
LOGOS_ASSERT_EQ(module.participate("/tmp/config.yaml", "/tmp/keystore.yaml", "/tmp/out", "1.2.3.4"), std::string("1"));
}
// ============================================================================
@ -1186,7 +1187,7 @@ LOGOS_TEST(add_key_returns_0_on_success) {
t.mockCFunction("add_key").returns(0);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "ed25519", VALID_HEX, ""), 0);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "ed25519", VALID_HEX, ""), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("add_key"));
}
@ -1194,7 +1195,7 @@ LOGOS_TEST(add_key_rejects_invalid_key_type) {
auto t = LogosTestContext("blockchain_module");
LogosBlockchainModule module;
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "bogus", VALID_HEX, ""), 1);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "bogus", VALID_HEX, ""), std::string("1"));
LOGOS_ASSERT_FALSE(t.cFunctionCalled("add_key"));
}
@ -1204,7 +1205,7 @@ LOGOS_TEST(add_key_returns_1_on_failure) {
t.mockCFunction("add_key").returns(1);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "zk", VALID_HEX, "title"), 1);
LOGOS_ASSERT_EQ(module.add_key("/tmp/config.yaml", "/tmp/keystore.yaml", "zk", VALID_HEX, "title"), std::string("1"));
}
LOGOS_TEST(remove_key_returns_0_on_success) {
@ -1213,7 +1214,7 @@ LOGOS_TEST(remove_key_returns_0_on_success) {
t.mockCFunction("remove_key").returns(0);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), 0);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), std::string("0"));
LOGOS_ASSERT(t.cFunctionCalled("remove_key"));
}
@ -1223,7 +1224,7 @@ LOGOS_TEST(remove_key_returns_1_on_failure) {
t.mockCFunction("remove_key").returns(1);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), 1);
LOGOS_ASSERT_EQ(module.remove_key("/tmp/config.yaml", "/tmp/keystore.yaml", "my-key"), std::string("1"));
}
// ============================================================================