Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose stakes as Near instead of yoctoNear #6

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import (
"github.com/fatih/color"
"github.com/kilnfi/near-validator-watcher/pkg/metrics"
"github.com/kilnfi/near-validator-watcher/pkg/near"
"github.com/shopspring/decimal"
"github.com/sirupsen/logrus"
)

var yoctoUnit = decimal.NewFromInt(10).Pow(decimal.NewFromInt(24))

type Watcher struct {
config *Config
client *near.Client
Expand Down Expand Up @@ -158,7 +161,7 @@ func (w *Watcher) collectValidators(ctx context.Context) (near.ValidatorsRespons
w.metrics.ValidatorProducedChunks.WithLabelValues(labels...).Set(float64(v.NumProducedChunks))

w.metrics.ValidatorSlashed.WithLabelValues(labels...).Set(metrics.BoolToFloat64(v.IsSlashed))
w.metrics.ValidatorStake.WithLabelValues(labels...).Set(v.Stake.InexactFloat64())
w.metrics.ValidatorStake.WithLabelValues(labels...).Set(v.Stake.Div(yoctoUnit).InexactFloat64())

t := v.Stake.InexactFloat64()
if seatPrice == 0 {
Expand All @@ -174,13 +177,13 @@ func (w *Watcher) collectValidators(ctx context.Context) (near.ValidatorsRespons
for _, v := range validators.NextValidators {
w.metrics.NextValidatorStake.
WithLabelValues(v.AccountId, v.PublicKey, labelEpochStartHeight, w.isTracked(v.AccountId)).
Set(v.Stake.InexactFloat64())
Set(v.Stake.Div(yoctoUnit).InexactFloat64())
}

for _, v := range validators.CurrentProposals {
w.metrics.CurrentProposals.
WithLabelValues(v.AccountId, v.PublicKey, labelEpochStartHeight, w.isTracked(v.AccountId)).
Set(v.Stake.InexactFloat64())
Set(v.Stake.Div(yoctoUnit).InexactFloat64())
}

for _, v := range validators.PrevEpochKickOut {
Expand Down
4 changes: 2 additions & 2 deletions pkg/watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ func TestWatcher(t *testing.T) {

// Stake
assert.Equal(t, 5, testutil.CollectAndCount(metrics.ValidatorStake))
assert.Equal(t, float64(47595986932991225292162473028453), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
assert.Equal(t, float64(47595986.932991225292162473028453), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
"node2",
`ed25519:GkDv7nSMS3xcqA45cpMvFmfV1o4fRF6zYo1JRR6mNqg5`,
"142256359",
"0",
)))
assert.Equal(t, float64(6736422258840329637507414885764), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
assert.Equal(t, float64(6736422.258840329637507414885764), testutil.ToFloat64(metrics.ValidatorStake.WithLabelValues(
"kiln.pool.f863973.m0",
`ed25519:Bq8fe1eUgDRexX2CYDMhMMQBiN13j8vTAVFyTNhEfh1W`,
"142256359",
Expand Down
Loading