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
17 changes: 0 additions & 17 deletions src/consensus/slot_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,3 @@ int lantern_slot_clock_compute(
out_timepoint->phase = interval_to_phase(interval_index);
return 0;
}

const char *lantern_duty_phase_name(enum lantern_duty_phase phase) {
switch (phase) {
case LANTERN_DUTY_PHASE_PROPOSAL:
return "proposal";
case LANTERN_DUTY_PHASE_VOTE:
return "vote";
case LANTERN_DUTY_PHASE_AGGREGATE:
return "aggregate";
case LANTERN_DUTY_PHASE_SAFE_TARGET:
return "safe-target";
case LANTERN_DUTY_PHASE_VOTE_ACCEPT:
return "vote-accept";
default:
return "unknown";
}
}
25 changes: 25 additions & 0 deletions src/consensus/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,30 @@ static void attestation_data_by_root_remove_index(
cache->length -= 1u;
}

static void attestation_data_by_root_shrink_to_fit(
struct lantern_attestation_data_by_root *cache) {
if (!cache) {
return;
}
if (cache->length == cache->capacity) {
return;
}
if (cache->length == 0u) {
free(cache->entries);
cache->entries = NULL;
cache->capacity = 0u;
return;
}

struct lantern_attestation_data_by_root_entry *entries =
realloc(cache->entries, cache->length * sizeof(*entries));
if (!entries) {
return;
}
cache->entries = entries;
cache->capacity = cache->length;
}

static int attestation_data_by_root_add(
struct lantern_attestation_data_by_root *cache,
const LanternRoot *data_root,
Expand Down Expand Up @@ -760,6 +784,7 @@ size_t lantern_store_prune_finalized_attestation_material(
}
data_index += 1u;
}
attestation_data_by_root_shrink_to_fit(data_cache);

size_t signature_index = 0u;
while (signature_index < store->gossip_signatures.length) {
Expand Down
19 changes: 0 additions & 19 deletions src/core/client_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,25 +393,6 @@ bool lantern_client_lock_pending(struct lantern_client *client);
*/
void lantern_client_unlock_pending(struct lantern_client *client, bool locked);


/* ============================================================================
* Validator Record Functions
* ============================================================================ */

/**
* Get a validator record from the genesis registry.
*
* @param client Client instance
* @param global_index Validator global index
* @return Pointer to validator record, or NULL if not found
*
* @note Thread safety: This function is thread-safe (read-only access)
*/
const struct lantern_validator_record *lantern_client_get_validator_record(
const struct lantern_client *client,
uint64_t global_index);


#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 0 additions & 18 deletions src/core/client_services_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,6 @@ extern "C" {
void validator_duty_state_reset(struct lantern_validator_duty_state *state);


/**
* Compute wall-clock time for a vote slot.
*
* @spec subspecs/slot/slot_clock.py - slot timing
*
* @param client Client instance
* @param vote_slot Slot number
* @param out_seconds Output for computed time in seconds
* @return true on success, false on failure
*
* @note Thread safety: This function is thread-safe
*/
bool lantern_client_vote_time_seconds(
const struct lantern_client *client,
uint64_t vote_slot,
uint64_t *out_seconds);


/**
* Check if the validator service should run.
*
Expand Down
36 changes: 0 additions & 36 deletions src/core/client_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,6 @@ enum
VALIDATOR_PUBKEY_HEX_BUFFER_LEN = (LANTERN_VALIDATOR_PUBKEY_SIZE * 2u) + 3u,
};


/* ============================================================================
* Validator Record Access
* ============================================================================ */

/**
* Get validator record from genesis registry.
*
* @spec subspecs/containers/validator.py - Validator container
*
* Retrieves a validator record from the genesis registry by index.
* The registry is populated during genesis initialization and remains
* immutable after that.
*
* @param client Client instance
* @param validator_id Validator index
* @return Validator record or NULL if not found
*
* @note Thread safety: Assumes registry is immutable after init
*/
const struct lantern_validator_record *lantern_client_get_validator_record(
const struct lantern_client *client,
uint64_t validator_id)
{
if (!client || !client->genesis.validator_registry.records)
{
return NULL;
}
if (validator_id >= client->genesis.validator_registry.count)
{
return NULL;
}
return &client->genesis.validator_registry.records[validator_id];
}


/* ============================================================================
* Enabled Validator Count
* ============================================================================ */
Expand Down
7 changes: 0 additions & 7 deletions src/core/client_sync_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,6 @@ bool lantern_client_find_missing_state_root_locked(
const LanternRoot *root,
LanternRoot *out_missing_root);

/**
* Return the active attestation committee count for sync/validator cache logic.
*
* Respects debug overrides used by tests and falls back to the protocol default.
*/
size_t lantern_client_attestation_committee_count(const struct lantern_client *client);

/**
* Determine whether this node should retain an attestation signature locally.
*
Expand Down
8 changes: 0 additions & 8 deletions src/core/client_sync_votes.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,6 @@ static bool validate_vote_cache_state(
return true;
}

size_t lantern_client_attestation_committee_count(const struct lantern_client *client)
{
if (client && client->debug_attestation_committee_count > 0) {
return client->debug_attestation_committee_count;
}
return DEFAULT_SYNC_ATTESTATION_COMMITTEE_COUNT;
}

bool lantern_client_should_cache_attestation_signature_locked(
const struct lantern_client *client,
const LanternVote *vote)
Expand Down
71 changes: 1 addition & 70 deletions src/core/client_validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,12 @@ static int aggregation_group_append(
{
return -1;
}
group->validator_ids = ids;
LanternSignature *sigs = realloc(group->signatures, new_capacity * sizeof(*sigs));
if (!sigs)
{
return -1;
}
group->validator_ids = ids;
group->signatures = sigs;
group->capacity = new_capacity;
}
Expand Down Expand Up @@ -1232,75 +1232,6 @@ void validator_duty_state_reset(struct lantern_validator_duty_state *state)
memset(state, 0, sizeof(*state));
}


/* ============================================================================
* Vote Time Utilities
* ============================================================================ */

/**
* Compute wall-clock time for a vote slot.
*
* Calculates the Unix timestamp (in seconds) at which the given vote slot
* begins, based on genesis time and seconds per slot configuration.
*
* @param client Client instance (must have fork_choice initialized)
* @param vote_slot Slot number to compute time for
* @param out_seconds Output for computed time in seconds (Unix timestamp)
*
* @return true on success
* @return false if client is NULL, fork_choice not initialized, out_seconds
* is NULL, or computed time overflows uint64_t
*
* @note Thread safety: This function is thread-safe
*/
bool lantern_client_vote_time_seconds(
const struct lantern_client *client,
uint64_t vote_slot,
uint64_t *out_seconds)
{
if (!client || !client->has_fork_choice || !out_seconds)
{
return false;
}
uint32_t seconds_per_slot = client->fork_choice.seconds_per_slot;
if (seconds_per_slot == 0)
{
seconds_per_slot = 1;
}
uint64_t slot_for_time = vote_slot;
if (slot_for_time != UINT64_MAX)
{
slot_for_time += 1u;
}

#if defined(__SIZEOF_INT128__)
__uint128_t slot_offset = (__uint128_t)slot_for_time * (uint64_t)seconds_per_slot;
__uint128_t result = slot_offset + (__uint128_t)client->fork_choice.config.genesis_time;
if (result > UINT64_MAX)
{
return false;
}
*out_seconds = (uint64_t)result;
#else
/* Fallback for platforms without 128-bit integers */
uint64_t genesis_time = client->fork_choice.config.genesis_time;
/* Check for overflow in multiplication */
if (seconds_per_slot != 0 && slot_for_time > UINT64_MAX / seconds_per_slot)
{
return false;
}
uint64_t slot_offset = slot_for_time * (uint64_t)seconds_per_slot;
/* Check for overflow in addition */
if (slot_offset > UINT64_MAX - genesis_time)
{
return false;
}
*out_seconds = slot_offset + genesis_time;
#endif
return true;
}


/* ============================================================================
* Validator Service Checks
* ============================================================================ */
Expand Down
9 changes: 0 additions & 9 deletions src/networking/gossipsub_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@
#include "protocol/gossipsub/gossipsub.h"
#include "../../external/c-libp2p/src/protocol/gossipsub/proto/gen/gossipsub_rpc.pb.h"

#ifdef __cplusplus
extern "C" {
#endif
libp2p_err_t libp2p_gossipsub_rpc_decode_frame(
const uint8_t *frame,
size_t frame_len,
libp2p_gossipsub_RPC **out_rpc);
#ifdef __cplusplus
}
#endif

#define LANTERN_GOSSIPSUB_TOPIC_CAP 128u
#define LANTERN_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define LANTERN_GOSSIPSUB_PROTOCOL "/meshsub/1.0.0"
#define LANTERN_GOSSIPSUB_HEARTBEAT_INTERVAL_MS 700u
#define LANTERN_GOSSIPSUB_FANOUT_TTL_MS 60000u
#define LANTERN_GOSSIPSUB_MESH_D 8
Expand All @@ -46,10 +39,8 @@ libp2p_err_t libp2p_gossipsub_rpc_decode_frame(
#define LANTERN_LEANSPEC_JUSTIFICATION_LOOKBACK 3u
#define LANTERN_LEANSPEC_SEEN_TTL_FACTOR 2u

/* Accept both raw 1.0.0 and libp2p's stacked identifiers (prefix/1.1.0) */
static const char *const k_leanspec_gossipsub_protocols[] = {
"/meshsub/1.1.0",
"/meshsub/1.0.0/1.1.0",
"/meshsub/1.0.0",
};

Expand Down
19 changes: 0 additions & 19 deletions src/support/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined(_WIN32)
#include <io.h>
#define lantern_isatty _isatty
#define lantern_fileno _fileno
#else
#include <unistd.h>
#define lantern_isatty isatty
#define lantern_fileno fileno
#endif

static char g_node_id[96] = {0};
static enum LanternLogLevel g_min_level = LANTERN_LOG_LEVEL_INFO;
Expand All @@ -34,22 +25,12 @@ static enum lantern_log_color_mode g_color_mode = LANTERN_LOG_COLOR_AUTO;

/* ANSI color codes */
#define ANSI_RESET "\x1b[0m"
#define ANSI_BOLD "\x1b[1m"
#define ANSI_DIM "\x1b[2m"
#define ANSI_BLACK "\x1b[30m"
#define ANSI_RED "\x1b[31m"
#define ANSI_GREEN "\x1b[32m"
#define ANSI_YELLOW "\x1b[33m"
#define ANSI_BLUE "\x1b[34m"
#define ANSI_MAGENTA "\x1b[35m"
#define ANSI_CYAN "\x1b[36m"
#define ANSI_WHITE "\x1b[37m"
#define ANSI_BRIGHT_BLACK "\x1b[90m"
#define ANSI_BRIGHT_RED "\x1b[91m"
#define ANSI_BRIGHT_GREEN "\x1b[92m"
#define ANSI_BRIGHT_YELLOW "\x1b[93m"
#define ANSI_BRIGHT_BLUE "\x1b[94m"
#define ANSI_BRIGHT_CYAN "\x1b[96m"

/* Level badge colors and symbols */
static const char *level_to_color(enum LanternLogLevel level) {
Expand Down
4 changes: 0 additions & 4 deletions tests/integration/consensus_fixture_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

#include <limits.h>

#ifndef LANTERN_TEST_FIXTURE_DIR
#error "LANTERN_TEST_FIXTURE_DIR must be defined"
#endif

#define LABEL_MAX_LENGTH 64
#define MAX_LABELS 128

Expand Down
8 changes: 0 additions & 8 deletions tests/integration/test_validator_duties.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ static int init_range_assignment(
return 0;
}

#define EXPECT_ZERO(expr, label) \
do { \
if ((expr) != 0) { \
fprintf(stderr, "%s failed\n", label); \
return 1; \
} \
} while (0)

#define EXPECT_EQ(actual, expected, label) \
do { \
if ((actual) != (expected)) { \
Expand Down
4 changes: 0 additions & 4 deletions tests/integration/test_verify_signatures_vectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include "lantern/consensus/state.h"
#include "lantern/support/log.h"

#ifndef LANTERN_TEST_FIXTURE_DIR
#error "LANTERN_TEST_FIXTURE_DIR must be defined"
#endif

static void configure_logging(void) {
const char *env_level = getenv("LANTERN_LOG_LEVEL");
if (env_level && env_level[0] != '\0') {
Expand Down
Loading
Loading