tn-domain-networking
Skill2 starsChanged 8 months agoMITView on GitHub
Domain expert reference for the telcoin-network libp2p layer — gossipsub topics, request-response protocols, peer discovery, epoch-aware filtering, ConsensusNetwork lifecycle. Loaded by tn-rust-engineer and tn-domain-reviewer when work touches crates/network-libp2p/**, crates/state-sync/**, peer/topic management, or any code that publishes/subscribes/requests over the wire. NOT user-invocable. Loaded programmatically by tn-* agents via the Skill tool.
In this repository36 other files it gives its agents.
- agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- create-agentSkill
- doc-writerSkill
- feynman-auditorSkill
- gh-issueSkill
- human-writingSkill
- mermaidSkill
- nemesis-ogSkill
- nemesis-scanSkill
- outline-codeSkill
- report-to-pr-commentsSkill
- skill-creatorSkill
- solidity-security-scanSkill
- state-inconsistency-auditorSkill
- telx-reviewSkill
- tn-add-benchmarkSkill
- tn-bug-scanSkill
- tn-debug-e2eSkill
- tn-domain-consensusSkill
- tn-domain-contractsSkill
- tn-domain-epochSkill
- tn-domain-executionSkill
- tn-domain-storageSkill
- tn-domain-workerSkill
- tn-hardenSkill
- tn-nemesis-scanSkill
- tn-review-contractsSkill
- tn-reviewSkill
- tn-rust-engineerSkill
- tn-rust-skillsSkill
- tn-security-evalSkill
- tn-threat-modelSkill
- tn-write-crate-docSkill
- tn-write-e2eSkill
- tn-write-proptestSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
If you are about to modify code that:
- Distinctive: line 47
Is this code path running on inbound (peer) data?: If yes, treat every byte as adversarial.
- Distinctive: line 55
Does epoch filtering happen before or after this point?: Before, ideally — downstream handlers should not need to re-check epoch validity.
- Distinctive: line 81
Keep the swarm alive; rebuild only the per-epoch handle.
- Distinctive: line 114
If we subscribe to epoch N+1's topic before our boundary fires, we receive future-epoch traffic and have to buffer it (or worse, dispatch …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
tn-domain-networking
Networking is the boundary where adversarial input first enters the node. Every byte received from the wire is potentially malicious. This layer's job is to drop, rate-limit, and filter that traffic so downstream layers (consensus, worker) see only well-formed, peer-authenticated, epoch-current messages.
If you are about to modify code that:
- lives under
crates/network-libp2p/**,crates/state-sync/** - defines or modifies gossipsub topics, request-response protocols, codecs
- handles peer discovery, connection management, peer scoring
- filters or routes messages by epoch
- publishes consensus messages or fetches batches over the network
…load this skill before writing a single line.
Why networking is different
Two things make this layer special:
- Adversarial input. Anyone with a libp2p connection can send any bytes. Codec errors, oversized messages, protocol-violating sequences must be handled without crashing or spending unbounded resources.
- Epoch-coupled lifecycle. The underlying swarm is node-lifetime, but topics, peer filters, and trust assumptions are per-epoch. Mismatched lifecycle (e.g., subscribing to next-epoch topic before our own boundary fires) leaks future-epoch traffic into current-epoch handling.
Invariants
ConsensusNetworkis created once and lives for the node's lifetime. Per-epoch handles wrap the inner network with epoch-specific subscriptions and committee filters; the swarm itself does not restart on epoch transition. (Cross-referencestn-domain-epochI-5.)- Topic subscriptions are managed at epoch transition. Subscribe to new-epoch topics on
RunEpochMode::NewEpoch; unsubscribe from prior-epoch topics after a grace window for late messages. - Inbound messages are filtered by epoch before downstream dispatch. A header from epoch N+1 received during epoch N must be deferred or dropped, not forwarded to the certifier (which would crash on the epoch mismatch).
- Codec failures are non-fatal and metered. A peer sending malformed bytes triggers a metered drop and possibly a peer-score decrement — never a panic, never an unbounded retry loop.
- Per-peer resource limits are enforced. Bytes/sec, pending requests, batch-fetch concurrency, gossipsub mesh size — all bounded. Unbounded queues here are amplification attacks waiting to happen.
Pre-write Checklist
- Is this code path running on inbound (peer) data? If yes, treat every byte as adversarial. Validate codec, size, and epoch before allocating downstream resources.
- What's the lifecycle of this resource? Node-lifetime (swarm, listeners), epoch-lifetime (topics, committee filter), or per-message (request-response handler)?
- What happens if a peer sends garbage? Metered drop, peer-score impact, no crash, no unbounded retry. Confirm the path satisfies all four.
- What bounds this allocation? Pending requests per peer, total mesh size, fetch buffer — name the bound and verify enforcement.
- Does epoch filtering happen before or after this point? Before, ideally — downstream handlers should not need to re-check epoch validity.
Canonical Sources
| Value | Source | Avoid |
| Long-running swarm | ConsensusNetwork created in spawn_node_networks, lives for node lifetime | Per-epoch swarm restart |
| Per-epoch topic name | LibP2pConfig::*_topic_for(epoch) (or eq.) | Hardcoded topic strings |
| Active peer set for epoch | Derived from epoch's committee + observers | Live peer list (includes retired validators) |
| Peer score | Per-peer accumulator with metered events | Boolean trust flag |
| Request-response timeout | Configured per-protocol | Default tokio timeout |
| Bound on pending fetches | Per-peer + per-protocol caps | Unbounded Vec |
Common Bug Patterns
Pattern 1: Per-epoch swarm restart
// WRONG — restarts swarm per epoch, breaking peer connections
match run_epoch_mode {
RunEpochMode::NewEpoch => {
self.network = ConsensusNetwork::new(...)?;
}
}Keep the swarm alive; rebuild only the per-epoch handle.
Pattern 2: Forwarding cross-epoch messages
// WRONG — forwards header from peer in epoch N+1 while we're in epoch N
fn on_header(&mut self, header: Header) {
self.certifier.process(header);
}Filter header.epoch against current epoch first; defer or drop.
Pattern 3: Unbounded pending fetches
// WRONG — unbounded; spammer drives node OOM
self.pending.push(fetch_request);Bounded buffer; drop or backpressure when full.
Pattern 4: Codec error → panic
// WRONG — peer-controlled bytes; panic = remote DoS
let msg: Header = bincode::deserialize(&bytes).unwrap();Return Err, increment a metric, decrement peer score, drop the message.
Pattern 5: Subscribing to next-epoch topic too early
If we subscribe to epoch N+1's topic before our boundary fires, we receive future-epoch traffic and have to buffer it (or worse, dispatch it to handlers that don't know epoch N+1 yet). Subscribe at the transition, not before.
Further Reading
references/invariants.mdreferences/bug-patterns.mdreferences/canonical-sources.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

