mirror of
https://github.com/logos-blockchain/logos-blockchain-module.git
synced 2026-07-13 10:39:32 +00:00
fix: Update join blend (#53)
* Update and simplify join blend method * Update and simplify join blend method * Update refs from latest ffi * Fix commit version
This commit is contained in:
parent
88d57c92b5
commit
1b0b5a45b4
8
flake.lock
generated
8
flake.lock
generated
@ -24,16 +24,16 @@
|
||||
"rust-rapidsnark": "rust-rapidsnark"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1782726809,
|
||||
"narHash": "sha256-wxuR8KgbFOAveS6qH4zyZ0ZR2Q3PMoZTUOTc/V5TYLE=",
|
||||
"lastModified": 1783712095,
|
||||
"narHash": "sha256-N5uloPS1FGvG/ClJmga8/K8w+2hxQBJIRP68ide4H58=",
|
||||
"owner": "logos-blockchain",
|
||||
"repo": "logos-blockchain",
|
||||
"rev": "c63efe648e1c43e75f6713e3f1fd63ed3e02a902",
|
||||
"rev": "ec648fa7239576dccb9aa8b684d4a780c9064797",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "logos-blockchain",
|
||||
"ref": "0.2.0",
|
||||
"ref": "ec648fa7239576dccb9aa8b684d4a780c9064797",
|
||||
"repo": "logos-blockchain",
|
||||
"type": "github"
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
inputs = {
|
||||
logos-module-builder.url = "github:logos-co/logos-module-builder?ref=38ddf92c1f240f4e420d300a1fbabb1609d5db01";
|
||||
logos-blockchain.url = "github:logos-blockchain/logos-blockchain?ref=0.2.0";
|
||||
logos-blockchain.url = "github:logos-blockchain/logos-blockchain?ref=ec648fa7239576dccb9aa8b684d4a780c9064797";
|
||||
};
|
||||
|
||||
outputs = inputs@{ logos-module-builder, ... }:
|
||||
|
||||
@ -144,7 +144,7 @@ namespace {
|
||||
std::string state_path_data;
|
||||
std::string storage_path_data;
|
||||
std::string logs_path_data;
|
||||
bool ibd_val;
|
||||
bool skip_ibd_val;
|
||||
std::string log_filter_data;
|
||||
std::string kms_file_data;
|
||||
|
||||
@ -235,12 +235,12 @@ namespace {
|
||||
ffi_args.logs_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;
|
||||
// skip_ibd (bool -> const bool*)
|
||||
if (args.contains("skip_ibd") && args["skip_ibd"].is_boolean()) {
|
||||
skip_ibd_val = args["skip_ibd"].get<bool>();
|
||||
ffi_args.skip_ibd = &skip_ibd_val;
|
||||
} else {
|
||||
ffi_args.ibd = nullptr;
|
||||
ffi_args.skip_ibd = nullptr;
|
||||
}
|
||||
|
||||
// log_filter (string -> const char*)
|
||||
@ -425,7 +425,7 @@ StdLogosResult LogosBlockchainModule::stop() {
|
||||
|
||||
s_instance = nullptr;
|
||||
|
||||
OperationStatus status = stop_node(node);
|
||||
OperationStatus status = shutdown_node(node);
|
||||
if (!is_ok(&status)) {
|
||||
fprintf(stderr, "Could not stop the node: %s\n", operation_status::take_message(status).c_str());
|
||||
}
|
||||
@ -939,23 +939,15 @@ StdLogosResult LogosBlockchainModule::wallet_get_claimable_vouchers() const {
|
||||
// Blend
|
||||
|
||||
StdLogosResult LogosBlockchainModule::blend_join_as_core_node(
|
||||
const std::string& provider_id_hex,
|
||||
const std::string& zk_id_hex,
|
||||
const std::string& locked_note_id_hex,
|
||||
const std::vector<std::string>& locators
|
||||
const std::string& locator,
|
||||
const std::string& locked_note_id_hex
|
||||
) const {
|
||||
if (!node) {
|
||||
return result::err("The node is not running.");
|
||||
}
|
||||
|
||||
const std::vector<uint8_t> provider_id_bytes = parse_address_hex(provider_id_hex);
|
||||
if (provider_id_bytes.empty() || static_cast<int>(provider_id_bytes.size()) != ADDRESS_BYTES) {
|
||||
return result::err("Invalid provider_id_hex (64 hex characters required).");
|
||||
}
|
||||
|
||||
const std::vector<uint8_t> zk_id_bytes = parse_address_hex(zk_id_hex);
|
||||
if (zk_id_bytes.empty() || static_cast<int>(zk_id_bytes.size()) != ADDRESS_BYTES) {
|
||||
return result::err("Invalid zk_id_hex (64 hex characters required).");
|
||||
if (locator.empty()) {
|
||||
return result::err("Invalid locator (must not be empty).");
|
||||
}
|
||||
|
||||
const std::vector<uint8_t> locked_note_id_bytes = parse_address_hex(locked_note_id_hex);
|
||||
@ -963,20 +955,10 @@ StdLogosResult LogosBlockchainModule::blend_join_as_core_node(
|
||||
return result::err("Invalid locked_note_id_hex (64 hex characters required).");
|
||||
}
|
||||
|
||||
// locators_ptrs holds raw pointers into the std::strings (valid as long as `locators` lives).
|
||||
std::vector<const char*> locators_ptrs;
|
||||
locators_ptrs.reserve(locators.size());
|
||||
for (const std::string& locator : locators) {
|
||||
locators_ptrs.push_back(locator.c_str());
|
||||
}
|
||||
|
||||
auto [value, error] = ::blend_join_as_core_node(
|
||||
node,
|
||||
provider_id_bytes.data(),
|
||||
zk_id_bytes.data(),
|
||||
locked_note_id_bytes.data(),
|
||||
locators_ptrs.data(),
|
||||
locators_ptrs.size()
|
||||
locator.c_str(),
|
||||
locked_note_id_bytes.data()
|
||||
);
|
||||
if (!is_ok(&error)) {
|
||||
return result::err(operation_status::take_message(error));
|
||||
|
||||
@ -130,10 +130,8 @@ public:
|
||||
|
||||
// Blend
|
||||
[[nodiscard]] StdLogosResult blend_join_as_core_node(
|
||||
const std::string& provider_id_hex,
|
||||
const std::string& zk_id_hex,
|
||||
const std::string& locked_note_id_hex,
|
||||
const std::vector<std::string>& locators
|
||||
const std::string& locator,
|
||||
const std::string& locked_note_id_hex
|
||||
) const;
|
||||
|
||||
// Explorer
|
||||
|
||||
@ -58,8 +58,8 @@ NodeResult start_lb_node(const char* config_path, const char* deployment) {
|
||||
return result;
|
||||
}
|
||||
|
||||
OperationStatus stop_node(LogosBlockchainNode* node) {
|
||||
LOGOS_CMOCK_RECORD("stop_node");
|
||||
OperationStatus shutdown_node(LogosBlockchainNode* node) {
|
||||
LOGOS_CMOCK_RECORD("shutdown_node");
|
||||
return make_status(0);
|
||||
}
|
||||
|
||||
@ -272,11 +272,8 @@ FfiChannelDepositResult channel_deposit_with_notes(
|
||||
|
||||
BlendHashResult blend_join_as_core_node(
|
||||
LogosBlockchainNode* node,
|
||||
const uint8_t* provider_id,
|
||||
const uint8_t* zk_id,
|
||||
const uint8_t* locked_note_id,
|
||||
const char** locators,
|
||||
size_t locators_count)
|
||||
const char* locator,
|
||||
const uint8_t* locked_note_id)
|
||||
{
|
||||
LOGOS_CMOCK_RECORD("blend_join_as_core_node");
|
||||
BlendHashResult result;
|
||||
|
||||
@ -62,7 +62,7 @@ typedef struct {
|
||||
const char* state_path;
|
||||
const char* storage_path;
|
||||
const char* logs_path;
|
||||
const bool* ibd;
|
||||
const bool* skip_ibd;
|
||||
const char* log_filter;
|
||||
const char* kms_file;
|
||||
} GenerateConfigArgs;
|
||||
@ -162,7 +162,7 @@ bool is_ok(const OperationStatus* status);
|
||||
// Lifecycle
|
||||
OperationStatus generate_user_config(GenerateConfigArgs args);
|
||||
NodeResult start_lb_node(const char* config_path, const char* deployment);
|
||||
OperationStatus stop_node(LogosBlockchainNode* node);
|
||||
OperationStatus shutdown_node(LogosBlockchainNode* node);
|
||||
OperationStatus subscribe_to_new_blocks(LogosBlockchainNode* node, BlockCallback callback);
|
||||
|
||||
// Config management
|
||||
@ -221,11 +221,8 @@ OperationStatus free_claimable_vouchers(ClaimableVouchers vouchers);
|
||||
// Blend
|
||||
BlendHashResult blend_join_as_core_node(
|
||||
LogosBlockchainNode* node,
|
||||
const uint8_t* provider_id,
|
||||
const uint8_t* zk_id,
|
||||
const uint8_t* locked_note_id,
|
||||
const char** locators,
|
||||
size_t locators_count);
|
||||
const char* locator,
|
||||
const uint8_t* locked_note_id);
|
||||
|
||||
// Explorer
|
||||
StringResult get_block(LogosBlockchainNode* node, const HeaderId* header_id);
|
||||
|
||||
@ -292,7 +292,7 @@ LOGOS_TEST(wallet_get_known_addresses_without_node_returns_error) {
|
||||
LOGOS_TEST(blend_join_as_core_node_without_node_returns_error) {
|
||||
auto t = LogosTestContext("blockchain_module");
|
||||
LogosBlockchainModule module;
|
||||
StdLogosResult result = module.blend_join_as_core_node(VALID_HEX, VALID_HEX, VALID_HEX, {"locator1"});
|
||||
StdLogosResult result = module.blend_join_as_core_node("locator1", VALID_HEX);
|
||||
LOGOS_ASSERT_FALSE(result.success);
|
||||
LOGOS_ASSERT_TRUE(contains(result.error, "not running"));
|
||||
}
|
||||
@ -354,7 +354,7 @@ LOGOS_TEST(stop_succeeds_with_running_node) {
|
||||
LOGOS_ASSERT_TRUE(module != nullptr);
|
||||
|
||||
LOGOS_ASSERT_TRUE(module->stop().success);
|
||||
LOGOS_ASSERT(t.cFunctionCalled("stop_node"));
|
||||
LOGOS_ASSERT(t.cFunctionCalled("shutdown_node"));
|
||||
delete module;
|
||||
}
|
||||
|
||||
@ -475,27 +475,15 @@ LOGOS_TEST(wallet_transfer_funds_rejects_invalid_optional_tip) {
|
||||
|
||||
// blend_join_as_core_node validation
|
||||
|
||||
LOGOS_TEST(blend_join_rejects_invalid_provider_id) {
|
||||
LOGOS_TEST(blend_join_rejects_empty_locator) {
|
||||
auto t = LogosTestContext("blockchain_module");
|
||||
TempDir tmpDir;
|
||||
auto* module = createStartedModule(t, tmpDir);
|
||||
LOGOS_ASSERT_TRUE(module != nullptr);
|
||||
|
||||
StdLogosResult result = module->blend_join_as_core_node("short", VALID_HEX, VALID_HEX, {});
|
||||
StdLogosResult result = module->blend_join_as_core_node("", VALID_HEX);
|
||||
LOGOS_ASSERT_FALSE(result.success);
|
||||
LOGOS_ASSERT_TRUE(contains(result.error, "provider_id"));
|
||||
delete module;
|
||||
}
|
||||
|
||||
LOGOS_TEST(blend_join_rejects_invalid_zk_id) {
|
||||
auto t = LogosTestContext("blockchain_module");
|
||||
TempDir tmpDir;
|
||||
auto* module = createStartedModule(t, tmpDir);
|
||||
LOGOS_ASSERT_TRUE(module != nullptr);
|
||||
|
||||
StdLogosResult result = module->blend_join_as_core_node(VALID_HEX, "short", VALID_HEX, {});
|
||||
LOGOS_ASSERT_FALSE(result.success);
|
||||
LOGOS_ASSERT_TRUE(contains(result.error, "zk_id"));
|
||||
LOGOS_ASSERT_TRUE(contains(result.error, "locator"));
|
||||
delete module;
|
||||
}
|
||||
|
||||
@ -505,7 +493,7 @@ LOGOS_TEST(blend_join_rejects_invalid_locked_note_id) {
|
||||
auto* module = createStartedModule(t, tmpDir);
|
||||
LOGOS_ASSERT_TRUE(module != nullptr);
|
||||
|
||||
StdLogosResult result = module->blend_join_as_core_node(VALID_HEX, VALID_HEX, "short", {});
|
||||
StdLogosResult result = module->blend_join_as_core_node("locator1", "short");
|
||||
LOGOS_ASSERT_FALSE(result.success);
|
||||
LOGOS_ASSERT_TRUE(contains(result.error, "locked_note_id"));
|
||||
delete module;
|
||||
@ -1035,8 +1023,7 @@ LOGOS_TEST(blend_join_as_core_node_returns_declaration_id) {
|
||||
|
||||
t.mockCFunction("blend_join_as_core_node_error").returns(0);
|
||||
|
||||
std::vector<std::string> locators = {"locator1", "locator2"};
|
||||
StdLogosResult result = module->blend_join_as_core_node(VALID_HEX, VALID_HEX, VALID_HEX, locators);
|
||||
StdLogosResult result = module->blend_join_as_core_node("locator1", VALID_HEX);
|
||||
LOGOS_ASSERT_TRUE(result.success);
|
||||
// Mock fills hash with 0xCD -> hex "cdcd...cd" (64 chars)
|
||||
std::string declarationId = result.value.get<std::string>();
|
||||
@ -1054,7 +1041,7 @@ LOGOS_TEST(blend_join_as_core_node_returns_error_on_ffi_failure) {
|
||||
|
||||
t.mockCFunction("blend_join_as_core_node_error").returns(1);
|
||||
|
||||
StdLogosResult result = module->blend_join_as_core_node(VALID_HEX, VALID_HEX, VALID_HEX, {});
|
||||
StdLogosResult result = module->blend_join_as_core_node("locator1", VALID_HEX);
|
||||
LOGOS_ASSERT_FALSE(result.success);
|
||||
delete module;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user