-
Notifications
You must be signed in to change notification settings - Fork 2
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
Aerilym
wants to merge
144
commits into
main
Choose a base branch
from
backend_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Backend v2 #4
Changes from 116 commits
Commits
Show all changes
144 commits
Select commit
Hold shift + click to select a range
6469528
feat: create logger, performance tracker and time keeper
Aerilym b002be3
feat: web3 client and contract function
Aerilym c44989c
feat: eth event scanner
Aerilym 5563aea
feat: registration api
Aerilym 00f8b51
chore: move oxen and omq logic to package
Aerilym 1f4fec3
feat: db manager
Aerilym 8f19288
feat: registrations reader
Aerilym e7e14c2
feat: overhaul config
Aerilym 9968ad7
feat: create fetcher
Aerilym 5d549b5
feat: read only api
Aerilym a653a36
chore: update README.md
Aerilym b552013
fix: config rpc validation
Aerilym 65c01d6
fix: omq rpc test
Aerilym 83c2f92
fix: rpc shared config var
Aerilym 1cb7630
fix: perf logger and rpc arg call
Aerilym cfd8aa6
fix: add self logger as non if perf is off
Aerilym e095381
fix: performance logger
Aerilym 4317c28
feat: add median operator fee to network info api endpoint
Aerilym 906328c
feat: add api route to get stakes by sn pubkey
Aerilym aaa27e7
feat: add arbitrum network info and event endpoints
Aerilym 92e0641
fix: change arbiturm provider url to list of urls for later adding of…
Aerilym cd10d49
feat: add rewards fetching and endpoints to fetcher and api
Aerilym e16f1f7
chore: move registration getter api endpoints to main api
Aerilym 7949251
fix: update db schema with arbitrum info and rewards info tables
Aerilym a51fd12
feat: add timestamps to events
Aerilym b8993c1
feat: add node counts to network info
Aerilym 6f4fee3
feat: add node exit list parsing to fetcher
Aerilym e208a27
fix: rewards address parsing
Aerilym 2f41817
fix: add contribution contract api endpoints
Aerilym 0012048
fix: event scanner block range chunk size passed between requests
Aerilym f71a41c
fix: time keeper perf enabled
Aerilym f965034
fix: time keeper perf
Aerilym ca798dc
fix: registration insert sql statement syntax
Aerilym 828c3bb
fix: registration bytes formatting
Aerilym c7d5f4e
fix: overriding in stake list from staging contributors
Aerilym 71ca9be
fix: use eth checksum addresses for api endpoints
Aerilym bf48c5a
feat: add bls key parser
Aerilym c02f36d
feat: create get_arbitrum_events_since_timestamp db reader
Aerilym 540661e
feat: add node_add_timestamp to contribution contracts using arbitrum…
Aerilym c8a7172
feat: create rpc usage tracker
Aerilym 65079d3
chore: simplify oxen rpc to use shared future json method
Aerilym 8c6d5e9
chore: clean up rpc usage logging formatting
Aerilym 0ba118d
fix: add default message to rpc usage
Aerilym c6cf1f8
fix: extend timeout on prc rewards bls request
Aerilym 33542a3
fix: add timeout tracking to rpc usage tracker and log reasons to file
Aerilym 84b7bb2
feat: add contribution contract by sn key api endpoint
Aerilym 705d31a
feat: add service_node_rewards_contract_id_bls_key_map from contract …
Aerilym 293348f
fix: increase timeout times for exit and rewards sig rpc calls
Aerilym f39084e
feat: create db snapshotter
Aerilym 44f1906
fix: request timout in omq
Aerilym 691557e
fix: only allow exit signature requests from exitable nodes and rewar…
Aerilym 9e8354b
feat: add l2 info to network info
Aerilym 27f2873
feat: add contract bls keys to stakes endpoint
Aerilym 85a642a
fix: contract add timestamps and new token addresses
Aerilym d6ee872
fix: handle median node fee when no nodes
Aerilym 2c13ee3
fix: decrease ttl for contribution contracts
Aerilym 963e770
fix: decrease ttl for network info
Aerilym adcdd2c
feat: change arbitrum update loop to use goal refetch time instead of…
Aerilym f9bebd1
feat: add all contracts associated to an address to contribution cont…
Aerilym 62e6af7
chore: adjust cache logic for nodes and registrations
Aerilym 8d86aac
feat: add manual finalize data for contributor contracts and created …
Aerilym 4aa4b23
feat: add reserved slots data to contracts
Aerilym c43b201
feat: add more detailed cache controls to cache manager
Aerilym c365304
feat: create flask rate limiter
Aerilym a852cd4
fix: remove unused contract field in registrations db and enforce uni…
Aerilym 5ff9b39
fix: performance logger orphan cleanup maths
Aerilym e6a2819
chore: add rate limits
Aerilym 82c3e4e
chore: cleanup v1 backend and start scripts
Aerilym 513c93a
feat: convert flask scripts into contained apps with parent dir runners
Aerilym 7b47db2
feat: create price fetcher
Aerilym 8e2e201
feat: create new config system for prices and base flask
Aerilym b269162
chore: create token conversion methods and tests
Aerilym 2c739dd
chore: move non route methods to app class in price api
Aerilym a1d9431
fix: abi manager default add to cache
Aerilym 663f42d
fix: change all inner module imports to relative imports
Aerilym b2acb63
fix: abi manager default and coingecko defaults
Aerilym 118f383
fix: add root level package init
Aerilym ad3fdc6
chore: move python code into src folder so it can be used as a packag…
Aerilym 02fb28e
chore: move configs
Aerilym 8587905
fix: make db readers read only
Aerilym ae65c66
fix: use relative imports for src
Aerilym 97361cb
fix: change packages to use relative imports to themselves
Aerilym 022a210
fix: only require uwsgi for price fetcher if timer is active
Aerilym 57bebdd
fix: leading slash on db file names
Aerilym 6f2b566
fix: add disable db file rewrite option
Aerilym 8a13b8d
fix: update most recent price fetcher
Aerilym b2d3018
fix: cache getters on no item
Aerilym 20410e9
fix: cache ttl and invalidation defaults
Aerilym 53ad6f0
fix: db read uri
Aerilym 06d7d87
fix: change server timestamp to int
Aerilym a7b0e76
fix: raw transaction old version support
Aerilym 0d9ffd0
feat: create cache tests
Aerilym 19653f1
fix: staking api config
Aerilym fe6fd00
fix: abi manager cache
Aerilym 71a225a
fix: fetcher runner
Aerilym 109b98f
fix: show reserved slots for non-contributed contracts
Aerilym bee4a2b
fix: module resolution for registration and snapshot apps
Aerilym df6361f
fix: make default immutable block height 0
Aerilym b52cfb2
fix: make immutable block height 0 if None
Aerilym 419a637
fix: mutate immutable block height 0 if None
Aerilym afcf941
fix: use get for immutable block height 0 if None
Aerilym d6d3f7b
fix: recreate network class on immutable 0
Aerilym 6b767cf
fix: add defaults to oxen rpc network info
Aerilym 167713a
fix: default config db schemas
Aerilym f3d0540
fix: add defaults for all net info fields
Aerilym 3101955
Merge pull request #5 from session-foundation/price_api
Aerilym 1fc42b2
fix: update db snapshot task with new config
Aerilym f1ce6dd
fix: update default config and config validator
Aerilym 2e9b5d9
chore: remove unused config items
Aerilym ae4524b
chore: update abis
Aerilym a6755e7
feat: compile smart contracts from source
Aerilym a722604
feat: create websockets arbitrum event scanner
Aerilym d538fdc
feat: add vesting support and updated event support to staking backend
Aerilym c67f4f1
feat: add vesting support and updated event support to staking backend
Aerilym eb00b5d
Merge pull request #6 from session-foundation/price_api
Aerilym 3df7206
Merge remote-tracking branch 'origin/main' into backend_v2
Aerilym c1451e4
fix: rework price api to simplify token fetching behaviour
Aerilym 0c75a79
fix: add db read mode utils
Aerilym aaa1555
feat: add ws contract classes
Aerilym ad32a25
fix: truncate price stale time
Aerilym e6decaa
feat: add precision to coingecko api
Aerilym d274c55
feat: add dynamic price cache management to price api
Aerilym 485394c
wip: to clean
Aerilym 2f1b496
Update readme and requirements with latest dependencies
Doy-lee aab080d
fix: update token contracts submodule to use the foundation repo
Aerilym 1050b82
fix: update requirements.txt with oxenmq, oxenc, and web3 requirements
Aerilym 66b2135
chore: update config_defaults.py with mainnet values
Aerilym f69b82d
feat: add daily rolling rewards endpoint
Aerilym bcf7848
feat: add block cap and getLogs chunking to event scanner and new hea…
Aerilym ef46433
chore: add utility setup scripts
Aerilym 195ff24
feat: add price range endpoint
Aerilym 8ea7c6e
Merge pull request #7 from session-foundation/fix/limits
Aerilym 2113bba
Merge pull request #8 from session-foundation/feat/price_ranges_api
Aerilym 04127bc
fix: seeded nodes in fetcher
Aerilym 2ac2091
fix: seed node pubkey arg
Aerilym ed129c4
fix: seed node bls pubkey arg
Aerilym 4ccd968
fix: add and use fetched time for stale time for token prices
Aerilym 92b9745
fix: add network mock validation for registrations
Aerilym 0ecc93f
fix: combine new service nodes with seeded service nodes and handle l…
Aerilym 3e2104f
fix: multicontributor contract bootstrapping
Aerilym b9126b9
fix: checksum vesting contract beneficiary addresses
Aerilym 5ee40d2
Merge pull request #9 from session-foundation/fix/limits
Aerilym 7968e29
fix: sort arbitrum events in db call
Aerilym 72a4a7f
feat: add hardfork info and contract nodes endpoints
Aerilym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/oxen-io/eth-sn-contracts.git | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# SENT Staking Backend | ||
# Session Staking Backend | ||
|
||
## Running the backend | ||
|
||
|
@@ -8,6 +8,7 @@ The `liboxenc-dev` and `liboxenmq-dev` packages require the development headers | |
[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**: | ||
|
||
```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 | ||
|
@@ -20,19 +21,40 @@ Instructions available at: | |
- [oxen-pyoxenc](https://github.com/oxen-io/oxen-pyoxenc) | ||
- [oxen-pyoxenmq](https://github.com/oxen-io/oxen-pyoxenmq) | ||
|
||
### Structure | ||
|
||
The backend is split into three parts: | ||
|
||
- **Fetcher**: `fetcher.py` is the main server that handles all the fetching, processing, and main database writing. | ||
- **Api**: `api.py` is the main API server that handles most requests. | ||
|
||
- **Registrations API**: `api_registrations.py` is the registration API server that handles all registration requests | ||
and registration database management. | ||
|
||
You can just run whichever service you want, but the intended usage is to run all three: | ||
|
||
- The fetcher will create and update the main database with network, node, contract, and arbitrum information. | ||
- The API is purely read-only and is a glorified wrapper for the main database with caching. | ||
- The registration API is used to store and retrieve registration information for nodes. | ||
|
||
### 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 Fetcher | ||
|
||
The fetcher is a pure python script that runs in a loop and fetches data from the smart contracts and the oxend RPC. You | ||
can simply run it with `python3 fetcher.py`. | ||
|
||
### Running the API | ||
|
||
It's possible to run the API in flask directly, but you'll want to use uwsgi in production. Both methods are detailed | ||
below: | ||
|
||
FLASK_APP=sent flask run --reload --debugger | ||
uwsgi --http 127.0.0.1:5000 --master -p 4 -w sent --callable app | ||
uwsgi --http 127.0.0.1:5000 --master -p 4 -w api --callable app | ||
|
||
You may optionally append `--fs-reload sent.py` to the `uwsgi` invocation to | ||
automatically restart the server when `sent.py` is modified. | ||
You may optionally append `--fs-reload api.py` to the `uwsgi` invocation to | ||
automatically restart the server when `api.py` is modified. | ||
|
||
After the server is running, visit `127.0.0.1:5000/info` to verify that the server is up and | ||
responding correctly with a payload like the following: | ||
|
@@ -53,6 +75,10 @@ responding correctly with a payload like the following: | |
} | ||
``` | ||
|
||
### Running the Registrations API | ||
|
||
**Follow the same instructions as the API above. Replacing `api` with `registrations` in the commands.** | ||
|
||
## Setting up an oxend instance | ||
|
||
The default configuration for mainnet.py, testnet.py, devnet.py look for mainnet.sock, testnet.sock, | ||
|
@@ -63,7 +89,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 | ||
|
@@ -75,7 +101,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. | ||
|
@@ -89,14 +115,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). | ||
|
||
|
@@ -106,3 +132,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. | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be updated to the
session-foundation
https://github.com/session-foundation/session-token-contracts