From c0ff0ca8fd3eceb884c0050059b8b023bf14a75a Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 3 Sep 2024 17:57:29 +0200 Subject: [PATCH] feat: atlasnet --- .github/ISSUE_TEMPLATE/bug_report.md | 31 ++++++++++ .github/actions/deploy/action.yml | 61 +++++++++++++++++++ .github/actions/release/action.yml | 64 ++++++++++++++++++++ .github/dependabot.yml | 21 +++++++ .github/workflows/auto-approve.yml | 12 ++++ .github/workflows/deploy-app.yml | 29 +++++++++ .github/workflows/main.yml | 24 ++++++++ .github/workflows/pr.yml | 20 +++++++ .gitignore | 3 + Dockerfile | 16 +++++ apiService.go | 71 ++++------------------ config.go | 89 +++++++--------------------- main.go | 79 +++++++----------------- workers.go | 30 +++------- 14 files changed, 345 insertions(+), 205 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/actions/deploy/action.yml create mode 100644 .github/actions/release/action.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/auto-approve.yml create mode 100644 .github/workflows/deploy-app.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pr.yml create mode 100644 Dockerfile diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..e487da6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,31 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '[Bug]' +labels: bug +assignees: ngundotra +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Example Links** + +- [Please provide at least 1 link here](https://explorer.solana.com) + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/actions/deploy/action.yml b/.github/actions/deploy/action.yml new file mode 100644 index 0000000..131d3e2 --- /dev/null +++ b/.github/actions/deploy/action.yml @@ -0,0 +1,61 @@ +name: 'Deploy to Cloud Run' +description: 'Deploys a service or job to Cloud Run with optional immediate execution for jobs' + +inputs: + environment: + required: true + description: 'Deployment environment' + default: 'dev' + repository: + required: true + description: 'Artifact repository' + default: 'artifacts-0' + project-name: + required: true + description: 'Name of the project' + gcp-project-id: + required: true + description: 'Google Cloud Project ID' + app-name: + required: true + description: 'Name of the application' + gcp-auth-key: + required: true + description: 'GCP authentication key' + image-name: + required: true + description: 'Name of the Docker image' + deploy-type: + required: true + default: service + description: 'Type of deployment: "service" or "job"' + execute-immediately: + required: false + default: "false" + description: 'Whether to execute the job immediately after deployment (only for jobs)' + +runs: + using: 'composite' + steps: + - shell: bash + run: echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV" + + - uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ inputs.gcp-auth-key }} + + - uses: google-github-actions/setup-gcloud@v2 + + - uses: google-github-actions/deploy-cloudrun@v2 + with: + project_id: ${{ inputs.gcp-project-id }} + ${{ inputs.deploy-type == 'job' && 'job' || 'service' }}: ${{ inputs.app-name }} + image: us-central1-docker.pkg.dev/${{ inputs.repository }}/${{ inputs.project-name }}/${{ inputs.image-name }}:sha-${{ env.sha_short }} + + - name: Execute Job Immediately + if: inputs.deploy-type == 'job' && inputs.execute-immediately == 'true' + shell: bash + run: | + gcloud run jobs execute ${{ inputs.app-name }} \ + --project ${{ inputs.gcp-project-id }} \ + --region us-central1 diff --git a/.github/actions/release/action.yml b/.github/actions/release/action.yml new file mode 100644 index 0000000..ba92f83 --- /dev/null +++ b/.github/actions/release/action.yml @@ -0,0 +1,64 @@ +name: 'Build and Release Docker image' +description: '' + +inputs: + repository: + required: true + description: '' + default: 'artifacts-0' + project-name: + required: true + description: '' + app-name: + required: true + description: '' + default: '' + gcp-auth-key: + required: true + description: '' + default: '' + +runs: + using: 'composite' + steps: + - uses: mobiledevops/secret-to-file-action@v1 + with: + base64-encoded-secret: ${{ secrets.CONFIG_YAML }} + filename: "config.yaml" + is-executable: false + working-directory: "./" + - uses: mobiledevops/secret-to-file-action@v1 + with: + base64-encoded-secret: ${{ secrets.CONFIG_ATLASNET_YAML }} + filename: "config-atlasnet.yaml" + is-executable: false + working-directory: "./" + - uses: mobiledevops/secret-to-file-action@v1 + with: + base64-encoded-secret: ${{ secrets.ID_JSON }} + filename: "id.json" + is-executable: false + working-directory: "./" + - uses: docker/metadata-action@v5 + id: metadata + with: + images: us-central1-docker.pkg.dev/${{ inputs.repository }}/${{ inputs.project-name }}/${{ inputs.app-name }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + type=sha + type=raw,value=latest,enable={{is_default_branch}} + - uses: docker/login-action@v3 + with: + username: _json_key + password: '${{ inputs.gcp-auth-key }}' + registry: 'us-central1-docker.pkg.dev' + - uses: int128/kaniko-action@v1 + with: + push: true + file: Dockerfile + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} + cache: true diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e5e4020 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +version: 2 +registries: + npmjs: + type: npm-registry + url: https://registry.npmjs.org + token: ${{secrets.NPM_TOKEN}} +updates: + - package-ecosystem: "docker" + directory: "/docker" + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "npm" + registries: + - npmjs + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/auto-approve.yml b/.github/workflows/auto-approve.yml new file mode 100644 index 0000000..dc76b4f --- /dev/null +++ b/.github/workflows/auto-approve.yml @@ -0,0 +1,12 @@ +name: Auto approve + +on: pull_request_target + +jobs: + auto-approve: + runs-on: ubuntu-latest + permissions: + pull-requests: write + if: github.actor == 'dependabot[bot]' + steps: + - uses: hmarr/auto-approve-action@v4 diff --git a/.github/workflows/deploy-app.yml b/.github/workflows/deploy-app.yml new file mode 100644 index 0000000..decdd19 --- /dev/null +++ b/.github/workflows/deploy-app.yml @@ -0,0 +1,29 @@ +name: deploy + +on: + workflow_call: + inputs: + environment: + required: true + type: string + secrets: + GCP_AUTH_KEY: + required: true +jobs: + + + deploy-ping: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/deploy + with: + deploy-type: service + environment: ${{ inputs.environment }} + gcp-project-id: fuzzy-lemur-${{ inputs.environment }} + gcp-auth-key: ${{ secrets.GCP_AUTH_KEY }} + repository: "artifacts-0" + project-name: "atlasnet" + app-name: "ping-api" + image-name: "ping" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0a3a60e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,24 @@ +name: deploy + +on: + push: + branches: [ 'main' ] + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/release + with: + repository: "artifacts-0" + project-name: "atlasnet" + app-name: "ping" + gcp-auth-key: ${{ secrets.GCP_AUTH_KEY }} + + deploy-test: + needs: [ release ] + uses: ./.github/workflows/deploy-app.yml + with: + environment: 'test' + secrets: inherit diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..9a8b850 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,20 @@ +name: build-lint-test + +on: + merge_group: + pull_request: + branches: ['main'] + types: [synchronize, opened, reopened] + +jobs: + + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/release + with: + repository: 'artifacts-0' + project-name: 'atlasnet' + app-name: 'ping' + gcp-auth-key: ${{ secrets.GCP_AUTH_KEY }} diff --git a/.gitignore b/.gitignore index 1a995f3..d4c4408 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ config-devnet.yaml # Go workspace file go.work.* +id.json +config-atlasnet.yaml +.idea/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..abc7d08 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.22 AS builder +WORKDIR /workspace +COPY . . +RUN go build -o app . + +FROM debian:latest +RUN \ + apt-get update && \ + apt-get install ca-certificates curl vim -y +WORKDIR /workspace +COPY --from=builder /workspace/app . +COPY --from=builder /workspace/config.yaml . +COPY --from=builder /workspace/config-atlasnet.yaml . +COPY --from=builder /workspace/id.json . + +CMD ["./app"] diff --git a/apiService.go b/apiService.go index a233dd3..31f0c51 100644 --- a/apiService.go +++ b/apiService.go @@ -51,59 +51,14 @@ func APIService(c ClustersToRun) { } // Single Cluster or all Cluster switch c { - case RunMainnetBeta: - if config.Mainnet.APIServer.Enabled { - go runCluster(config.Mainnet.APIServer.Mode, - config.Mainnet.APIServer.IP, - config.Mainnet.APIServer.SSLIP, - config.Mainnet.APIServer.KeyPath, - config.Mainnet.APIServer.CrtPath) - log.Println("--- API Server Mainnet Start--- ") - } - - case RunTestnet: - if config.Testnet.APIServer.Enabled { - go runCluster(config.Testnet.APIServer.Mode, - config.Testnet.APIServer.IP, - config.Testnet.APIServer.SSLIP, - config.Testnet.APIServer.KeyPath, - config.Testnet.APIServer.CrtPath) - log.Println("--- API Server Testnet Start--- ") - } - - case RunDevnet: - if config.Devnet.APIServer.Enabled { - go runCluster(config.Devnet.APIServer.Mode, - config.Devnet.APIServer.IP, - config.Devnet.APIServer.SSLIP, - config.Devnet.APIServer.KeyPath, - config.Devnet.APIServer.CrtPath) - log.Println("--- API Server Devnet Start--- ") - } - case RunAllClusters: - if config.Mainnet.APIServer.Enabled { - go runCluster(config.Mainnet.APIServer.Mode, - config.Mainnet.APIServer.IP, - config.Mainnet.APIServer.SSLIP, - config.Mainnet.APIServer.KeyPath, - config.Mainnet.APIServer.CrtPath) - log.Println("--- API Server Mainnet Start--- ") - } - if config.Testnet.APIServer.Enabled { - go runCluster(config.Testnet.APIServer.Mode, - config.Testnet.APIServer.IP, - config.Testnet.APIServer.SSLIP, - config.Testnet.APIServer.KeyPath, - config.Testnet.APIServer.CrtPath) - log.Println("--- API Server Testnet Start--- ") - } - if config.Devnet.APIServer.Enabled { - go runCluster(config.Devnet.APIServer.Mode, - config.Devnet.APIServer.IP, - config.Devnet.APIServer.SSLIP, - config.Devnet.APIServer.KeyPath, - config.Devnet.APIServer.CrtPath) - log.Println("--- API Server Devnet Start--- ") + case RunAtlasnet: + if config.Atlasnet.APIServer.Enabled { + go runCluster(config.Atlasnet.APIServer.Mode, + config.Atlasnet.APIServer.IP, + config.Atlasnet.APIServer.SSLIP, + config.Atlasnet.APIServer.KeyPath, + config.Atlasnet.APIServer.CrtPath) + log.Println("--- API Server Atlasnet Start--- ") } default: @@ -119,12 +74,8 @@ func getRPCEndpoint(c *gin.Context) { cluster := c.Param("cluster") var e *FailoverEndpoint switch cluster { - case "mainnet-beta": - e = mainnetFailover.GetEndpoint() - case "testnet": - e = testnetFailover.GetEndpoint() - case "devnet": - e = devnetFailover.GetEndpoint() + case "atlasnet": + e = atlasnetFailover.GetEndpoint() default: c.AbortWithStatus(http.StatusNotFound) log.Println("StatusNotFound Error:", cluster) @@ -159,6 +110,8 @@ func last6hours(c *gin.Context) { cluster := c.Param("cluster") var ret []DataPoint1MinResultJSON switch cluster { + case "atlasnet": + ret = GetLast6hours(Atlasnet, HasComputeUnitPrice, 0) case "mainnet-beta": ret = GetLast6hours(MainnetBeta, HasComputeUnitPrice, 0) case "testnet": diff --git a/config.go b/config.go index 7835e47..2e7ca83 100644 --- a/config.go +++ b/config.go @@ -89,13 +89,15 @@ type SolanaCLIConfig struct { } type ClusterCLIConfig struct { - Dir string - MainnetPath string - TestnetPath string - DevnetPath string - ConfigMain SolanaCLIConfig - ConfigTestnet SolanaCLIConfig - ConfigDevnet SolanaCLIConfig + Dir string + MainnetPath string + TestnetPath string + DevnetPath string + AtlasnetPath string + ConfigMain SolanaCLIConfig + ConfigTestnet SolanaCLIConfig + ConfigDevnet SolanaCLIConfig + ConfigAtlasnet SolanaCLIConfig } type RPCEndpoint struct { @@ -131,9 +133,10 @@ type ClusterConfig struct { type Config struct { Database InfluxdbConfig - Mainnet ClusterConfig - Testnet ClusterConfig - Devnet ClusterConfig + Mainnet ClusterConfig + Atlasnet ClusterConfig + Testnet ClusterConfig + Devnet ClusterConfig ClusterCLIConfig Retension } @@ -143,12 +146,8 @@ func loadConfig() Config { // jww.SetStdoutThreshold(jww.LevelTrace) c := Config{} v := viper.New() - userHome, err := os.UserHomeDir() - if err != nil { - panic("loadConfig error:" + err.Error()) - } - v.AddConfigPath(userHome + "/.config/ping-api") + v.AddConfigPath("./") v.SetConfigType("yaml") v.AutomaticEnv() hostname, err := os.Hostname() @@ -183,43 +182,25 @@ func loadConfig() Config { } // setup config.yaml (ClusterConfigFile) c.ClusterCLIConfig = ClusterCLIConfig{ - Dir: v.GetString("SolanaCliFile.Dir"), - MainnetPath: v.GetString("SolanaCliFile.MainnetPath"), - TestnetPath: v.GetString("SolanaCliFile.TestnetPath"), - DevnetPath: v.GetString("SolanaCliFile.DevnetPath"), + Dir: v.GetString("SolanaCliFile.Dir"), + AtlasnetPath: v.GetString("SolanaCliFile.AtlasnetPath"), } - if len(c.ClusterCLIConfig.MainnetPath) > 0 { - sConfig, err := ReadSolanaCLIConfigFile(c.ClusterCLIConfig.Dir + c.ClusterCLIConfig.MainnetPath) - if err != nil { - log.Fatal(err) - } - c.ClusterCLIConfig.ConfigMain = sConfig - } - if len(c.ClusterCLIConfig.TestnetPath) > 0 { - sConfig, err := ReadSolanaCLIConfigFile(c.ClusterCLIConfig.Dir + c.ClusterCLIConfig.TestnetPath) + if len(c.ClusterCLIConfig.AtlasnetPath) > 0 { + sConfig, err := ReadSolanaCLIConfigFile(c.ClusterCLIConfig.Dir + c.ClusterCLIConfig.AtlasnetPath) if err != nil { log.Fatal(err) } - c.ClusterCLIConfig.ConfigTestnet = sConfig - } - if len(c.ClusterCLIConfig.DevnetPath) > 0 { - sConfig, err := ReadSolanaCLIConfigFile(c.ClusterCLIConfig.Dir + c.ClusterCLIConfig.DevnetPath) - if err != nil { - log.Fatal(err) - } - c.ClusterCLIConfig.ConfigDevnet = sConfig + c.ClusterCLIConfig.ConfigAtlasnet = sConfig } // setup config.yaml (SolanaCliFile) all cluster services - configMainnetFile := v.GetString("ClusterConfigFile.Mainnet") - configTestnetFile := v.GetString("ClusterConfigFile.Testnet") - configDevnetFile := v.GetString("ClusterConfigFile.Devnet") + configAtlasnetFile := v.GetString("ClusterConfigFile.Atlasnet") // Read Each Cluster Configurations // setup config.yaml for mainnet - v.SetConfigName(configMainnetFile) + v.SetConfigName(configAtlasnetFile) v.ReadInConfig() - c.Mainnet = ClusterConfig{ - Cluster: MainnetBeta, + c.Atlasnet = ClusterConfig{ + Cluster: Atlasnet, HostName: hostname, ClusterPing: ReadClusterPingConfig(v), } @@ -228,30 +209,6 @@ func loadConfig() Config { c.Mainnet.APIServer.Mode = HTTP log.Println("Mainnet API server mode not support! use default mode") } - v.SetConfigName(configTestnetFile) - v.ReadInConfig() - c.Testnet = ClusterConfig{ - Cluster: Testnet, - HostName: hostname, - ClusterPing: ReadClusterPingConfig(v), - } - if c.Testnet.APIServer.Mode != HTTP && - c.Testnet.APIServer.Mode != HTTPS && c.Testnet.APIServer.Mode != BOTH { - c.Testnet.APIServer.Mode = HTTP - log.Println("Mainnet API server mode not support! use default mode") - } - v.SetConfigName(configDevnetFile) - v.ReadInConfig() - c.Devnet = ClusterConfig{ - Cluster: Devnet, - HostName: hostname, - ClusterPing: ReadClusterPingConfig(v), - } - if c.Devnet.APIServer.Mode != HTTP && - c.Devnet.APIServer.Mode != HTTPS && c.Devnet.APIServer.Mode != BOTH { - c.Devnet.APIServer.Mode = HTTP - log.Println("Devnet API server mode not support! use default mode") - } return c } diff --git a/main.go b/main.go index 7bf1934..25dfab4 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,9 @@ package main import ( "flag" "log" - "strings" "time" _ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres" - "github.com/blocto/solana-go-sdk/rpc" "gorm.io/driver/postgres" "gorm.io/gorm" ) @@ -28,18 +26,18 @@ const ( MainnetBeta Cluster = "MainnetBeta" Testnet = "Testnet" Devnet = "Devnet" + Atlasnet = "Atlasnet" ) var influxdb *InfluxdbClient var userInputClusterMode string -var mainnetFailover RPCFailover -var testnetFailover RPCFailover -var devnetFailover RPCFailover +var atlasnetFailover RPCFailover const ( RunMainnetBeta ClustersToRun = "mainnet" RunTestnet = "testnet" RunDevnet = "devnet" + RunAtlasnet = "atlasnet" RunAllClusters = "all" ) @@ -53,27 +51,13 @@ func init() { log.Println("--- //// Retension --- ") log.Println(config.Retension) log.Println("--- //// ClusterCLIConfig--- ") - log.Println("ClusterCLIConfig Mainnet", config.ClusterCLIConfig.ConfigMain) - log.Println("ClusterCLIConfig Testnet", config.ClusterCLIConfig.ConfigTestnet) - log.Println("ClusterCLIConfig Devnet", config.ClusterCLIConfig.ConfigDevnet) - log.Println("--- Mainnet Ping --- ") - log.Println("Mainnet.ClusterPing.APIServer", config.Mainnet.ClusterPing.APIServer) - log.Println("Mainnet.ClusterPing.PingServiceEnabled", config.Mainnet.ClusterPing.PingServiceEnabled) - log.Println("Mainnet.ClusterPing.AlternativeEnpoint.HostList", config.Mainnet.ClusterPing.AlternativeEnpoint.HostList) - log.Println("Mainnet.ClusterPing.PingConfig", config.Mainnet.ClusterPing.PingConfig) - log.Println("Mainnet.ClusterPing.Report", config.Mainnet.ClusterPing.Report) - log.Println("--- Testnet Ping --- ") - log.Println("Mainnet.ClusterPing.APIServer", config.Testnet.ClusterPing.APIServer) - log.Println("Mainnet.ClusterPing.PingServiceEnabled", config.Mainnet.ClusterPing.PingServiceEnabled) - log.Println("Testnet.ClusterPing.AlternativeEnpoint.HostList", config.Testnet.ClusterPing.AlternativeEnpoint.HostList) - log.Println("Testnet.ClusterPing.PingConfig", config.Testnet.ClusterPing.PingConfig) - log.Println("Testnet.ClusterPing.Report", config.Testnet.ClusterPing.Report) - log.Println("--- Devnet Ping --- ") - log.Println("Devnet.ClusterPing.APIServer", config.Devnet.ClusterPing.APIServer) - log.Println("Devnet.ClusterPing.Enabled", config.Devnet.ClusterPing.PingServiceEnabled) - log.Println("Devnet.ClusterPing.AlternativeEnpoint.HostList", config.Devnet.ClusterPing.AlternativeEnpoint.HostList) - log.Println("Devnet.ClusterPing.PingConfig", config.Devnet.ClusterPing.PingConfig) - log.Println("Devnet.ClusterPing.Report", config.Devnet.ClusterPing.Report) + log.Println("ClusterCLIConfig Atlasnet", config.ClusterCLIConfig.ConfigAtlasnet) + log.Println("--- Atlasnet Ping --- ") + log.Println("Atlasnet.ClusterPing.APIServer", config.Atlasnet.ClusterPing.APIServer) + log.Println("Atlasnet.ClusterPing.PingServiceEnabled", config.Atlasnet.ClusterPing.PingServiceEnabled) + log.Println("Atlasnet.ClusterPing.AlternativeEnpoint.HostList", config.Atlasnet.ClusterPing.AlternativeEnpoint.HostList) + log.Println("Atlasnet.ClusterPing.PingConfig", config.Atlasnet.ClusterPing.PingConfig) + log.Println("Atlasnet.ClusterPing.Report", config.Atlasnet.ClusterPing.Report) log.Println(" *** Config End *** ") @@ -99,36 +83,25 @@ func init() { } database = gormDB } + err := database.AutoMigrate(&PingResult{}) + if err != nil { + log.Printf("Failed to auto migrate: %v", err) + } log.Println("database connected") if config.InfluxdbConfig.Enabled { influxdb = NewInfluxdbClient(config.InfluxdbConfig) } /// ---- Start RPC Failover --- log.Println("RPC Endpoint Failover Setting ---") - if len(config.Mainnet.AlternativeEnpoint.HostList) <= 0 { - mainnetFailover = NewRPCFailover([]RPCEndpoint{{ - Endpoint: rpc.MainnetRPCEndpoint, + if len(config.Atlasnet.AlternativeEnpoint.HostList) <= 0 { + atlasnetFailover = NewRPCFailover([]RPCEndpoint{{ + Endpoint: "https://api.atlasnet.staratlas.cloud", Piority: 1, MaxRetry: 30}}) } else { - mainnetFailover = NewRPCFailover(config.Mainnet.AlternativeEnpoint.HostList) - } - if len(config.Testnet.AlternativeEnpoint.HostList) <= 0 { - testnetFailover = NewRPCFailover([]RPCEndpoint{{ - Endpoint: rpc.MainnetRPCEndpoint, - Piority: 1, - MaxRetry: 30}}) - } else { - testnetFailover = NewRPCFailover(config.Testnet.AlternativeEnpoint.HostList) - } - if len(config.Devnet.AlternativeEnpoint.HostList) <= 0 { - devnetFailover = NewRPCFailover([]RPCEndpoint{{ - Endpoint: rpc.MainnetRPCEndpoint, - Piority: 1, - MaxRetry: 30}}) - } else { - devnetFailover = NewRPCFailover(config.Devnet.AlternativeEnpoint.HostList) + atlasnetFailover = NewRPCFailover(config.Atlasnet.AlternativeEnpoint.HostList) } + } func main() { @@ -138,23 +111,15 @@ func main() { } if database != nil { sqldb, err := database.DB() + if err == nil { sqldb.Close() } } }() flag.Parse() - clustersToRun := flag.Arg(0) - if !(strings.Compare(clustersToRun, string(RunMainnetBeta)) == 0 || - strings.Compare(clustersToRun, string(RunTestnet)) == 0 || - strings.Compare(clustersToRun, string(RunDevnet)) == 0 || - strings.Compare(clustersToRun, string(RunAllClusters)) == 0) { - go launchWorkers(RunMainnetBeta) - go APIService(RunMainnetBeta) - } else { - go launchWorkers(ClustersToRun(clustersToRun)) - go APIService(ClustersToRun(clustersToRun)) - } + go launchWorkers(RunAtlasnet) + go APIService(RunAtlasnet) for { time.Sleep(10 * time.Second) diff --git a/workers.go b/workers.go index 82227b5..0d37d8c 100644 --- a/workers.go +++ b/workers.go @@ -40,6 +40,8 @@ func launchWorkers(c ClustersToRun) { } // Single Cluster or all Cluster switch c { + case RunAtlasnet: + runCluster(config.Atlasnet) case RunMainnetBeta: runCluster(config.Mainnet) case RunTestnet: @@ -68,27 +70,13 @@ func pingDataWorker(cConf ClusterConfig, workerNum int) { var acct types.Account switch cConf.Cluster { - case MainnetBeta: - failover = mainnetFailover - clusterAcct, err := getConfigKeyPair(config.ClusterCLIConfig.ConfigMain) + case Atlasnet: + failover = atlasnetFailover + clusterAcct, err := getConfigKeyPair(config.ClusterCLIConfig.ConfigAtlasnet) if err != nil { log.Panic("getConfigKeyPair Error") } acct = clusterAcct - case Testnet: - failover = testnetFailover - clusterAcct, err := getConfigKeyPair(config.ClusterCLIConfig.ConfigTestnet) - if err != nil { - log.Panic("Testnet getConfigKeyPair Error") - } - acct = clusterAcct - case Devnet: - failover = devnetFailover - clusterAcct, err := getConfigKeyPair(config.ClusterCLIConfig.ConfigDevnet) - if err != nil { - log.Panic("Devnet getConfigKeyPair Error") - } - acct = clusterAcct default: panic(ErrInvalidCluster) } @@ -177,12 +165,8 @@ func reportWorker(cConf ClusterConfig) { toSendAlert bool, alertTrigger AlertTrigger, messageMemo string) { var accessToken string switch cConf.Cluster { - case MainnetBeta: - accessToken = mainnetFailover.GetEndpoint().AccessToken - case Testnet: - accessToken = testnetFailover.GetEndpoint().AccessToken - case Devnet: - accessToken = devnetFailover.GetEndpoint().AccessToken + case Atlasnet: + accessToken = atlasnetFailover.GetEndpoint().AccessToken default: panic(fmt.Sprintf("%s:%s", "no such cluster", cConf.Cluster)) }