Workshop 11: Federation Hands-On
Goal
Explore federation code paths, understand agreement workflows, and trace cross-cooperative message handling.
Prerequisites
- Completed Module 11 reading
- Familiarity with gossip concepts from Module 5
Estimated time
2-3 hours
Part 1: Cooperative Registry Exploration
Steps
- Open
icn/crates/icn-federation/src/registry.rs - Find the
CooperativeRegistrystruct - Identify the methods for:
- Adding a cooperative
- Looking up a cooperative
- Listing known cooperatives
Questions to answer
- What information is stored about each cooperative?
- How is the registry persisted?
- What happens when a duplicate cooperative is registered?
Code to find
pub struct CooperativeInfo {
pub coop_id: String,
pub coop_name: String,
pub did: Did,
pub policy: FederationPolicy,
// ...
}
Checkpoint
- You found the CooperativeRegistry struct
- You understand what metadata is stored per cooperative
Part 2: Agreement Lifecycle Walkthrough
Steps
- Open
icn/crates/icn-federation/src/agreement/types.rs - Find the
AgreementStatusenum - Open
icn/crates/icn-federation/src/agreement/manager.rs - Trace the state transitions:
- Draft → Proposed
- Proposed → Active
- Active → Suspended
- Active → Terminated
Exercise
Draw the state machine for agreement lifecycle. Include:
- All states
- Transitions with triggering methods
- Final states
Expected states
Draft → Proposed → Active → Suspended → Active
↓ ↓
Terminated ← ─ ─ ┘
Questions to answer
- What triggers the transition from Proposed to Active?
- Can a terminated agreement be reactivated?
- How is agreement expiration handled?
Checkpoint
- You drew the agreement state machine
- You found the
all_parties_signedcheck
Part 3: Agreement Types Deep Dive
Steps
- In
agreement/types.rs, findAgreementTypeenum - List all agreement types
- For each type, explain its purpose
Expected findings
| Type | Purpose |
|---|---|
| ResourceSharing | Share compute/storage resources |
| ClearingArrangement | Settle cross-coop transactions |
| MutualRecognition | Recognize members/attestations |
| JointGovernance | Coordinate shared decisions |
| Custom | Domain-specific agreements |
Questions to answer
- What terms would a ResourceSharing agreement include?
- How does MutualRecognition relate to attestations?
- When would you use a Custom agreement?
Checkpoint
- You can explain all agreement types
- You understand when to use each type
Part 4: Clearing and Netting Exploration
Steps
- Open
icn/crates/icn-federation/src/clearing_manager.rs - Find the
record_obligationmethod - Find the
net_positionmethod - Read
icn/crates/icn-federation/src/netting_example.md
Netting calculation exercise
Given these obligations:
Coop A owes Coop B: 150
Coop B owes Coop A: 80
Coop A owes Coop C: 50
Coop C owes Coop A: 30
Calculate:
- Net position between A and B: ___
- Net position between A and C: ___
- Total transfers with netting: ___
- Total transfers without netting: ___
Expected answers
- A owes B: 70 (150 - 80)
- A owes C: 20 (50 - 30)
- With netting: 90 total
- Without netting: 310 total
Checkpoint
- You understand bilateral netting
- You calculated net positions correctly
Part 5: Federation Gossip Handler
Steps
- Open
icn/crates/icn-federation/src/gossip.rs - Find
FederationGossipHandler - Identify the gossip topics handled:
federation:announcefederation:agreementsfederation:clearing
Questions to answer
- What happens when an announcement is received?
- How are agreement messages routed?
- What is the send callback used for?
Code to trace
pub fn handle_message(&self, topic: &str, data: &[u8]) -> Result<()>
Checkpoint
- You found all federation gossip topics
- You understand the message routing logic
Part 6: Federation Initialization
Steps
- Open
icn/crates/icn-core/src/supervisor/init_federation.rs - Trace the initialization sequence:
- Registry creation
- Clearing manager setup
- Attestation store initialization
- Agreement manager creation
- Gossip handler wiring
Questions to answer
- What services are created during federation init?
- How is the gossip send callback configured?
- What happens if federation is disabled in config?
Checkpoint
- You understand federation initialization order
- You found the config check for enabling federation
Part 7: Attestation Store
Steps
- Open
icn/crates/icn-federation/src/attestation_store.rs - Find the attestation storage methods
- Understand how attestations are verified
Questions to answer
- What data is stored in an attestation?
- How is the attestation signature verified?
- What's the difference between attestations and trust edges?
Checkpoint
- You can explain attestation structure
- You understand attestation vs trust edge distinction
Summary
After completing this workshop you should be able to:
- Navigate the federation crate structure
- Trace agreement lifecycle from draft to termination
- Calculate bilateral net positions
- Understand federation gossip message routing
- Explain attestation storage and verification
Troubleshooting
"No federation config found"
Federation must be enabled in the node config. Check FederationConfig in
the configuration file.
"Unknown cooperative"
The cooperative must be in the registry before creating agreements. Verify the announcement was received.
Next steps
You've completed the advanced federation module! Consider:
- Implementing a custom agreement type
- Exploring multilateral netting scenarios
- Contributing to federation test coverage