robosats
robosats copied to clipboard
Add The Federation Layer v0.6.0
follow up of #601. This PR squashes and rebases over main the-federation-layer branch All API pre-requisites are already merged in Main. This PR contains only frontend changes
What does this PR do?
This PR brings to main the experimental fork The Federation Layer. We will keep it open as a draft for some time to track progress. We will certainly keep it away from main until well tested with a bunch of Testnet voluntary coordinators.
For context read the Issue where the RoboSats Federation concept was introduced https://github.com/Reckless-Satoshi/robosats/issues/228
Tasks towards RoboSats Federation Minimum Viable Product:
Last things needed before merge and release:
- [ ] Bugs and regressions on v0.6.0 https://github.com/RoboSats/robosats/issues/1069
Frontend:
- [x] Read from
static/federation.json
the list of RoboSats coordinators and their.onion
addresses. - [x] Build Coordinator Dialog with a profile of each coordinator. Optionally, make it cool and add coordinator badges.
- [x] Build Coordinator table (keep it in the Settings tab)
- [x] Refactor Stats dialogs to show aggregated stats for all active coordinators (volume, premium, etc).
- [x] Create Context high level functions and abstractions of the federation.
- [x] Book page requests all orders from all coordinators. Shows each row on coordinator's color as well as the coordinator logo. Book page allows for filtering by Federation member.
- [x] If a user clicks on the order of another coordinator, it should trigger an
api/usergen/
request (so that Robot / Avatar / Token hash / PGP pubkey and encPrivKey exists as well on the coordinator's database). EDIT: new middleware will generate robots in the fly if auth token (SHA256(robot_token)) does not exist. New endpoint "Robot" to fetch existing robot nickname, pubkey, etc. - [x] Everything else in the trade pipeline remains the same. However the
/order/
API requests will be made to that order's coordinator.onion
address. - [x] Each coordinator, on its hosted frontend should be able to opt-in and out of showing other coordinators orders. They can do so by editing the static file they host in
static/federation.json
. - [x] Use paths for each coordinator. E.g.
...robosats.onion/order/coordinator_shortname/21
- [x] Add a "select host" dropdown in the MakerForm
- [ ] Add a new Setting "Number of active coordinators" to select how many coordinators to use at once. Default to 5. Users can increase them at the cost of UI performance.
- [x] At startup coordinators will be selected ranked 1 to N, the rank will be probabilistically linked to the devfund donation (%) of the coordinator. The top K (default 5) will be selected. Orders in the order book will be sorted by coordinator rank by default. This is the only patron perk so far designed to reward those coordinators contributing to RoboSats development.
- [x] If selfhosted, use the same "local" endpoint for every coordinator, yet a different path using the coordinator shortname. E.g. ".../api/coordinator_shortname/order/...".On nodeapp, spawan a socat bridge for each Coordinator Onion address and write nginx config to proxy each API subpath to the coordinator onion endpoint.
- [ ] Optional - Low priority On the coordinator table, add tools for users to delete/add coordinators using a form (issue: these are forgotten in browsers that do not keep local storage after restart. This will work just fine on Android app).
- [ ] Optional - Needs research At the end of a trade, the user rates the coordinator (instead of "What do you think of RoboSats?"). The order ID, rating and coordinator alias is sent to every Federation member. The ratings will help keep coordinators informed about their own performance and other federation members performance. It will allow for sorting access to coordinator addresses in the docs / github / frontends according to some non-arbitrary criteria.
Backend:
- [x] Allow CORS. Let other origins make calls to coordinator API.
- [x] Upgrade authentication. Replace SessionID + CSRF token for only robot hash token on every authenticated request. Implement middleware that creates user+profile+avatar entries on first authenticated request with a robot token hash not seen before.
- [x] Deprecate /user/ POST.
- [x] Anyone with the hash of a robot token could send authenticated requests (e.g, another coordinator could MITM attack a user on another coordinator). Solution: robot submits his pubkey on first authenticated requests, then every next requests must be pgp signed?
- [x] Delete current rewards program (hard to fit on a multi-coordinator set up. There are ways, but this is to be explored in the future).
- [x] Implement
compute_trade_proceeds()
on each trade finished. Implement Keysend feature for Dev donations. - [x] Limit Coordinator devfund donation to 49% of trade proceeds.
- [ ] Optional - Needs research coordinators backend could periodically fetch stats from other coordinators and "keep them in check". E.g. a coordinator might not want to show in its frontend orders of Federation members whose LN node is down, whose trade fee is very large, not contributing Sats to the dev fund, etc.
Other:
- [x] Write up
FEDERATION.md
base guide/ruleset document. - [x] Build and release docker-compose orchestration.
- [x] Build and release kubernetes RoboSats orchestration.
We have around ~110 linting issues left in this branch, they are all very minor. It is a good chance for me to check over them and get more acquainted to the large recent refactor.
The day has come. We are merging this PR. After 1 year of madness. Congratulations to anyone involved in decentralizing RoboSats!
๐๐๐๐๐๐โกโกโก