From 5bd0a4744c45246fcd880b73f3f6526a64481150 Mon Sep 17 00:00:00 2001 From: Jay Jie Date: Sat, 21 Sep 2024 13:02:02 -0700 Subject: [PATCH 1/5] ci: add golangci-lint --- .github/workflows/lint.yml | 39 ++++++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 6 +++--- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..bd76382 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,39 @@ +name: Lint + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened, labeled] + workflow_dispatch: + +permissions: + contents: read + repository-projects: read + packages: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + golangci-lint: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version-file: go.mod + cache: true + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.56.0 + args: --timeout 10m --tests=false --out-format=github-actions + skip-pkg-cache: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e538b2..6be6e52 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,12 +1,12 @@ ---- name: Tests on: push: branches: - - main + - master pull_request: types: [opened, synchronize, reopened, labeled] + workflow_dispatch: permissions: contents: read @@ -14,7 +14,7 @@ permissions: packages: read concurrency: - group: ci-${{ github.ref }}-tests + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: From b15287b734853504525427806ec4b513dd65a55f Mon Sep 17 00:00:00 2001 From: Jay Jie Date: Sat, 21 Sep 2024 13:09:35 -0700 Subject: [PATCH 2/5] ci: create release only when there's tags --- .github/workflows/ build-and-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ build-and-publish.yml b/.github/workflows/ build-and-publish.yml index c8b7f6a..a06123d 100644 --- a/.github/workflows/ build-and-publish.yml +++ b/.github/workflows/ build-and-publish.yml @@ -79,6 +79,7 @@ jobs: run: echo ${{ steps.docker_build.outputs.digest }} - name: Create GitHub Release + if: startsWith(github.ref, 'refs/tags/') uses: ncipollo/release-action@v1 with: allowUpdates: true From 937a5a051a5dd7e67cd7276861c1b2b722c33c2d Mon Sep 17 00:00:00 2001 From: Jay Jie Date: Sat, 21 Sep 2024 13:29:52 -0700 Subject: [PATCH 3/5] ci: fix lint --- .github/workflows/build-and-publish.yml | 1 + config/main.go | 16 +++++-------- exporter/main.go | 5 +++- main.go | 5 +++- services/akash/akash.go | 32 ++++++++++++++++++------- services/bank.go | 8 +++++-- services/block.go | 8 +++++-- services/consensus.go | 4 +++- services/delegation.go | 6 +++-- services/gov.go | 8 +++++-- services/gravity.go | 28 ++++++++++++++++------ services/ibc.go | 12 ++++++---- services/inflation.go | 4 +++- services/node.go | 4 +++- services/oracle.go | 12 +++++++--- services/slashing.go | 8 +++++-- services/staking.go | 8 +++++-- services/tx.go | 24 ++++++++++++++----- services/upgrade.go | 4 +++- services/validator.go | 16 +++++++++---- types/gravity.go | 5 ---- 21 files changed, 153 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/build-and-publish.yml diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/config/main.go b/config/main.go index c8f9eb0..ea42614 100644 --- a/config/main.go +++ b/config/main.go @@ -146,19 +146,13 @@ func GetLogLevel(lvl string) zapcore.Level { } } -func GetDenomList(chain string, chainList map[string][]string) []string { - var found bool - +func GetDenomList(chain string, chainList map[string][]string) ([]string, error) { for k, v := range chainList { if k == chain { - found = true - return v + return v, nil } } - if !found { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "chain("+chain+") denom not supported")) - } - return []string{} + return []string{}, fmt.Errorf("chain(%s) denom not supported", chain) } func GetChainList() map[string][]string { @@ -171,7 +165,9 @@ func GetChainList() map[string][]string { byteValue, _ := io.ReadAll(jsonFile) var chains []Chain - json.Unmarshal(byteValue, &chains) + if err := json.Unmarshal(byteValue, &chains); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } chainList := make(map[string][]string) for _, chain := range chains { diff --git a/exporter/main.go b/exporter/main.go index 56060dd..9bb10db 100644 --- a/exporter/main.go +++ b/exporter/main.go @@ -18,7 +18,10 @@ func Start(config *config.Config, port string, logger *zap.Logger, restService c } func CollectMetrics(cfg *config.Config, log *zap.Logger, restService controllers.RestServices, rpcService controllers.RpcServices) { - denomList := config.GetDenomList(cfg.Chain.Name, cfg.ChainList) + denomList, err := config.GetDenomList(cfg.Chain.Name, cfg.ChainList) + if err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } registerGauges(denomList) counterVecs := registerLabels() diff --git a/main.go b/main.go index bda0832..0eae17d 100644 --- a/main.go +++ b/main.go @@ -71,7 +71,10 @@ func main() { go dashboard.StartDashboard() } - denomList := config.GetDenomList(cfg.Chain.Name, cfg.ChainList) + denomList, err := config.GetDenomList(cfg.Chain.Name, cfg.ChainList) + if err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // start the data fetcher in a separate thread fetcher.Start(&cfg, restServicesController, rpcServicesController, denomList, logger) diff --git a/services/akash/akash.go b/services/akash/akash.go index b61dabc..781da51 100644 --- a/services/akash/akash.go +++ b/services/akash/akash.go @@ -35,7 +35,9 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &deployments) + if err := json.Unmarshal(res, &deployments); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // get total deployments count totalDeploymentsCount, err := strconv.Atoi(deployments.Pagination.Total) @@ -49,7 +51,9 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(resActive, &activeDeployments) + if err := json.Unmarshal(resActive, &activeDeployments); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } activeDeploymentsCount, err := strconv.Atoi(activeDeployments.Pagination.Total) if err != nil { @@ -74,7 +78,9 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &providers) + if err := json.Unmarshal(res, &providers); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // handle pagination nextKey := providers.Pagination.NextKey @@ -84,7 +90,9 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } var nextPage akash.ProvidersResponse - json.Unmarshal(res, &nextPage) + if err := json.Unmarshal(res, &nextPage); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // append to the response providers.Providers = append(providers.Providers, nextPage.Providers...) @@ -175,7 +183,9 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide if err != nil { return fmt.Errorf("error querying auditors for provider owner: %w", err) } - json.Unmarshal(res, &auditors) + if err := json.Unmarshal(res, &auditors); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // handle pagination nextKey := auditors.Pagination.NextKey @@ -185,7 +195,9 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } var nextPage akash.AuditorsResponse - json.Unmarshal(res, &nextPage) + if err := json.Unmarshal(res, &nextPage); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // append to the response auditors.Providers = append(auditors.Providers, nextPage.Providers...) @@ -259,7 +271,9 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi if err != nil { return fmt.Errorf("error querying deployments for provider owner: %w", err) } - json.Unmarshal(res, &deployments) + if err := json.Unmarshal(res, &deployments); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // handle pagination nextKey := deployments.Pagination.NextKey @@ -269,7 +283,9 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } var nextPage akash.DeploymentsResponse - json.Unmarshal(res, &nextPage) + if err := json.Unmarshal(res, &nextPage); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } // append to the response deployments.Deployments = append(deployments.Deployments, nextPage.Deployments...) diff --git a/services/bank.go b/services/bank.go index 85d5f51..2309a7e 100644 --- a/services/bank.go +++ b/services/bank.go @@ -43,7 +43,9 @@ func (bs *BankService) GetBalanceInfo(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &b) + if err := json.Unmarshal(res, &b); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -61,7 +63,9 @@ func (bs *BankService) GetRewardsCommissionInfo(cfg config.Config, rd *types.RES if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &rc) + if err := json.Unmarshal(res, &rc); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/block.go b/services/block.go index fec32ee..87c9bbb 100644 --- a/services/block.go +++ b/services/block.go @@ -39,7 +39,9 @@ func (bs *BlockService) GetInfo(cfg config.Config) types.Blocks { if err != nil { zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &bs.Block) + if err := json.Unmarshal(res, &bs.Block); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -56,7 +58,9 @@ func (bs *BlockService) GetLastBlockTimestamp(cfg config.Config, currentHeight i if err != nil { zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &lastBlock) + if err := json.Unmarshal(res, &lastBlock); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/consensus.go b/services/consensus.go index e7b42af..bb046a5 100644 --- a/services/consensus.go +++ b/services/consensus.go @@ -30,7 +30,9 @@ func (css *ConsensusService) GetConsensusDump(cfg config.Config, rpc *types.RPCD if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &cs) + if err := json.Unmarshal(res, &cs); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } conspubMonikerMap := rest.GetConspubMonikerMapWrapper() // cs.Result.Validatorset.Validators is already sorted based on voting power diff --git a/services/delegation.go b/services/delegation.go index 7132c1c..e6c0a4f 100644 --- a/services/delegation.go +++ b/services/delegation.go @@ -31,7 +31,9 @@ func (ds *DelegationService) GetInfo(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &delInfo) + if err := json.Unmarshal(res, &delInfo); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -45,7 +47,7 @@ func (ds *DelegationService) GetInfo(cfg config.Config, rd *types.RESTData) { func() { defer func() { if r := recover(); r != nil { - // precommit failure validator + zap.L().Error("", zap.Bool("Success", false), zap.String("err", "failed to get delegation info")) } }() delRes[value.Delegation.DelegatorAddr] = []string{value.Balance.Amount} diff --git a/services/gov.go b/services/gov.go index 7b3dc33..2ced15e 100644 --- a/services/gov.go +++ b/services/gov.go @@ -36,7 +36,9 @@ func (rs *GovService) GetInfo(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &g) + if err := json.Unmarshal(res, &g); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } totalProposals := g.Proposals for _, value := range totalProposals { @@ -60,7 +62,9 @@ func (rs *GovService) GetInfo(cfg config.Config, rd *types.RESTData) { log.Info().Msgf("Error getting vote info: %v", err) zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &voteInfo) + if err := json.Unmarshal(res, &voteInfo); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if voteInfo.Vote.Options[0].Option != "" { inVotingVoted++ } else { diff --git a/services/gravity.go b/services/gravity.go index 4649177..bd6983c 100644 --- a/services/gravity.go +++ b/services/gravity.go @@ -29,7 +29,9 @@ func GetUmeePrice(rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &p) + if err := json.Unmarshal(res, &p); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } rd.GravityInfo.UMEEPrice = p.UMEEPrice } @@ -45,7 +47,9 @@ func (gs *GravityService) GetBatchFees(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &b) + if err := json.Unmarshal(res, &b); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } for _, bf := range b.BatchFees { b.Fees += utils.StringToFloat64(bf.TotalFees) @@ -67,7 +71,9 @@ func (gs *GravityService) GetBatchesFees(cfg config.Config, rd *types.RESTData) if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &b) + if err := json.Unmarshal(res, &b); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } for _, batch := range b.Batches { for _, tx := range batch.Transactions { @@ -92,7 +98,9 @@ func (gs *GravityService) GetBridgeFees(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &p) + if err := json.Unmarshal(res, &p); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } rd.GravityInfo.ETHPrice = p.ETHPrice GetUmeePrice(rd) @@ -112,7 +120,9 @@ func (gs *GravityService) GetBridgeParams(cfg config.Config, rd *types.RESTData) if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, ¶ms) + if err := json.Unmarshal(res, ¶ms); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } rd.GravityInfo.BridgeParams = params.BridgeParams @@ -135,7 +145,9 @@ func (gs *GravityService) GetOracleEventNonce(cfg config.Config, rd *types.RESTD if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &evt) + if err := json.Unmarshal(res, &evt); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } rd.GravityInfo.EventNonce = evt.EventNonce } @@ -153,7 +165,9 @@ func (gs *GravityService) GetValSet(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &vs) + if err := json.Unmarshal(res, &vs); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } for _, member := range vs.ValSet.Members { vsResult[member.ETHAddr] = member.Power diff --git a/services/ibc.go b/services/ibc.go index cc97aea..237a9ba 100644 --- a/services/ibc.go +++ b/services/ibc.go @@ -32,7 +32,9 @@ func (is *IbcService) GetChannelInfo(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &ibcInfo) + if err := json.Unmarshal(res, &ibcInfo); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -45,7 +47,7 @@ func (is *IbcService) GetChannelInfo(cfg config.Config, rd *types.RESTData) { func() { defer func() { if r := recover(); r != nil { - // precommit failure validator + zap.L().Error("", zap.Bool("Success", false), zap.String("err", "failed to get ibc channel info")) } }() ibcChannels[value.ChannelID] = []string{value.State, value.Ordering, value.Counterparty.ChannelID} @@ -70,7 +72,9 @@ func (is *IbcService) GetConnectionInfo(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &ibcInfo) + if err := json.Unmarshal(res, &ibcInfo); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -83,7 +87,7 @@ func (is *IbcService) GetConnectionInfo(cfg config.Config, rd *types.RESTData) { func() { defer func() { if r := recover(); r != nil { - // precommit failure validator + zap.L().Error("", zap.Bool("Success", false), zap.String("err", "failed to get ibc connection info")) } }() ibcConnections[value.ID] = []string{value.State, value.ClientID, value.Counterparty.ConnectionID, value.Counterparty.ClientID} diff --git a/services/inflation.go b/services/inflation.go index b8c763d..a8478e7 100644 --- a/services/inflation.go +++ b/services/inflation.go @@ -37,7 +37,9 @@ func (is *InflationService) GetInfo(cfg config.Config, rd *types.RESTData) { return } - json.Unmarshal(res, &i) + if err := json.Unmarshal(res, &i); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/node.go b/services/node.go index 425dd7b..668b848 100644 --- a/services/node.go +++ b/services/node.go @@ -30,7 +30,9 @@ func (ns *NodeService) GetInfo(cfg *config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &nodeInfo) + if err := json.Unmarshal(res, &nodeInfo); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/oracle.go b/services/oracle.go index f2eb2a7..938d037 100644 --- a/services/oracle.go +++ b/services/oracle.go @@ -30,7 +30,9 @@ func (os *OracleService) GetMissedCounterInfoByValidator(cfg config.Config, rd * if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &ms) + if err := json.Unmarshal(res, &ms); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -49,7 +51,9 @@ func (os *OracleService) GetPrevoteInfoByValidator(cfg config.Config, rd *types. if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &pv) + if err := json.Unmarshal(res, &pv); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Warn("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -68,7 +72,9 @@ func (os *OracleService) GetVoteInfoByValidator(cfg config.Config, rd *types.RES if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &v) + if err := json.Unmarshal(res, &v); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Warn("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/slashing.go b/services/slashing.go index 009e289..893e7c8 100644 --- a/services/slashing.go +++ b/services/slashing.go @@ -36,7 +36,9 @@ func (ss *SlashingService) GetSlashingParams(cfg config.Config, rd *types.RESTDa if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &d) + if err := json.Unmarshal(res, &d); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -53,7 +55,9 @@ func (ss *SlashingService) GetSigningInfo(cfg config.Config, consAddr string, rd if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &d) + if err := json.Unmarshal(res, &d); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/staking.go b/services/staking.go index cef957a..e5eaed0 100644 --- a/services/staking.go +++ b/services/staking.go @@ -29,7 +29,9 @@ func (ss *StakingService) GetInfo(cfg config.Config, denom string, rd *types.RES if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "Failed to connect to REST-Server")) } - json.Unmarshal(res, &sp) + if err := json.Unmarshal(res, &sp); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else { @@ -48,7 +50,9 @@ func (ss *StakingService) getTotalSupply(cfg config.Config, denom string, log *z if err != nil { log.Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &ts) + if err := json.Unmarshal(res, &ts); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { log.Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/tx.go b/services/tx.go index caa460b..9d16d10 100644 --- a/services/tx.go +++ b/services/tx.go @@ -100,7 +100,9 @@ func (ts *TxnService) GetTxnsInBlock(cfg config.Config, height int64) (types.TxI if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &txInfo) + if err := json.Unmarshal(res, &txInfo); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { @@ -133,7 +135,9 @@ func (ts *TxnService) Index(cfg config.Config, height int64, txsInBlock types.Tx ON CONFLICT (hash) DO NOTHING`, txnData.TxRespData.Hash, height, txnData.TxRespData.Timestamp, txnData.TxRespData.Tx.Type, txnData.TxRespData.GasWanted, txnData.TxRespData.GasUsed, txnData.TxsData.Body.Memo, txnData.TxsData.AuthInfo.Fee.Payer, txnData.TxsData.AuthInfo.Fee.Granter) if err != nil { - tx.Rollback() + if rbErr := tx.Rollback(); rbErr != nil { + zap.L().Error("failed to rollback transaction", zap.Error(rbErr)) + } return err } @@ -144,7 +148,9 @@ func (ts *TxnService) Index(cfg config.Config, height int64, txsInBlock types.Tx VALUES ($1, $2)`, msg.Type, txnData.TxRespData.Hash) if err != nil { - tx.Rollback() + if rbErr := tx.Rollback(); rbErr != nil { + zap.L().Error("failed to rollback transaction", zap.Error(rbErr)) + } return err } } @@ -157,7 +163,9 @@ func (ts *TxnService) Index(cfg config.Config, height int64, txsInBlock types.Tx VALUES ($1) ON CONFLICT (denom) DO UPDATE SET denom = $1 RETURNING id`, v.Denom).Scan(&denomId) if err != nil { - tx.Rollback() + if rbErr := tx.Rollback(); rbErr != nil { + zap.L().Error("failed to rollback transaction", zap.Error(rbErr)) + } return err } @@ -166,7 +174,9 @@ func (ts *TxnService) Index(cfg config.Config, height int64, txsInBlock types.Tx VALUES ($1, $2, $3)`, v.Amount, txnData.TxRespData.Hash, denomId) if err != nil { - tx.Rollback() + if rbErr := tx.Rollback(); rbErr != nil { + zap.L().Error("failed to rollback transaction", zap.Error(rbErr)) + } return err } } @@ -175,7 +185,9 @@ func (ts *TxnService) Index(cfg config.Config, height int64, txsInBlock types.Tx // Commit the transaction err = tx.Commit() if err != nil { - tx.Rollback() + if rbErr := tx.Rollback(); rbErr != nil { + zap.L().Error("failed to rollback transaction", zap.Error(rbErr)) + } return err } diff --git a/services/upgrade.go b/services/upgrade.go index dc60f60..697fa82 100644 --- a/services/upgrade.go +++ b/services/upgrade.go @@ -30,7 +30,9 @@ func (us *UpgradeService) GetInfo(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &upgradeInfo) + if err := json.Unmarshal(res, &upgradeInfo); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/services/validator.go b/services/validator.go index 97ca1e4..78c0c86 100644 --- a/services/validator.go +++ b/services/validator.go @@ -87,7 +87,9 @@ func (vs *ValidatorService) GetValidatorInfo(cfg config.Config, currentBlockHeig zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &vSets) + if err := json.Unmarshal(res, &vSets); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) @@ -175,7 +177,9 @@ func runPages(cfg config.Config, currentBlockHeight int64, vSets *validatorsetsL zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &vSets) + if err := json.Unmarshal(res, &vSets); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) @@ -198,7 +202,9 @@ func testPageLimit(cfg config.Config, currentBlockHeight int64, vSets *validator zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &vSets) + if err := json.Unmarshal(res, &vSets); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "Internal error: page should be within") { zap.L().Info("", zap.String("warn", string(res))) @@ -216,7 +222,9 @@ func getValidator(cfg config.Config, rd *types.RESTData) { if err != nil { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } - json.Unmarshal(res, &v) + if err := json.Unmarshal(res, &v); err != nil { + zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + } if strings.Contains(string(res), "not found") { zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res))) } else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") { diff --git a/types/gravity.go b/types/gravity.go index f3dbc9d..d576ec6 100644 --- a/types/gravity.go +++ b/types/gravity.go @@ -91,11 +91,6 @@ type OracleEventNonce struct { EventNonce string `json:"event_nonce"` } -type lastClaimEvent struct { - EventNonce string `json:"ethereum_event_nonce"` - EventHeight string `json:"ethereum_event_height"` -} - type ValSetInfo struct { ValSet valSet `json:"valset"` ValCount int From e7f1eaa5d68a58b274e6190abacf223950c9b403 Mon Sep 17 00:00:00 2001 From: Jay Jie Date: Sat, 21 Sep 2024 13:32:00 -0700 Subject: [PATCH 4/5] chore: remove redundant files --- .github/workflows/ build-and-publish.yml | 88 ----------------------- .github/workflows/build-and-publish.yml | 89 +++++++++++++++++++++++- 2 files changed, 88 insertions(+), 89 deletions(-) delete mode 100644 .github/workflows/ build-and-publish.yml diff --git a/.github/workflows/ build-and-publish.yml b/.github/workflows/ build-and-publish.yml deleted file mode 100644 index a06123d..0000000 --- a/.github/workflows/ build-and-publish.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Build and Publish - -on: - push: - branches: [master, develop, jay/*] - tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+" - - "[v]?[0-9]+.[0-9]+.[0-9]+(-rc|-alpha|-beta)?[0-9]*" - workflow_dispatch: - -permissions: - contents: write - repository-projects: write - packages: write - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - publish: - name: Build and Publish - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - - # steps to perform in job - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Github Packages - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: Sanitize GitHub ref name - id: sanitize - run: echo "::set-output name=ref_name::$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9_.-]/-/g' | tr '[:upper:]' '[:lower:]')" - - - name: Sanitize repository name - id: sanitize_repo - run: echo "::set-output name=repo_name::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" - - - name: Build image and push to GitHub Container Registry - uses: docker/build-push-action@v5 - with: - labels: ${{ steps.meta.outputs.labels }} - tags: | - ${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }}:${{ steps.sanitize.outputs.ref_name }} - ${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }}:latest - push: true - cache-from: type=gha - cache-to: type=gha,mode=max - outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }},name-canonical=true,push=true - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} - - - name: Create GitHub Release - if: startsWith(github.ref, 'refs/tags/') - uses: ncipollo/release-action@v1 - with: - allowUpdates: true - generateReleaseNotes: true - body: ${{ steps.changelog.outputs.clean_changelog }} - artifacts: "" diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 0519ecb..a06123d 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -1 +1,88 @@ - \ No newline at end of file +name: Build and Publish + +on: + push: + branches: [master, develop, jay/*] + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+" + - "[v]?[0-9]+.[0-9]+.[0-9]+(-rc|-alpha|-beta)?[0-9]*" + workflow_dispatch: + +permissions: + contents: write + repository-projects: write + packages: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + publish: + name: Build and Publish + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + + # steps to perform in job + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Github Packages + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Sanitize GitHub ref name + id: sanitize + run: echo "::set-output name=ref_name::$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9_.-]/-/g' | tr '[:upper:]' '[:lower:]')" + + - name: Sanitize repository name + id: sanitize_repo + run: echo "::set-output name=repo_name::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" + + - name: Build image and push to GitHub Container Registry + uses: docker/build-push-action@v5 + with: + labels: ${{ steps.meta.outputs.labels }} + tags: | + ${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }}:${{ steps.sanitize.outputs.ref_name }} + ${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }}:latest + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.sanitize_repo.outputs.repo_name }},name-canonical=true,push=true + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + - name: Create GitHub Release + if: startsWith(github.ref, 'refs/tags/') + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + generateReleaseNotes: true + body: ${{ steps.changelog.outputs.clean_changelog }} + artifacts: "" From 3116091fc66906661a09203fdc71fb7a5538d110 Mon Sep 17 00:00:00 2001 From: Jay Jie Date: Sat, 21 Sep 2024 14:45:50 -0700 Subject: [PATCH 5/5] fix: info log instead of error when json unmarshaling fails --- services/akash/akash.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/akash/akash.go b/services/akash/akash.go index 781da51..eefc047 100644 --- a/services/akash/akash.go +++ b/services/akash/akash.go @@ -36,7 +36,7 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } if err := json.Unmarshal(res, &deployments); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } // get total deployments count @@ -52,7 +52,7 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } if err := json.Unmarshal(resActive, &activeDeployments); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } activeDeploymentsCount, err := strconv.Atoi(activeDeployments.Pagination.Total) @@ -79,7 +79,7 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) } if err := json.Unmarshal(res, &providers); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } // handle pagination @@ -91,7 +91,7 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa } var nextPage akash.ProvidersResponse if err := json.Unmarshal(res, &nextPage); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } // append to the response @@ -184,7 +184,7 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide return fmt.Errorf("error querying auditors for provider owner: %w", err) } if err := json.Unmarshal(res, &auditors); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } // handle pagination @@ -196,7 +196,7 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide } var nextPage akash.AuditorsResponse if err := json.Unmarshal(res, &nextPage); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } // append to the response @@ -272,7 +272,7 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi return fmt.Errorf("error querying deployments for provider owner: %w", err) } if err := json.Unmarshal(res, &deployments); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } // handle pagination @@ -284,7 +284,7 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi } var nextPage akash.DeploymentsResponse if err := json.Unmarshal(res, &nextPage); err != nil { - zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error())) + zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error())) } // append to the response