Tighten TreeAnnounce validation to match spanning tree specification

Adds TreeAnnounce::validate_semantics() called from handle_tree_announce
before any tree-state mutation. Enforces that the ancestry accompanying
a parent declaration conforms to the spanning tree rules:

- first ancestry entry matches the signed sender
- is_root declarations carry a single-entry ancestry
- non-root declarations include the signed parent as the second entry
- the advertised root is the minimum node_addr in the ancestry

Non-conforming announcements are rejected with a warn log and no state
change. Adds unit tests for each rejected shape plus an integration
test covering the full receive path in a two-node tree.

Co-authored-by: Johnathan Corgan <johnathan@corganlabs.com>
This commit is contained in:
Sats And Sports
2026-04-15 16:55:48 +00:00
committed by Johnathan Corgan
co-authored by Johnathan Corgan
parent 7e002a3883
commit b36966be3a
5 changed files with 305 additions and 1 deletions
+9
View File
@@ -172,6 +172,15 @@ impl Node {
return;
}
if let Err(e) = announce.validate_semantics() {
warn!(
from = %self.peer_display_name(from),
error = %e,
"Rejected TreeAnnounce with invalid ancestry"
);
return;
}
let now_ms = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_millis() as u64)