Skip to content

Backend v2 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 134 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
6469528
feat: create logger, performance tracker and time keeper
Aerilym Nov 20, 2024
b002be3
feat: web3 client and contract function
Aerilym Nov 20, 2024
c44989c
feat: eth event scanner
Aerilym Nov 20, 2024
5563aea
feat: registration api
Aerilym Nov 20, 2024
00f8b51
chore: move oxen and omq logic to package
Aerilym Nov 20, 2024
1f4fec3
feat: db manager
Aerilym Nov 20, 2024
8f19288
feat: registrations reader
Aerilym Nov 20, 2024
e7e14c2
feat: overhaul config
Aerilym Nov 20, 2024
9968ad7
feat: create fetcher
Aerilym Nov 20, 2024
5d549b5
feat: read only api
Aerilym Nov 20, 2024
a653a36
chore: update README.md
Aerilym Nov 20, 2024
b552013
fix: config rpc validation
Aerilym Nov 21, 2024
65c01d6
fix: omq rpc test
Aerilym Nov 21, 2024
83c2f92
fix: rpc shared config var
Aerilym Nov 21, 2024
1cb7630
fix: perf logger and rpc arg call
Aerilym Nov 21, 2024
cfd8aa6
fix: add self logger as non if perf is off
Aerilym Nov 21, 2024
e095381
fix: performance logger
Aerilym Nov 21, 2024
4317c28
feat: add median operator fee to network info api endpoint
Aerilym Nov 26, 2024
906328c
feat: add api route to get stakes by sn pubkey
Aerilym Dec 11, 2024
aaa27e7
feat: add arbitrum network info and event endpoints
Aerilym Dec 20, 2024
92e0641
fix: change arbiturm provider url to list of urls for later adding of…
Aerilym Dec 23, 2024
cd10d49
feat: add rewards fetching and endpoints to fetcher and api
Aerilym Dec 23, 2024
e16f1f7
chore: move registration getter api endpoints to main api
Aerilym Dec 23, 2024
7949251
fix: update db schema with arbitrum info and rewards info tables
Aerilym Dec 23, 2024
a51fd12
feat: add timestamps to events
Aerilym Dec 28, 2024
b8993c1
feat: add node counts to network info
Aerilym Dec 28, 2024
6f4fee3
feat: add node exit list parsing to fetcher
Aerilym Dec 28, 2024
e208a27
fix: rewards address parsing
Aerilym Dec 28, 2024
2f41817
fix: add contribution contract api endpoints
Aerilym Dec 28, 2024
0012048
fix: event scanner block range chunk size passed between requests
Aerilym Dec 28, 2024
f71a41c
fix: time keeper perf enabled
Aerilym Dec 28, 2024
f965034
fix: time keeper perf
Aerilym Dec 28, 2024
ca798dc
fix: registration insert sql statement syntax
Aerilym Dec 29, 2024
828c3bb
fix: registration bytes formatting
Aerilym Dec 29, 2024
c7d5f4e
fix: overriding in stake list from staging contributors
Aerilym Dec 30, 2024
71ca9be
fix: use eth checksum addresses for api endpoints
Aerilym Dec 30, 2024
bf48c5a
feat: add bls key parser
Aerilym Jan 2, 2025
c02f36d
feat: create get_arbitrum_events_since_timestamp db reader
Aerilym Jan 2, 2025
540661e
feat: add node_add_timestamp to contribution contracts using arbitrum…
Aerilym Jan 2, 2025
c8a7172
feat: create rpc usage tracker
Aerilym Jan 2, 2025
65079d3
chore: simplify oxen rpc to use shared future json method
Aerilym Jan 2, 2025
8c6d5e9
chore: clean up rpc usage logging formatting
Aerilym Jan 2, 2025
0ba118d
fix: add default message to rpc usage
Aerilym Jan 2, 2025
c6cf1f8
fix: extend timeout on prc rewards bls request
Aerilym Jan 2, 2025
33542a3
fix: add timeout tracking to rpc usage tracker and log reasons to file
Aerilym Jan 5, 2025
84b7bb2
feat: add contribution contract by sn key api endpoint
Aerilym Jan 5, 2025
705d31a
feat: add service_node_rewards_contract_id_bls_key_map from contract …
Aerilym Jan 5, 2025
293348f
fix: increase timeout times for exit and rewards sig rpc calls
Aerilym Jan 5, 2025
f39084e
feat: create db snapshotter
Aerilym Jan 6, 2025
44f1906
fix: request timout in omq
Aerilym Jan 7, 2025
691557e
fix: only allow exit signature requests from exitable nodes and rewar…
Aerilym Jan 7, 2025
9e8354b
feat: add l2 info to network info
Aerilym Jan 9, 2025
27f2873
feat: add contract bls keys to stakes endpoint
Aerilym Jan 9, 2025
85a642a
fix: contract add timestamps and new token addresses
Aerilym Jan 15, 2025
d6ee872
fix: handle median node fee when no nodes
Aerilym Jan 15, 2025
2c13ee3
fix: decrease ttl for contribution contracts
Aerilym Jan 18, 2025
963e770
fix: decrease ttl for network info
Aerilym Jan 18, 2025
adcdd2c
feat: change arbitrum update loop to use goal refetch time instead of…
Aerilym Jan 18, 2025
f9bebd1
feat: add all contracts associated to an address to contribution cont…
Aerilym Jan 20, 2025
62e6af7
chore: adjust cache logic for nodes and registrations
Aerilym Jan 21, 2025
8d86aac
feat: add manual finalize data for contributor contracts and created …
Aerilym Jan 21, 2025
4aa4b23
feat: add reserved slots data to contracts
Aerilym Jan 27, 2025
c43b201
feat: add more detailed cache controls to cache manager
Aerilym Jan 27, 2025
c365304
feat: create flask rate limiter
Aerilym Jan 27, 2025
a852cd4
fix: remove unused contract field in registrations db and enforce uni…
Aerilym Jan 27, 2025
5ff9b39
fix: performance logger orphan cleanup maths
Aerilym Jan 27, 2025
e6a2819
chore: add rate limits
Aerilym Jan 27, 2025
82c3e4e
chore: cleanup v1 backend and start scripts
Aerilym Jan 27, 2025
513c93a
feat: convert flask scripts into contained apps with parent dir runners
Aerilym Jan 27, 2025
7b47db2
feat: create price fetcher
Aerilym Jan 27, 2025
8e2e201
feat: create new config system for prices and base flask
Aerilym Jan 27, 2025
b269162
chore: create token conversion methods and tests
Aerilym Jan 28, 2025
2c739dd
chore: move non route methods to app class in price api
Aerilym Jan 28, 2025
a1d9431
fix: abi manager default add to cache
Aerilym Jan 28, 2025
663f42d
fix: change all inner module imports to relative imports
Aerilym Jan 28, 2025
b2acb63
fix: abi manager default and coingecko defaults
Aerilym Jan 29, 2025
118f383
fix: add root level package init
Aerilym Jan 29, 2025
ad3fdc6
chore: move python code into src folder so it can be used as a packag…
Aerilym Jan 29, 2025
02fb28e
chore: move configs
Aerilym Jan 29, 2025
8587905
fix: make db readers read only
Aerilym Jan 30, 2025
ae65c66
fix: use relative imports for src
Aerilym Jan 30, 2025
97361cb
fix: change packages to use relative imports to themselves
Aerilym Jan 30, 2025
022a210
fix: only require uwsgi for price fetcher if timer is active
Aerilym Jan 30, 2025
57bebdd
fix: leading slash on db file names
Aerilym Jan 30, 2025
6f2b566
fix: add disable db file rewrite option
Aerilym Jan 30, 2025
8a13b8d
fix: update most recent price fetcher
Aerilym Jan 30, 2025
b2d3018
fix: cache getters on no item
Aerilym Jan 30, 2025
20410e9
fix: cache ttl and invalidation defaults
Aerilym Jan 30, 2025
53ad6f0
fix: db read uri
Aerilym Jan 31, 2025
06d7d87
fix: change server timestamp to int
Aerilym Jan 31, 2025
a7b0e76
fix: raw transaction old version support
Aerilym Feb 3, 2025
0d9ffd0
feat: create cache tests
Aerilym Feb 3, 2025
19653f1
fix: staking api config
Aerilym Feb 4, 2025
fe6fd00
fix: abi manager cache
Aerilym Feb 4, 2025
71a225a
fix: fetcher runner
Aerilym Feb 4, 2025
109b98f
fix: show reserved slots for non-contributed contracts
Aerilym Feb 4, 2025
bee4a2b
fix: module resolution for registration and snapshot apps
Aerilym Feb 6, 2025
df6361f
fix: make default immutable block height 0
Aerilym Feb 6, 2025
b52cfb2
fix: make immutable block height 0 if None
Aerilym Feb 6, 2025
419a637
fix: mutate immutable block height 0 if None
Aerilym Feb 6, 2025
afcf941
fix: use get for immutable block height 0 if None
Aerilym Feb 6, 2025
d6d3f7b
fix: recreate network class on immutable 0
Aerilym Feb 6, 2025
6b767cf
fix: add defaults to oxen rpc network info
Aerilym Feb 6, 2025
167713a
fix: default config db schemas
Aerilym Feb 6, 2025
f3d0540
fix: add defaults for all net info fields
Aerilym Feb 6, 2025
3101955
Merge pull request #5 from session-foundation/price_api
Aerilym Feb 12, 2025
1fc42b2
fix: update db snapshot task with new config
Aerilym Mar 7, 2025
f1ce6dd
fix: update default config and config validator
Aerilym Mar 7, 2025
2e9b5d9
chore: remove unused config items
Aerilym Mar 7, 2025
ae4524b
chore: update abis
Aerilym Mar 7, 2025
a6755e7
feat: compile smart contracts from source
Aerilym Mar 7, 2025
a722604
feat: create websockets arbitrum event scanner
Aerilym Mar 7, 2025
d538fdc
feat: add vesting support and updated event support to staking backend
Aerilym Mar 7, 2025
c67f4f1
feat: add vesting support and updated event support to staking backend
Aerilym Mar 7, 2025
eb00b5d
Merge pull request #6 from session-foundation/price_api
Aerilym Mar 7, 2025
3df7206
Merge remote-tracking branch 'origin/main' into backend_v2
Aerilym Mar 7, 2025
c1451e4
fix: rework price api to simplify token fetching behaviour
Aerilym Apr 2, 2025
0c75a79
fix: add db read mode utils
Aerilym Apr 2, 2025
aaa1555
feat: add ws contract classes
Aerilym Apr 2, 2025
ad32a25
fix: truncate price stale time
Aerilym Apr 2, 2025
e6decaa
feat: add precision to coingecko api
Aerilym Apr 2, 2025
d274c55
feat: add dynamic price cache management to price api
Aerilym Apr 11, 2025
485394c
wip: to clean
Aerilym May 15, 2025
2f1b496
Update readme and requirements with latest dependencies
Doy-lee May 15, 2025
aab080d
fix: update token contracts submodule to use the foundation repo
Aerilym May 19, 2025
1050b82
fix: update requirements.txt with oxenmq, oxenc, and web3 requirements
Aerilym May 19, 2025
66b2135
chore: update config_defaults.py with mainnet values
Aerilym May 19, 2025
f69b82d
feat: add daily rolling rewards endpoint
Aerilym May 19, 2025
bcf7848
feat: add block cap and getLogs chunking to event scanner and new hea…
Aerilym May 19, 2025
ef46433
chore: add utility setup scripts
Aerilym May 19, 2025
195ff24
feat: add price range endpoint
Aerilym May 19, 2025
8ea7c6e
Merge pull request #7 from session-foundation/fix/limits
Aerilym May 20, 2025
2113bba
Merge pull request #8 from session-foundation/feat/price_ranges_api
Aerilym May 20, 2025
4ccd968
fix: add and use fetched time for stale time for token prices
Aerilym Jun 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/sent-backend.db*
/config.py
/*.db
/src/config.py
/__pycache__
/oxend/*.sock
*/__pycache__
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "session-token-contracts"]
path = session-token-contracts
url = https://github.com/session-foundation/session-token-contracts.git
5 changes: 0 additions & 5 deletions Makefile

This file was deleted.

46 changes: 29 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SENT Staking Backend
# Session Staking Backend

## Running the backend

Expand All @@ -7,10 +7,14 @@
The `liboxenc-dev` and `liboxenmq-dev` packages require the development headers by setting up the
[Oxen Deb Repository](https://deb.oxen.io). Follow those instructions then they can be installed with `apt`.

To run the backend on **Ubuntu >= 24.04**:
The backend has been tested on Ubuntu 24.04. It requires Python >=3.11.x and
`pnpm` from NodeJS >=20.12.x . To get started with this repository ensure you
have the necessary dependencies and the submodules have been synchronised.

```shell
apt install build-essential python3-pip python3-dev pybind11-dev liboxenc-dev liboxenmq-dev
python3 -m pip install eth_utils web3 PyNaCl Flask uWSGI
python3 -m pip install --requirement requirements.txt
git submodule update --init --recursive
```

**Python bindings for oxen-mq & oxen-encoding**
Expand All @@ -20,21 +24,28 @@ Instructions available at:
- [oxen-pyoxenc](https://github.com/oxen-io/oxen-pyoxenc)
- [oxen-pyoxenmq](https://github.com/oxen-io/oxen-pyoxenmq)

### Structure

The backend has multiple parts:

- **Events**: `app_events.py` retrieves events emitted by contracts on Arbitrum and stores them to the database
- **Fetcher**: `app_fetcher.py` retrieves data from the Session and Arbitrum network
- **Price**: `app_price.py` polls Coingecko for pricing information TODO: Merge this into staking
- **Registrations**: `app_registrations.py` handles HTTP requests for Session node registrations TODO: Merge this into staking
- **Snapshot**: TODO: Remove this class, snapshot should mean copying the DB file or using sqlite's native backup
- **Staking**: Serves endpoints for managing the state of staking into the Session network via the staking portal website

### Instance

Before running an instance, `oxend` must be running and its address/smart contracts configured in
`config.py`.
Before running the Fetcher or API, `oxend` must be running and its address/smart contracts configured in `config.py`.

It's possible to run the service in flask directly but the timers to poll the smart contracts
requires WSGI. Both methods are detailed below:
### Running the backend stack

FLASK_APP=sent flask run --reload --debugger
uwsgi --http 127.0.0.1:5000 --master -p 4 -w sent --callable app
Run the backend using UWSGI (example runs it on port 4455 with 4 request handlers):

You may optionally append `--fs-reload sent.py` to the `uwsgi` invocation to
automatically restart the server when `sent.py` is modified.
uwsgi --http 127.0.0.1:4455 --master -p 4 -w src.app_staking --callable app --mule=src/app_events.py --mule=src/app_fetcher.py

After the server is running, visit `127.0.0.1:5000/info` to verify that the server is up and
After the server is running, visit `127.0.0.1:4455/info` to verify that the server is up and
responding correctly with a payload like the following:

```json
Expand Down Expand Up @@ -63,7 +74,7 @@ There are a few ways to make this work.

### Symlinks

You can add symlinks here to existing oxend sockets. If oxend and the backend code are running as
You can add symlinks here to existing oxend sockets. If oxend and the backend code are running as
the same user then you can simply create a symlink:

ln -s /var/lib/oxend/oxend.sock mainnet.sock
Expand All @@ -75,7 +86,7 @@ you can make it work, but will need an extra step to configure socket permission

and then do one of:

- Set the active group of the running sent staking backend to the `_loki` user. Whether this is
- Set the active group of the running sent staking backend to the `_loki` user. Whether this is
easy or not depends on how the backend service is running.

- Add the `_loki` group to the supplemental groups of the user that will be running this backend.
Expand All @@ -89,14 +100,14 @@ and then do one of:

Do *NOT*:

- Run any production service as root (including under sudo). Don't be tempted just because "it
- Run any production service as root (including under sudo). Don't be tempted just because "it
works" under sudo: by running things under root/sudo you compromise the security of your entire
system as a solution to properly setting up permissions. Please don't do this, ever.
system as a solution to properly setting up permissions. Please don't do this, ever.

### Make oxend create the socket

The `lmq-public=ipc:///path/to/sent-staking-backend/oxend/mainnet.sock` can be added to oxen.conf
(or run with `--lmq-public=...`) to have it listen on that socket. Note that when oxend and
(or run with `--lmq-public=...`) to have it listen on that socket. Note that when oxend and
sent-staking-backend are running as separate users, this has the same permission issues as the
Symlinks approach (see above for solutions).

Expand All @@ -106,3 +117,4 @@ You can configure oxend with `lmq-public=tcp://127.0.0.1:6789` (choose whatever
place of `6789`) in the oxen.conf config file [alternatively: run oxend with
`--lmq-public=tcp://127.0.0.1:6789`] and then add/uncomment the `mainnet_rpc=...` (or `testnet_rpc=`
or `devnet_rpc=`) line in config.py.

36 changes: 0 additions & 36 deletions abi_manager.py

This file was deleted.

Loading