Skip to content

fix(NodeDB): addFromContact follow-up - DEBUG log level, shorter comment, regression tests - #11443

Draft
h3lix1 wants to merge 3 commits into
meshtastic:developfrom
h3lix1:fix/addfromcontact-followup
Draft

fix(NodeDB): addFromContact follow-up - DEBUG log level, shorter comment, regression tests#11443
h3lix1 wants to merge 3 commits into
meshtastic:developfrom
h3lix1:fix/addfromcontact-followup

Conversation

@h3lix1

@h3lix1 h3lix1 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #11432, which merged before these three items landed on the branch. All were raised in review of that PR.

1. Log the keyless-contact path at DEBUG. Clients send add_contact before every text-message DM, so a contact carrying no key is an expected, high-frequency case. LOG_INFO there emits one record per DM. (CodeRabbit flagged this on #11432.)

2. Shorten the comment to two lines, per AGENTS.md: "Keep code comments minimal - one or two lines, max."

3. Add the regression coverage requested on #11432 — four cases in test/test_nodedb_blocked, which already builds a real NodeDB via its test shim:

Stored key Incoming key Asserts
32 × 0xA5 empty stored key survives
32 × 0x5A 4 bytes stored key survives
32 × 0x11 32 × 0x22 incoming replaces stored
none 32 × 0x33 incoming stored

Each asserts .size and .bytes independently. That matters: CopyUserToNodeInfoLite memcpy's all 32 bytes and then sets size, so restoring size alone would leave a zeroed byte array that still reads as a valid key. The third case is the guard against over-correcting the original fix into a blanket pin — add_contact must still be able to update a key.

No manifest changes needed: test_nodedb_blocked already declares nodes.proto and warm.dat writes in test/state-manifest.tsv, and suite discovery is dynamic since #11413.

Behaviour of the merged fix is unchanged — this only lowers a log level, trims a comment, and adds tests.

🤖 Generated with Claude Code

h3lix1 and others added 2 commits August 12, 2026 11:45
Clients send add_contact before every text-message DM, so a contact with no key
is an expected, high-frequency case - LOG_INFO there would emit one record per
DM. Drop it to LOG_DEBUG.

Also trims the comment to two lines per AGENTS.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…irections

The fix in 7425f84 snapshots the stored key before CopyUserToNodeInfoLite()
and restores it when the entry held a full 32-byte key and the post-copy key
is not 32 bytes. Nothing exercised that guard, and the guard is the kind that
is easy to widen by accident, so pin all four corners of it.

Added to test_nodedb_blocked rather than test_type_conversions: addFromContact()
is a NodeDB method that needs a real hot store, getOrCreateMeshNode(), the
protected-node cap and saveNodeDatabaseToDisk(). test_nodedb_blocked already
constructs a NodeDB via NodeDBTestShim and already declares nodes.proto/warm.dat
in test/state-manifest.tsv, which is exactly the state addFromContact persists -
so no manifest or suite-registration change is needed. test_type_conversions
deliberately avoids the global nodeDB and covers CopyUserToNodeInfoLite in
isolation, where the erasure is correct behaviour, not a bug.

What each case pins:

1. emptyKeyKeepsStoredKey - a contact with public_key.size == 0 must not erase a
   stored 32-byte key. This is the reported bug: public_key is a singular bytes
   field, so a client that simply has no key for a contact is indistinguishable
   on the wire from one clearing it, and clients send add_contact before every DM.

2. shortKeyKeepsStoredKey - the same for a 4-byte key. CopyUserToNodeInfoLite
   memcpy's all 32 bytes and then sets size, so a short key both truncates size
   and rewrites the byte array; anything short of 32 bytes is unusable for PKI
   and must not displace a full key either.

3. fullKeyReplacesStoredKey - a well-formed 32-byte contact key still replaces a
   different stored 32-byte key. This is the case that matters most: the obvious
   over-correction is to turn "never erase" into updateUser()'s blanket
   first-key-wins pin, which would silently break QR-code contact sharing and
   every other documented add_contact key-update flow. Without this test, that
   regression passes cases 1, 2 and 4 unnoticed.

4. fullKeyStoredWhenNoneHeld - the ordinary add_contact path: a full key lands on
   an entry that held none, so the guard's storedKey.size == 32 precondition
   cannot be loosened into refusing new keys.

Every case asserts both public_key.size and public_key.bytes, because the two
fail independently - restoring size alone would leave the zeroed byte array the
memcpy wrote, which reads as a valid key and is not.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b555f6c3-cf6b-4ca7-a8e5-8a96e6ae7429

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

⚡ Try this PR in the Web Flasher

Note

Building this pull request… the flash button, badges and supported-board
list will appear here automatically once CI finishes.

@h3lix1 h3lix1 changed the title test fix(NodeDB): addFromContact follow-up - DEBUG log level, shorter comment, regression tests Aug 12, 2026
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.

1 participant