Skip to content

feat: add federation gateway monitoring and API#109

Open
bansalayush247 wants to merge 5 commits into
fedimint:masterfrom
bansalayush247:feature/gateways
Open

feat: add federation gateway monitoring and API#109
bansalayush247 wants to merge 5 commits into
fedimint:masterfrom
bansalayush247:feature/gateways

Conversation

@bansalayush247

Copy link
Copy Markdown
Member
## Summary

This PR adds federation gateway monitoring, stores gateway announcements in the database, and exposes the stored gateway data through a new API endpoint.

## Changes

- add a new `GatewayInfo` API type for gateway responses
- add schema migration `v9` with a new `gateways` table
- start a background gateway monitor for each federation
- poll LN module peers for gateway announcements and merge results across guardians
- upsert gateway records with `first_seen` and `last_seen` timestamps
- expose `GET /federations/:federation_id/gateways`

## Steps to Run Locally

1. Enter the Nix shell.

```bash
cd /home/nightfury69/data/fedimint-observer
nix develop
  1. Copy the env file once.
cp sample.env .env
  1. Start PostgreSQL.
just pg_start
  1. Export the .env values into your shell, then run the server.
set -a
source .env
set +a
cargo run --bin fmo_server
  1. Register a live federation from another terminal inside nix develop.
set -a
source .env
set +a

INVITE=$(curl -s "https://observer.fedimint.org/api/federations" | python3 -c "
import sys, json
feds = json.load(sys.stdin)
print(feds[0]['invite'])
")

echo "Invite: $INVITE"

curl -X PUT http://localhost:3000/federations \
  -H "Authorization: Bearer $FO_ADMIN_AUTH" \
  -H "Content-Type: application/json" \
  -d "{\"invite\": \"$INVITE\"}"
  1. Wait for the gateway monitor to poll.
    The default poll interval is 5 minutes, or it can be reduced temporarily for local testing.

  2. Fetch the federation ID and test the gateways endpoint.

FED_ID=$(curl -s http://localhost:3000/federations | python3 -c "
import sys, json
feds = json.load(sys.stdin)
print(feds[0]['id'])
")

echo "Federation ID: $FED_ID"

curl -s http://localhost:3000/federations/$FED_ID/gateways | python3 -m json.tool

Verification

  • manually registered a live federation locally
  • confirmed the gateway monitor stores gateway data
  • confirmed GET /federations/:federation_id/gateways returns the stored gateway list

- Introduced  and  methods in the API service to retrieve gateway information based on federation ID and invite code.
- Updated API types to include , , and  for better structure and type safety.

feat(database): create gateway_poll_snapshots table

- Added a new table  to store snapshots of gateway visibility over time, including fields for federation ID, gateway ID, poll time, and visibility status.

feat(federation): implement gateway fetching logic

- Implemented  to aggregate gateway information from federation peers.
- Enhanced the  to periodically poll and store gateway data, including metrics for activity and uptime.

fix(federation): update gateway listing to include metrics

- Modified  to return additional metrics such as activity and uptime for specified time windows.
- Improved error handling and logging for gateway fetching operations.

refactor(federation): adjust module visibility

- Changed the visibility of the  module to  to restrict access to internal components only.
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