Skip to content

fix: Enforce single target network notes in NTB#1166

Merged
sergerad merged 11 commits intonextfrom
sergerad-ntb-single-target-note
Aug 27, 2025
Merged

fix: Enforce single target network notes in NTB#1166
sergerad merged 11 commits intonextfrom
sergerad-ntb-single-target-note

Conversation

@sergerad
Copy link
Copy Markdown
Collaborator

@sergerad sergerad commented Aug 20, 2025

Context

Closes #1115.

The NTB only supports single target network notes and does not currently check for this when constructing NetworkNote from Note.

Changes

  • Update NetworkNote to be an enum with single and multi target variants.
  • Add SingleTargetNetworkNote and MultiTargetNetworkNote types.
  • Use SingleTargetNetworkNote in NTB.

Comment thread crates/proto/src/domain/note.rs
Comment thread CHANGELOG.md Outdated
Comment thread crates/proto/src/domain/note.rs
@sergerad sergerad force-pushed the sergerad-ntb-single-target-note branch from e307d6d to 0681e25 Compare August 20, 2025 23:04
@sergerad sergerad changed the title fix: Validate note is single target when converting into NetworkNote in NTB fix: Filter out NetworkNotes that are not single target in NTB Aug 21, 2025
Comment thread crates/ntx-builder/src/state/mod.rs
@sergerad sergerad requested a review from bobbinth August 25, 2025 00:05
Comment thread crates/ntx-builder/src/store.rs Outdated
Comment thread crates/proto/src/domain/note.rs Outdated
@sergerad sergerad requested a review from bobbinth August 25, 2025 03:01
@sergerad sergerad changed the title fix: Filter out NetworkNotes that are not single target in NTB fix: Enforce single target network notes in NTB Aug 25, 2025
Copy link
Copy Markdown
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you. Overall, I think this approach works fine for now. We could make it more type-safe by introducing newtype for each type of notes. NetworkNote then could look something like:

pub enum NetworkNote {
    SingleTarget(SingleTargetNote),
    MultiTarget(MultiTargetNote),
}

pub struct SingleTargetNote(Note);
pub struct MultiTargetNote(Note);

And then most of the APIs would work with SingleTargetNote for now.

But I'll defer to @Mirko-von-Leipzig on this.

Comment thread crates/ntx-builder/src/state/mod.rs Outdated
Comment on lines +119 to +126
// TODO: support multi target network notes.
if let Some(prefix) = note.account_prefix() {
// Ignore notes which don't target an existing account.
let Some(account) = state.fetch_account(prefix).await? else {
continue;
};
account.add_note(note);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably replace the TODO with a simple comment explaining that we handle only single-target accounts for now.

Also, we can probably re-write this as:

if let Some(prefix) = note.account_prefix() {
    let Some(account) = state.fetch_account(prefix).await? {
        account.add_note(note);
    }
}

Lastly, I would expand the comment and explain under which circumstances we may get a single-target note that doesn't have a target account.

Comment thread crates/ntx-builder/src/state/mod.rs Outdated
Comment on lines +345 to +353
// TODO: support multi target network notes.
if let Some(prefix) = note.account_prefix() {
self.nullifier_idx.insert(note.nullifier(), prefix);
// Skip notes which target a non-existent network account.
if let Some(account) =
self.fetch_account(prefix).await.context("failed to load account")?
{
account.add_note(note);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too I would replace the TODO with a simple comment about not handling multi-target notes yet (mostly because enabling support for multi-target notes is a much bigger refactoring than a simple TODO here implies).

Also, I would expand the comment and explain why there could be non-existent network accounts.

Comment thread crates/ntx-builder/src/state/mod.rs Outdated
Copy link
Copy Markdown
Collaborator

@Mirko-von-Leipzig Mirko-von-Leipzig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned; I would prefer a SingleTargetNetworkNote so that we're certain what we're working with everywhere.

We don't know what or how we're going to manage the other variant(s); I think adding a strong type will help us refactor in the future without worrying about screwing up.

Comment thread crates/proto/src/domain/note.rs Outdated
Comment thread crates/ntx-builder/src/state/mod.rs Outdated
@sergerad sergerad force-pushed the sergerad-ntb-single-target-note branch from b454ddf to 914f859 Compare August 27, 2025 20:15
@sergerad sergerad merged commit f0735ca into next Aug 27, 2025
6 checks passed
@sergerad sergerad deleted the sergerad-ntb-single-target-note branch August 27, 2025 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client interaction failure after creating network note

3 participants