From 4a6c437f08af887068a4f449c8bb4819e9ba7918 Mon Sep 17 00:00:00 2001 From: SangyunOck Date: Wed, 12 Oct 2022 19:07:28 +0900 Subject: [PATCH 1/6] feat: pool params to big int conversion --- .idea/.gitignore | 8 ++++++++ .idea/cosmos-exporter.iml | 9 +++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ general.go | 11 +++++++++-- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/cosmos-exporter.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..c3f502a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 디폴트 무시된 파일 +/shelf/ +/workspace.xml +# 에디터 기반 HTTP 클라이언트 요청 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/cosmos-exporter.iml b/.idea/cosmos-exporter.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/cosmos-exporter.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bfd10b5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/general.go b/general.go index 589ec1c..62eddbe 100644 --- a/general.go +++ b/general.go @@ -2,6 +2,7 @@ package main import ( "context" + "math/big" "net/http" "strconv" "sync" @@ -105,8 +106,14 @@ func GeneralHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Clien Float64("request-time", time.Since(queryStart).Seconds()). Msg("Finished querying staking pool") - generalBondedTokensGauge.Set(float64(response.Pool.BondedTokens.Int64())) - generalNotBondedTokensGauge.Set(float64(response.Pool.NotBondedTokens.Int64())) + bondedTokensBigInt := response.Pool.BondedTokens.BigInt() + bondedTokens, _ := new(big.Float).SetInt(bondedTokensBigInt).Float64() + + notBondedTokensBigInt := response.Pool.NotBondedTokens.BigInt() + notBondedTokens, _ := new(big.Float).SetInt(notBondedTokensBigInt).Float64() + + generalBondedTokensGauge.Set(bondedTokens) + generalNotBondedTokensGauge.Set(notBondedTokens) }() wg.Add(1) From 7c309be623c5fb1e3f2a609dc74315be88d299aa Mon Sep 17 00:00:00 2001 From: SangyunOck Date: Wed, 12 Oct 2022 19:32:41 +0900 Subject: [PATCH 2/6] feat: Dockerfile --- Dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..01aa2c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.18 AS exporter + +ENV GOBIN=/go/bin +ENV GOPATH=/go +ENV CGO_ENABLED=0 +ENV GOOS=linux + +RUN git clone "https://github.com/validance/cosmos-exporter" /exporter +WORKDIR /exporter +RUN go install + +FROM debian:buster-slim + +RUN apt-get update && apt-get upgrade && apt-get install -y curl +RUN useradd -ms /bin/bash exporter && chown -R exporter /usr + +COPY --from=exporter /go/bin/main /usr/bin/cosmos-exporter + +USER exporter From eab67060ae5592f53ed3b0cc11dd012897fb334a Mon Sep 17 00:00:00 2001 From: SangyunOck Date: Wed, 12 Oct 2022 20:03:24 +0900 Subject: [PATCH 3/6] feat: validator delegator share comp --- validators.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/validators.go b/validators.go index 753e407..bf9d4e9 100644 --- a/validators.go +++ b/validators.go @@ -153,7 +153,11 @@ func ValidatorsHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cl // sorting by delegator shares to display rankings sort.Slice(validators, func(i, j int) bool { - return validators[i].DelegatorShares.RoundInt64() > validators[j].DelegatorShares.RoundInt64() + if validators[i].DelegatorShares.BigInt().Cmp(validators[j].DelegatorShares.BigInt()) > 0 { + return true + } else { + return false + } }) }() From a70abb5f2a603b7eb5b1e3c6717993a713857fbe Mon Sep 17 00:00:00 2001 From: SangyunOck Date: Wed, 12 Oct 2022 20:22:34 +0900 Subject: [PATCH 4/6] chore: git repository change --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 01aa2c4..7864e19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ENV GOPATH=/go ENV CGO_ENABLED=0 ENV GOOS=linux -RUN git clone "https://github.com/validance/cosmos-exporter" /exporter +RUN git clone "https://github.com/solarlabsteam/cosmos-exporter" /exporter WORKDIR /exporter RUN go install From d91b7e38e5e1c0eaaad1947aba838ec899b152ac Mon Sep 17 00:00:00 2001 From: SangyunOck Date: Wed, 12 Oct 2022 20:26:24 +0900 Subject: [PATCH 5/6] chore: apply gitignore --- .gitignore | 1 + .idea/.gitignore | 8 -------- .idea/cosmos-exporter.iml | 9 --------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 5 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/cosmos-exporter.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 22b9958..324bf95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ main dist/ +.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index c3f502a..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# 디폴트 무시된 파일 -/shelf/ -/workspace.xml -# 에디터 기반 HTTP 클라이언트 요청 -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/cosmos-exporter.iml b/.idea/cosmos-exporter.iml deleted file mode 100644 index 5e764c4..0000000 --- a/.idea/cosmos-exporter.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index bfd10b5..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 4f57d9f5067d9673189f0e8497d6dd8d5de21305 Mon Sep 17 00:00:00 2001 From: Darron Park Date: Tue, 27 Feb 2024 15:52:43 +0900 Subject: [PATCH 6/6] fix: remove unbonded val from active set rank --- validator.go | 6 ++++++ validators.go | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/validator.go b/validator.go index a121b9e..01c6673 100644 --- a/validator.go +++ b/validator.go @@ -581,6 +581,12 @@ func ValidatorHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cli firstShares, firstErr := strconv.ParseFloat(validators[i].DelegatorShares.String(), 64) secondShares, secondErr := strconv.ParseFloat(validators[j].DelegatorShares.String(), 64) + if !validators[i].IsBonded() && validators[j].IsBonded() { + return false + } else if validators[i].IsBonded() && !validators[j].IsBonded() { + return true + } + if firstErr != nil || secondErr != nil { sublogger.Error(). Err(err). diff --git a/validators.go b/validators.go index bf9d4e9..0d9e044 100644 --- a/validators.go +++ b/validators.go @@ -151,13 +151,14 @@ func ValidatorsHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cl Msg("Finished querying validators") validators = validatorsResponse.Validators - // sorting by delegator shares to display rankings + // sorting by delegator shares to display rankings (unbonded go last) sort.Slice(validators, func(i, j int) bool { - if validators[i].DelegatorShares.BigInt().Cmp(validators[j].DelegatorShares.BigInt()) > 0 { - return true - } else { + if !validators[i].IsBonded() && validators[j].IsBonded() { return false + } else if validators[i].IsBonded() && !validators[j].IsBonded() { + return true } + return validators[i].DelegatorShares.BigInt().Cmp(validators[j].DelegatorShares.BigInt()) > 0 }) }()