Skip to content

Commit

Permalink
feat: add node registeration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Nov 16, 2023
1 parent 815a4d9 commit 71d8bda
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ var command = cobra.Command{
return fmt.Errorf("setup config file: %w", err)
}

server, err := node.NewServer(config.Node)
server, err := node.NewServer(config.Config.Node)
if err != nil {
return fmt.Errorf("build node server: %w", err)
}

return server.Run(cmd.Context())
return server.Run(cmd.Context(), *config)
},
}

Expand Down
130 changes: 125 additions & 5 deletions deploy/config.development.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,125 @@
environment: development
node:
network: arweave
chain: mainnet
endpoint: https://ethereum.blockpi.network/v1/rpc/public
discovery:
version: "1.0.0" # version of your RSS3 node
maintainer:
owner_evm_address: "0x123" # address to receive network incentivization and ownership verification
signature: "hello_world" # signature of the above address
website: "https://abc.com/rss3-node" # link to your website
# public_endpoint is how the Global Indexer reaches your RSS3 node
# a domain name is recommended but not required, you can use an IP address+port as well
node:
endpoint: "https://rss3.abc.com/"
access_key: "access_key"

config:
hub:
endpoint: "https://hub.abc.com/"
environment: "development" # set to "production" when you are ready to go live
node:
network: arweave
chain: mainnet
endpoint: https://ethereum.blockpi.network/v1/rpc/public
# the following config is for your RSS3 node to operate on data
data:
database:
type: "CockroachDB"
external: true # if set to true, the automated deployment process will not sprint up a database container.
host: "pg.abc.com"
port: 5432
username: "username"
password: "password"
database_name: "abc"

redis:
external: true
host: "redis.abc.com"
port: 6379
password: "password"
database_name: 1 # redis database index

object_storage:
external: true
type: "s3"
endpoint:
private:
public:
bucket:
credential:
id:
secret:
# the following config is for your RSS3 node to spring up components
component:
data:
indexer_module: # leave it empty to disable individual module here
decentralized:
network: # list all the supported networks here, see: https://docs.rss3.io/docs/supported-networks
indexer:
# fallback is a special indexer that stores all on-chain transctions
# that are not handled by other indexersinto database.
# when enabled, a CockroachDB is required.
- type: fallback
args:
- chain_id: "0x01,0x137" # 或者用下面的格式

- type: app_uniswap
args:
- chain_id: ["0x01","0x137"]

- type: app_snapshot
args:
- api_key: "12345678"
- upstream_endpoint: "https://snapshot.app/graphql"

- type: app_mirror
args:
- upstream_endpoint: "https://arweave-gateway.abc.com/"
depends_on:
storage:
- "arweave_storage_1"

- type: app_farcaster
args:
- upstream_endpoint: "https://farcaster-hub.abc.com/"

storage: # storage used by applications, indexers may require read-only access to retrieve data
- id: "ipfs_storage_1"
upstream_endpoint: "https://ipfs-gateway.abc.com/" # your IPFS gateway endpoint

- id: "arweave_storage_1"
upstream_endpoint: "https://arweave-gateway.abc.com/" # your Arweave gateway endpoint

RSS:
# RSSHub is the only supported RSS module for now
# as RSSHub is an external dependency, you need to make sure:
# 1. the instance must be accessible by your RSS3 node itself
# 2. certain APIs must be accessible by the Global Indexer:
# 2.1 /api/routes # TBD
# 2.2 /api/config # TBD
RSSHub:
# instance_url stands for the RSSHub instance you are running
instance_url: "https://rsshub.abc.com/"
# proper authentication is highly recommended to protect your RSSHub instance
# choose an authentication method: basic auth using username/password
# or query string auth using access_key
# make sure it's always accessible by your RSS3 node
# see: https://docs.rsshub.app/install/#user-authentication-configurations
authentication:
username: "username"
password: "password"
access_key: "access_key"

federated: # leave blank for now

search: # leave blank for now

observability:
opentelemetry:
# leave blank to disable individual signal here
# see: https://opentelemetry.io/
metrics:
endpoint: "https://opentelemetry.abc.com/metrics"

logs:
endpoint: "https://opentelemetry.abc.com/logs"

traces:
endpoint: "https://opentelemetry.abc.com/traces"
181 changes: 178 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,190 @@ import (
)

const (
Environment = "environment"
Environment = "config.environment"

EnvironmentDevelopment = "development"
EnvironmentProduction = "production"
)

// Config represents the top-level configuration structure.
type File struct {
Environment string `mapstructure:"environment"`
Node *engine.Config `mapstructure:"node"`
Discovery Discovery `mapstructure:"discovery"`
Config Config `mapstructure:"config"`
Observability Observability `mapstructure:"observability"`
}

// Discovery represents the discovery configuration.
type Discovery struct {
Version string `mapstructure:"version"`
Maintainer Maintainer `mapstructure:"maintainer"`
Node NodeConfig `mapstructure:"node"`
}

// Maintainer holds maintainer specific configuration.
type Maintainer struct {
OwnerEVMAddress string `mapstructure:"owner_evm_address"`
Signature string `mapstructure:"signature"`
Website string `mapstructure:"website"`
}

// NodeConfig holds node specific configuration.
type NodeConfig struct {
Endpoint string `mapstructure:"endpoint"`
AccessKey string `mapstructure:"access_key"`
}

// Config holds application level configuration.
type Config struct {
Environment string `mapstructure:"environment"`
Hub HubConfig `mapstructure:"hub"`
Node *engine.Config `mapstructure:"node"`
Data DataConfig `mapstructure:"data"`
Component ComponentConfig `mapstructure:"component"`
}

type HubConfig struct {
Endpoint string `mapstructure:"endpoint"`
}

// DataConfig holds data related configuration.
type DataConfig struct {
Database DatabaseConfig `mapstructure:"database"`
Redis RedisConfig `mapstructure:"redis"`
ObjectStorage ObjectStorageConfig `mapstructure:"object_storage"`
}

// DatabaseConfig holds database configuration.
type DatabaseConfig struct {
Type string `mapstructure:"type"`
External bool `mapstructure:"external"`
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
DatabaseName string `mapstructure:"database_name"`
}

// RedisConfig holds Redis configuration.
type RedisConfig struct {
External bool `mapstructure:"external"`
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Password string `mapstructure:"password"`
DatabaseName int `mapstructure:"database_name"`
}

// ObjectStorageConfig holds object storage configuration.
type ObjectStorageConfig struct {
External bool `mapstructure:"external"`
Type string `mapstructure:"type"`
Endpoint EndpointConfig `mapstructure:"endpoint"`
Bucket string `mapstructure:"bucket"`
Credential CredentialConfig `mapstructure:"credential"`
}

// EndpointConfig holds endpoints for object storage.
type EndpointConfig struct {
Private string `mapstructure:"private"`
Public string `mapstructure:"public"`
}

// CredentialConfig holds credentials for object storage.
type CredentialConfig struct {
ID string `mapstructure:"id"`
Secret string `mapstructure:"secret"`
}

// ComponentConfig holds component configuration.
type ComponentConfig struct {
Data DataComponentConfig `mapstructure:"data"`
Search interface{} `mapstructure:"search"`
}

// DataComponentConfig holds data component configuration.
type DataComponentConfig struct {
IndexerModule IndexerModuleConfig `mapstructure:"indexer_module"`
}

// IndexerModuleConfig holds indexer module configuration.
type IndexerModuleConfig struct {
Decentralized DecentralizedConfig `mapstructure:"decentralized"`
RSS RSSConfig `mapstructure:"RSS"`
Federated interface{} `mapstructure:"federated"`
}

// DecentralizedConfig holds decentralized configuration.
type DecentralizedConfig struct {
Network NetworkConfig `mapstructure:"network"`
Storage []StorageConfig `mapstructure:"storage"`
}

// NetworkConfig holds network specific configuration.
type NetworkConfig struct {
Indexer []IndexerConfig `mapstructure:"indexer"`
}

// IndexerConfig holds indexer specific configuration.
type IndexerConfig struct {
Type string `mapstructure:"type"`
Args []map[string]interface{} `mapstructure:"args"`
DependsOn DependsOnConfig `mapstructure:"depends_on"`
}

// DependsOnConfig holds dependency information.
type DependsOnConfig struct {
Storage []string `mapstructure:"storage"`
}

// StorageConfig holds storage configuration.
type StorageConfig struct {
ID string `mapstructure:"id"`
UpstreamEndpoint string `mapstructure:"upstream_endpoint"`
}

// RSSConfig holds RSS module configuration.
type RSSConfig struct {
RSSHub RSSHubConfig `mapstructure:"RSSHub"`
}

// RSSHubConfig holds RSSHub specific configuration.
type RSSHubConfig struct {
InstanceURL string `mapstructure:"instance_url"`
Authentication AuthenticationConfig `mapstructure:"authentication"`
}

// AuthenticationConfig holds authentication configuration.
type AuthenticationConfig struct {
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
AccessKey string `mapstructure:"access_key"`
}

// Observability holds observability related configuration.
type Observability struct {
Opentelemetry OpentelemetryConfig `mapstructure:"opentelemetry"`
}

// OpentelemetryConfig holds OpenTelemetry configuration.
type OpentelemetryConfig struct {
Metrics MetricsConfig `mapstructure:"metrics"`
Logs LogsConfig `mapstructure:"logs"`
Traces TracesConfig `mapstructure:"traces"`
}

// MetricsConfig holds metrics configuration.
type MetricsConfig struct {
Endpoint string `mapstructure:"endpoint"`
}

// LogsConfig holds logs configuration.
type LogsConfig struct {
Endpoint string `mapstructure:"endpoint"`
}

// TracesConfig holds traces configuration.
type TracesConfig struct {
Endpoint string `mapstructure:"endpoint"`
}

func Setup(configFilePath string) (*File, error) {
Expand Down
Loading

0 comments on commit 71d8bda

Please sign in to comment.