Skip to content

Commit

Permalink
fix: sentinal update (#297)
Browse files Browse the repository at this point in the history
* chore: update provider

* chore: subscribe mod provider and bond provider events

* fix: logging in handling events

* chore: add unit tests

* chore: code lint

* chore: update changelog

* chore: update proxies

* chore: update docs

* fix: websocket client connection issue

* chore: update changelog

* fix: update provider storage

* chore: update docs

* fix: update regression tests

* fix: provider mod event parsing

* docs: update readme

* docs: add sentinel setup docs

* chore: update changelog

* chore: update docs
  • Loading branch information
shreyasbhat0 authored Nov 5, 2024
1 parent deb1b73 commit e4d1901
Show file tree
Hide file tree
Showing 17 changed files with 546 additions and 34 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ Contains bug fixes.
Contains all the PRs that improved the code without changing the behaviors.
-->

# v1.0.3-Prerelease

## Added
- Added sentinel setup docs

## Changed
- Updated sentinel to handle provider events

## Fixed
- Fixed code lint
- Fixed ws client issue with event stream

# v1.0.2-Prerelease

## Added
Expand Down
8 changes: 7 additions & 1 deletion cmd/sentinel/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"

"github.com/arkeonetwork/arkeo/app"
"github.com/arkeonetwork/arkeo/common/cosmos"
"github.com/arkeonetwork/arkeo/sentinel"
Expand All @@ -12,6 +14,10 @@ func main() {
c.SetBech32PrefixForAccount(app.AccountAddressPrefix, app.AccountAddressPrefix+"pub")

config := conf.NewConfiguration()
proxy := sentinel.NewProxy(config)
proxy, err := sentinel.NewProxy(config)
if err != nil {
fmt.Println(err)
return
}
proxy.Run()
}
3 changes: 2 additions & 1 deletion directory/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ func TestDownloadProviderMetadata(t *testing.T) {
if err != nil {
t.FailNow()
}

// nolint:staticcheck
if metadata == nil {
t.FailNow()
}

// nolint:staticcheck
if metadata.Version == "" {
t.FailNow()
}
Expand Down
133 changes: 133 additions & 0 deletions docs/SENTINEL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# 🛠️ Setting Up Sentinel

## 🌟 Becoming a Provider

### 🪙 Create a Wallet Account for the Provider

To create a wallet account for the provider, run the following command:

```shell
arkeod add <provider-wallet-account> --keyring-backend test
```

### 🔍 Get the Provider Public Key

Retrieve the provider's public key with:

```bash
arkeod show <provider-wallet-account> -p --keyring-backend test | jq -r .key
```

Convert the result to Bech32 format:

```bash
arkeod debug pubkey-raw <result-from-above-command> | grep "Bech32 Acc" | awk '{ print $NF }'
```

> **ℹ️ Note:** Request tokens from the faucet to bond the provider in the relevant 💬 Discord channel.
### 🤝 Bond the Provider

Bond your provider by executing the following command:

```shell
arkeod tx arkeo bond-provider <provider-pubkey> <service-providing> <bond-amount> --from <provider-wallet> --keyring-backend 🧪 --fees 20uarkeo
```

## 🚀 Starting the Sentinel Service

### 🛠️ Build the Sentinel Binary

Compile the Sentinel binary by running:

```bash
TAG=testnet make install
```

### ⚙️ Set Environment Variables

Configure the environment variables as follows:

```bash
NET="testnet" \
MONIKER="<your-moniker>" \
WEBSITE="<website-address>" \
DESCRIPTION="<provider description>" \
LOCATION="<location>" \
PORT="<sentinel-port>" \
SOURCE_CHAIN="<arkeo chain address>" \
EVENT_STREAM_HOST="<arkeo event stream host (rpc address)>" \
FREE_RATE_LIMIT=<free tier rate limit> \
FREE_RATE_LIMIT_DURATION="<duration>" \
CLAIM_STORE_LOCATION="~/.arkeo/claims" \
CONTRACT_CONFIG_STORE_LOCATION="~/.arkeo/contract_configs" \
PROVIDER_PUBKEY="<Provider PubKey>" \
PROVIDER_CONFIG_STORE_LOCATION="~/.arkeo/provider"
```

### ▶️ Run Sentinel

Start the Sentinel service by executing:

```bash
sentinel
```

When Sentinel starts, you should see output similar to the following:

```bash
I[2024-10-28|11:58:20.056] Starting Sentinel (reverse proxy)....
Moniker <your-moniker>
Website <website address>
Description <provider description>
Location <location>
Port <sentinel-port>
TLS Certificate
TLS Key
Source Chain <arkeo chain address>
Event Stream Host <arkeo event stream host (rpc address)>
Provider PubKey <Provider Pubkey>
Claim Store Location ~/.arkeo/claims
Contract Config Store Location ~/.arkeo/contract_configs
Free Tier Rate Limit <free tier rate limit> requests per <duration>
Provider Config Store Location ~/.arkeo/provider
I[2024-10-28|11:58:20.057] service start msg="Starting WSEvents service" impl=WSEvents
```

## 📝 Add Provider Metadata

Once the Sentinel service is running, update the provider metadata by running:

```shell
arkeod tx arkeo mod-provider <provider-pubkey> <service> "http://<sentineladdress>/metadata.json" <nonce> <status> <min-contract-duration> <max-contract-duration> <subscription-rates> <pay-as-you-go-rates> <settlement-duration> --from <provider-wallet> --keyring-backend --fees 20uarkeo
```

## Sequence Diagram

```mermaid
sequenceDiagram
participant Provider
participant ARKEO_CLI
participant ARKEO
participant Sentinel
Provider->>ARKEO_CLI: Bond Provider (with bond amount and service)
ARKEO_CLI->>ARKEO: Validate and Execute Transaction
ARKEO-->>ARKEO_CLI: Tx hash returned to user
ARKEO_CLI-->>Provider: Verify Tx hash for success
ARKEO-->>ARKEO_CLI: Tx Result
ARKEO_CLI-->>Provider: Tx Result
Provider->>Sentinel: Starts Sentinel with Provider PubKey
Sentinel-->>Provider: URL for provider metadata and service data
Sentinel->>ARKEO: Listen to Events via Websockets
ARKEO->>Sentinel: Websocket Response
Provider->>ARKEO_CLI: Create Tx Mod Provider (with Sentinel Address)
ARKEO_CLI->>ARKEO: Validate and Execute Transaction
ARKEO-->>ARKEO_CLI: Tx hash
ARKEO-->>ARKEO_CLI: Tx Result
ARKEO_CLI-->>Provider: Verify Tx hash for success
ARKEO_CLI-->>Provider: Tx Result
```
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ ignite chain serve

## Local

Build Binary
Installing Arkeo Binary

```shell
make proto-gen install
make install
```

Run
Expand Down
2 changes: 1 addition & 1 deletion sentinel/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (p Proxy) auth(next http.Handler) http.Handler {

if conf.PerUserRateLimit > 0 {
if ok := p.isRateLimited(contract.Id, remoteAddr, conf.PerUserRateLimit); ok {
http.Error(w, http.StatusText(429), http.StatusTooManyRequests)
http.Error(w, "Too Many Requests", http.StatusTooManyRequests)
return
}
}
Expand Down
6 changes: 4 additions & 2 deletions sentinel/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func TestFreeTier(t *testing.T) {
config := conf.Configuration{
FreeTierRateLimit: 1,
}
proxy := NewProxy(config)
proxy, err := NewProxy(config)
require.NoError(t, err)

remoteAddr := "127.0.0.1:8000"

Expand Down Expand Up @@ -107,7 +108,8 @@ func TestPaidTier(t *testing.T) {
ProviderPubKey: pubkey,
FreeTierRateLimit: 1,
}
proxy := NewProxy(config)
proxy, err := NewProxy(config)
require.NoError(t, err)

contract := types.NewContract(pubkey, common.BTCService, pk)
contract.Height = 5
Expand Down
5 changes: 4 additions & 1 deletion sentinel/conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ type Configuration struct {
Description string `json:"description"`
Location string `json:"location"`
Port string `json:"port"`
SourceChain string `json:"source_chain"` // base url for arceo block chain
SourceChain string `json:"source_chain"` // base url for arkeo block chain
EventStreamHost string `json:"event_stream_host"`
ClaimStoreLocation string `json:"claim_store_location"` // file location where claims are stored
ContractConfigStoreLocation string `json:"contract_config_store_location"` // file location where contract configurations are stored
ProviderConfigStoreLocation string `json:"provider_config_store_location"` // file location where provider configurations are stored
ProviderPubKey common.PubKey `json:"provider_pubkey"`
FreeTierRateLimit int `json:"free_tier_rate_limit"`
TLS TLSConfiguration `json:"tls"`
Expand Down Expand Up @@ -95,6 +96,7 @@ func NewConfiguration() Configuration {
ClaimStoreLocation: loadVarString("CLAIM_STORE_LOCATION"),
ContractConfigStoreLocation: loadVarString("CONTRACT_CONFIG_STORE_LOCATION"),
TLS: NewTLSConfiguration(),
ProviderConfigStoreLocation: loadVarString("PROVIDER_CONFIG_STORE_LOCATION"),
}
}

Expand All @@ -113,5 +115,6 @@ func (c Configuration) Print() {
fmt.Fprintln(writer, "Claim Store Location\t", c.ClaimStoreLocation)
fmt.Fprintln(writer, "Contract Config Store Location\t", c.ContractConfigStoreLocation)
fmt.Fprintln(writer, "Free Tier Rate Limit\t", fmt.Sprintf("%d requests per 1m", c.FreeTierRateLimit))
fmt.Fprintln(writer, "Provider Config Store Location\t", c.ProviderConfigStoreLocation)
writer.Flush()
}
2 changes: 2 additions & 0 deletions sentinel/conf/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestConfiguration(t *testing.T) {
os.Setenv("FREE_RATE_LIMIT", "99")
os.Setenv("CLAIM_STORE_LOCATION", "clammy")
os.Setenv("CONTRACT_CONFIG_STORE_LOCATION", "configy")
os.Setenv("PROVIDER_CONFIG_STORE_LOCATION", "providy")

config := NewConfiguration()

Expand All @@ -32,4 +33,5 @@ func TestConfiguration(t *testing.T) {
require.Equal(t, config.FreeTierRateLimit, 99)
require.Equal(t, config.ClaimStoreLocation, "clammy")
require.Equal(t, config.ContractConfigStoreLocation, "configy")
require.Equal(t, config.ProviderConfigStoreLocation, "providy")
}
Loading

0 comments on commit e4d1901

Please sign in to comment.