Skip to content

Commit

Permalink
fix: expose stakes as Near instead of yoctoNear (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKetmo authored Oct 19, 2023
1 parent 8005224 commit 46913a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 46913a9

Please sign in to comment.