From 0cf6fe72fdee62f80070c6d4bf4341ce6faf3cc8 Mon Sep 17 00:00:00 2001 From: Tom <116762865+NomDeTom@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:17:42 +0100 Subject: [PATCH] fix self-nodeID change (#10822) * fix se0fl-nodeID change * address review: avoid redundant satellite erase + add braces in createNewIdentity removeNodeByNum() already drops the satellite stores (and warm-tier copy) when it removes the node, so only erase satellites directly in the rare case the lite entry was already absent. Brace the removal block. --------- Co-authored-by: Ben Meadors --- src/mesh/NodeDB.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index dbffddff8..9adebf5d6 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -3858,19 +3858,18 @@ bool NodeDB::createNewIdentity() if (newNodeNum == oldNodeNum) return false; - // Retire the old node entry - meshtastic_NodeInfoLite *node = getMeshNode(oldNodeNum); - if (node != NULL) { - LOG_DEBUG("Old node num %u is now %u", oldNodeNum, newNodeNum); - nodeInfoLiteSetBit(node, NODEINFO_BITFIELD_IS_IGNORED_MASK, true); - node->public_key.size = 0; - memset(node->public_key.bytes, 0, sizeof(node->public_key.bytes)); + // Remove the old node entry entirely rather than retiring it in place. Flagging the old identity as + // ignored (the previous behavior) left a keyless ghost of ourselves that survived cleanup/eviction, was + // still streamed to clients, and made any DM/admin aimed at it fail forever with PKI_SEND_FAIL_PUBLIC_KEY. + // removeNodeByNum() drops the lite entry, its satellite stores, and the warm-tier copy. + if (getMeshNode(oldNodeNum) != NULL) { + LOG_DEBUG("Old node num %u is now %u, removing stale identity", oldNodeNum, newNodeNum); + removeNodeByNum(oldNodeNum); + } else { + // Lite entry already absent: drop any orphaned satellite-store entries directly. + eraseNodeSatellites(oldNodeNum); } - // Drop satellite-store entries (position/telemetry/environment/status) keyed by the retired - // node number so stale data isn't left attached to the old identity. - eraseNodeSatellites(oldNodeNum); - myNodeInfo.my_node_num = newNodeNum; meshtastic_NodeInfoLite *info = getOrCreateMeshNode(getNodeNum());