Skip to content
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

check status of peers in kdf network #25

Merged
merged 20 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ log = "0.4.17"
once_cell = "1.12.0"
url = { version = "2.2.2", features = ["serde"] }
redis = { version = "0.21.5", default-features = false, features = ["tokio-comp"] }
rustc-hash = "1.1.0"
serde = "1.0.137"
serde_json = { version = "1.0.81", features = ["preserve_order", "raw_value"] }
sha3 = "0.9"
Expand Down
47 changes: 17 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ Create the configuration file for app runtime.
"pubkey_path": "/path_to_publick_key.pem",
"privkey_path": "/path_to_private_key.pem",
"redis_connection_string": "redis://localhost",
"kdf_rpc_client": "http://127.0.0.1:7783",
"kdf_rpc_password": "testpass",
"token_expiration_time": 300,
"proxy_routes": [
{
"inbound_route": "/dev",
"outbound_route": "http://localhost:8000",
"proxy_type": "quicknode",
"proxy_type": "quicknode", # available types are: "quicknode", "moralis", "block_pi"
"authorized": false,
"allowed_rpc_methods": [
"eth_blockNumber",
Expand All @@ -42,14 +44,11 @@ Create the configuration file for app runtime.

Expose configuration file's path as an environment variable in `AUTH_APP_CONFIG_PATH`.

***Important Note:*** The environment where the application will be deployed, the timezone MUST be as UTC. Also, make sure redis is version `6.*`
***Important Note:*** The environment where the application will be deployed, the timezone MUST be as UTC. Also, make sure redis is version `7.*`
onur-ozkan marked this conversation as resolved.
Show resolved Hide resolved

### Architecture (TODO: OUTDATED)
### Architecture
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you plz add some intro to the README about how this service is used?
Is it basically for KDF app to access backends (web3, quicknode etc providers)?
Will it be a network of proxies or each KDF peer will have its own proxy locally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you plz add some intro to the README about how this service is used?

Sure.

Is it basically for KDF app to access backends (web3, quicknode etc providers)?

Yes, we use this to hide the keys for our paid services and protect them from misuse. You can take a look on https://gist.github.com/onur-ozkan/725f56c05a2eb01e0428f03191f8da86 for some more context.

Will it be a network of proxies or each KDF peer will have its own proxy locally?

No.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you plz add some intro to the README about how this service is used?

Done that.


![arch2](https://github.com/KomodoPlatform/komodo-defi-proxy/assets/39852038/be7fe7ae-2f2a-4f68-afa8-ce4938c570a7)


**Execution flow (TODO: OUTDATED):**
![2024-09-09_14-09](https://github.com/user-attachments/assets/2775d73e-8003-4bfe-89e1-2c64da9e3004)

1) Client sends the request.

Expand All @@ -58,29 +57,17 @@ Expose configuration file's path as an environment variable in `AUTH_APP_CONFIG_
3) If the incoming request comes from the same network, step 4 will be by-passed.

4) Request Handling in the Middleware:
- **Status Checker**:
- **Blocked**: Return `403 Forbidden`.
- **Allowed**: Process continues with the rate limiter.
- **Trusted**: Bypass rate limiter and proof of funding.

**For Quicknode:**
- **Status Checker**:
- **Blocked**: Return `403 Forbidden` immediately.
- **Allowed**: Process continues with the rate limiter.
- **Trusted**: Bypass rate limiter and proof of funding.

- **Rate Limiter**:
- First, verify the signed message. If not valid, return `401 Unauthorized` immediately.
- If valid, calculate the request count with the time interval specified in the application configuration. If the wallet address has sent too many requests than the expected amount, process continues with the proof of funding. If not, bypass the proof of funding.
- **Peer Status Checker**:
- The requesting peer must be active in the KDF network. Validate this by executing the `peer_connection_healthcheck` KDF RPC. If the peer is not connected to the network, return `401 Unauthorized`.

- **Proof of Funding**:
- Return `406 Not Acceptable` if the wallet has a 0 balance. Otherwise, assume the request is valid and process it as usual.

**For Moralis:**
- **Status Checker**:
- **Blocked**: Return `403 Forbidden` immediately.
- **Allowed**: Process continues with the rate limiter.
- **Trusted**: Bypass the rate limiter.

- **Rate Limiter**:
- First, verify the signed message. If not valid, return `401 Unauthorized` immediately.
- If valid, calculate the request count with the time interval specified in the application configuration. If the wallet address has sent too many requests, return an error `406 Not Acceptable` indicating that the wallet address must wait for some time before making more requests.
- **Rate Limiter**:
- First, verify the signed message. If not valid, return `401 Unauthorized`.
- If valid, calculate the request count with the time interval specified in the application configuration. If the wallet address has sent too many requests than the expected amount, process continues with the proof of funding. If not, bypass the proof of funding.

5) Find target route by requested endpoint.

Expand All @@ -102,7 +89,7 @@ curl -v --url "'$mm2_address'" -s --data '{
"params": {
"ticker": "ETH",
"nodes": [
{"url": "'$atomicdex_gui_auth_address'", "gui_auth": true }
{"url": "'$atomicdex_gui_auth_address'", "komodo_proxy": true }
],
"swap_contract_address": "0x24ABE4c71FC658C91313b6552cd40cD808b3Ea80",
"erc20_tokens_requests": [
Expand Down Expand Up @@ -140,4 +127,4 @@ If you want to test features locally, you can run Docker containers using Docker
4. **Stop the Containers**:
```sh
docker compose down
```
```
2 changes: 2 additions & 0 deletions assets/.config_test
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"port": 6150,
"redis_connection_string": "redis://redis:6379",
"kdf_rpc_client": "http://127.0.0.1:7783",
"kdf_rpc_password": "testpass",
"pubkey_path": "/usr/src/komodo-defi-proxy/assets/.pubkey_test",
"privkey_path": "/usr/src/komodo-defi-proxy/assets/.privkey_test",
"token_expiration_time": 300,
Expand Down
Loading
Loading