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
3 changes: 1 addition & 2 deletions crates/discovery-core/src/discovery/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ pub struct ChannelCursor {
// TODO: Consider encrypting/masking channel_key in the serialized cursor
// to avoid exposing it in plaintext (sensitive value).
/// The channel key for this channel.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub channel_key: Option<Felt>,
pub channel_key: Felt,

/// All subchannels have been enumerated. Set by the discovery service
/// once the sentinel subchannel is reached. When `true`, no further
Expand Down
7 changes: 4 additions & 3 deletions crates/discovery-core/src/discovery/incoming_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub async fn discover_incoming_channels_paginated<S: IViews>(
.channels
.entry(channel.sender_addr)
.or_insert(ChannelCursor {
channel_key: Some(channel.channel_key),
channel_key: channel.channel_key,
subchannel_discovery_complete: false,
last_subchannel_index: None,
subchannels: Default::default(),
Expand Down Expand Up @@ -467,8 +467,9 @@ mod tests {

let sender_addr = channels[0].sender_addr;
assert!(cursor.channels.contains_key(&sender_addr));
assert!(
cursor.channels[&sender_addr].channel_key.is_some(),
assert_ne!(
cursor.channels[&sender_addr].channel_key,
Felt::ZERO,
"channel_key should be set for incoming channels"
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/discovery-core/src/discovery/outgoing_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub async fn discover_outgoing_channels_paginated<S: IViews>(
.channels
.entry(channel.recipient_addr)
.or_insert_with(|| ChannelCursor {
channel_key: Some(channel.channel_key),
channel_key: channel.channel_key,
subchannel_discovery_complete: false,
last_subchannel_index: None,
subchannels: HashMap::new(),
Expand Down
12 changes: 6 additions & 6 deletions crates/discovery-core/src/discovery/subchannels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ mod tests {
.unwrap();

let mut cursor = ChannelCursor {
channel_key: Some(channel_key),
channel_key,
subchannel_discovery_complete: false,
last_subchannel_index: None,
subchannels: HashMap::new(),
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
.unwrap();

let mut cursor = ChannelCursor {
channel_key: Some(channel_key),
channel_key,
subchannel_discovery_complete: false,
last_subchannel_index: None,
subchannels: HashMap::new(),
Expand Down Expand Up @@ -409,7 +409,7 @@ mod tests {

// Fresh cursor: empty map + no total → should discover subchannels
let mut fresh = ChannelCursor {
channel_key: Some(channel_key),
channel_key,
subchannel_discovery_complete: false,
last_subchannel_index: None,
subchannels: HashMap::new(),
Expand All @@ -424,7 +424,7 @@ mod tests {
// Fully enumerated cursor: empty map + skip=true → should skip entirely
// (simulates state after all notes processed and entries pruned)
let mut done = ChannelCursor {
channel_key: Some(channel_key),
channel_key,
subchannel_discovery_complete: true,
last_subchannel_index: Some(0),
subchannels: HashMap::new(),
Expand Down Expand Up @@ -484,7 +484,7 @@ mod tests {

// Pre-fill cursor to capacity (1 entry, max = 1).
let mut cursor = ChannelCursor {
channel_key: Some(channel_key),
channel_key,
subchannel_discovery_complete: false,
last_subchannel_index: None,
subchannels: HashMap::from([(Felt::from(0xabc), Default::default())]),
Expand Down Expand Up @@ -519,7 +519,7 @@ mod tests {

// 1 existing entry + max_cursor_subchannels=2 → 1 slot available.
let mut cursor = ChannelCursor {
channel_key: Some(channel_key),
channel_key,
subchannel_discovery_complete: false,
last_subchannel_index: None,
subchannels: HashMap::from([(Felt::from(0xabc), Default::default())]),
Expand Down
4 changes: 1 addition & 3 deletions crates/discovery-core/src/sync/incoming_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ async fn process_channel<S: IViews>(
max_cursor_subchannels: usize,
budget: &IoBudget,
) -> Result<ProcessChannelResult, DiscoveryError> {
let channel_key = cursor.channel_key.ok_or_else(|| {
DiscoveryError::InvalidCursor("channel_key is required for incoming channel".into())
})?;
let channel_key = cursor.channel_key;

discover_subchannels_paginated(
pool,
Expand Down
1 change: 1 addition & 0 deletions crates/discovery-core/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//! Composes discovery primitives into complete sync workflows.

pub mod incoming_state;
pub mod outgoing_state;
Loading