Skip to content
Merged
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
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ if(LANTERN_BUILD_TESTS)
add_test(NAME lantern_signature COMMAND lantern_signature_test)
set_tests_properties(lantern_signature PROPERTIES TIMEOUT 3600)

add_executable(lantern_fixture_loader_test tests/unit/test_fixture_loader.c)
target_link_libraries(lantern_fixture_loader_test PRIVATE ${LANTERN_TEST_LINK_LIB})
target_include_directories(
lantern_fixture_loader_test
PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/external/jsmn
)
add_test(NAME lantern_fixture_loader COMMAND lantern_fixture_loader_test)

add_executable(lantern_consensus_runtime_test tests/unit/test_consensus_runtime.c)
target_link_libraries(lantern_consensus_runtime_test PRIVATE ${LANTERN_TEST_LINK_LIB})
add_test(NAME lantern_consensus_runtime COMMAND lantern_consensus_runtime_test)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ RUN --mount=type=cache,target=/root/.ccache,sharing=locked,id=ccache-${TARGETPLA
--mount=type=cache,target=/usr/src/lantern/build,sharing=locked,id=lantern-build-${TARGETPLATFORM} \
echo "LANTERN_FORCE_REBUILD=${LANTERN_FORCE_REBUILD}" \
&& cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DLANTERN_GIT_COMMIT="${GIT_COMMIT}" -DLANTERN_GIT_BRANCH="${GIT_BRANCH}" \
&& cmake --build build --target lantern_cli --parallel "$(nproc)" \
&& cmake --build build --target lantern_cli --parallel "$(nproc)" --clean-first \
&& (cmake --build build --target lantern_client_test --parallel "$(nproc)" || true) \
&& mkdir -p /opt/lantern/bin \
&& cp build/lantern_cli /opt/lantern/bin/lantern \
Expand Down
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function(_lantern_define_c_leanvm_xmss_variant target_name source_dir cargo_targ
set_target_properties(${target_name}
PROPERTIES
IMPORTED_LOCATION "${c_leanvm_xmss_output}"
INTERFACE_INCLUDE_DIRECTORIES "${header_dir}"
INTERFACE_INCLUDE_DIRECTORIES "${header_dir};${source_dir}/include"
)
if(C_XMSS_TEST_CONFIG)
set_target_properties(${target_name}
Expand Down
2 changes: 1 addition & 1 deletion src/core/client_reqresp.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ static void lantern_client_peer_status_update(
true,
network_finalized_slot,
true,
false);
true);
}


Expand Down
3 changes: 3 additions & 0 deletions tests/support/fixture_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ int lantern_fixture_parse_signature_proof(
if (proof_data_idx < 0) {
proof_data_idx = lantern_fixture_object_get_field(doc, proof_idx, "proof_data");
}
if (proof_data_idx < 0) {
proof_data_idx = lantern_fixture_object_get_field(doc, proof_idx, "proof");
}
if (proof_data_idx < 0) {
return -1;
}
Expand Down
55 changes: 54 additions & 1 deletion tests/unit/test_client_pending.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,12 +987,14 @@ static int test_idle_status_triggers_syncing_before_gossip_backfill(void)
status.head.root = child_root;
status.head.slot = client.state.slot;
status.finalized = client.state.latest_finalized;
status.finalized.slot = client.state.slot + 1u;
client_test_fill_root(&status.finalized.root, 0x55u);
if (reqresp_handle_status(&client, &status, peer_id) != LANTERN_CLIENT_OK) {
fprintf(stderr, "peer status update failed\n");
goto cleanup;
}
if (client.sync_state != LANTERN_SYNC_STATE_SYNCING) {
fprintf(stderr, "first peer status should move IDLE to SYNCING\n");
fprintf(stderr, "peer status finalized ahead should keep sync incomplete\n");
goto cleanup;
}

Expand All @@ -1019,6 +1021,54 @@ static int test_idle_status_triggers_syncing_before_gossip_backfill(void)
return rc;
}

static int test_idle_status_at_known_head_completes_sync(void)
{
struct lantern_client client;
struct PQSignatureSchemePublicKey *pub = NULL;
struct PQSignatureSchemeSecretKey *secret = NULL;
LanternRoot child_root;
const char *peer_id = "16Uiu2HAmPV5jU62WtmDkCEmfq1jzbBDkGbHNsDN78gJyvmv2TuC6";
int rc = 1;

if (client_test_setup_vote_validation_client(
&client,
"sync_idle_status_caught_up",
&pub,
&secret,
NULL,
&child_root)
!= 0) {
return 1;
}
if (enable_sync_test_peer(&client, peer_id) != 0) {
fprintf(stderr, "failed to enable sync test peer\n");
goto cleanup;
}

client.sync_state = LANTERN_SYNC_STATE_IDLE;

LanternStatusMessage status;
memset(&status, 0, sizeof(status));
status.head.root = child_root;
status.head.slot = client.state.slot;
status.finalized = client.state.latest_finalized;
if (reqresp_handle_status(&client, &status, peer_id) != LANTERN_CLIENT_OK) {
fprintf(stderr, "caught-up peer status update failed\n");
goto cleanup;
}
if (client.sync_state != LANTERN_SYNC_STATE_SYNCED) {
fprintf(stderr, "caught-up peer status should complete sync from IDLE\n");
goto cleanup;
}

rc = 0;

cleanup:
disable_sync_test_peer(&client);
client_test_teardown_vote_validation_client(&client, pub, secret);
return rc;
}

static int test_imported_blocks_update_sync_network_view(void)
{
struct block_signature_fixture fixture;
Expand Down Expand Up @@ -2016,6 +2066,9 @@ int main(void) {
if (test_idle_status_triggers_syncing_before_gossip_backfill() != 0) {
return 1;
}
if (test_idle_status_at_known_head_completes_sync() != 0) {
return 1;
}
if (test_reqresp_block_response_accepts_missing_parent() != 0) {
return 1;
}
Expand Down
58 changes: 58 additions & 0 deletions tests/unit/test_fixture_loader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "tests/support/fixture_loader.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CHECK(cond) \
do { \
if (!(cond)) { \
fprintf(stderr, "check failed: %s (%s:%d)\n", #cond, __FILE__, __LINE__); \
abort(); \
} \
} while (0)

static char *copy_text(const char *text) {
size_t len = strlen(text);
char *copy = (char *)malloc(len + 1u);
CHECK(copy != NULL);
memcpy(copy, text, len + 1u);
return copy;
}

static void expect_lstar_signature_proof_alias(void) {
static const char json[] =
"{"
"\"participants\":{\"data\":[false,true,true]},"
"\"proof\":{\"data\":\"0x01020304\"}"
"}";

struct lantern_fixture_document doc;
LanternAggregatedSignatureProof proof;

memset(&doc, 0, sizeof(doc));
lantern_aggregated_signature_proof_init(&proof);

CHECK(lantern_fixture_document_init(&doc, copy_text(json)) == 0);
CHECK(lantern_fixture_parse_signature_proof(&doc, 0, &proof) == 0);

CHECK(proof.participants.bit_length == 3u);
CHECK(!lantern_bitlist_get(&proof.participants, 0u));
CHECK(lantern_bitlist_get(&proof.participants, 1u));
CHECK(lantern_bitlist_get(&proof.participants, 2u));

CHECK(proof.proof_data.length == 4u);
CHECK(proof.proof_data.data != NULL);
CHECK(proof.proof_data.data[0] == 0x01u);
CHECK(proof.proof_data.data[1] == 0x02u);
CHECK(proof.proof_data.data[2] == 0x03u);
CHECK(proof.proof_data.data[3] == 0x04u);

lantern_aggregated_signature_proof_reset(&proof);
lantern_fixture_document_reset(&doc);
}

int main(void) {
expect_lstar_signature_proof_alias();
return 0;
}
Loading