Skip to content

Commit

Permalink
Merge pull request #78 from Team-Kujira/telemetry
Browse files Browse the repository at this point in the history
Telemetry
  • Loading branch information
starsquidnodes authored Aug 4, 2024
2 parents 0280c9e + 4fb47b8 commit 15eade8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
11 changes: 11 additions & 0 deletions x/oracle/abci/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"github.com/Team-Kujira/core/x/oracle/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/hashicorp/go-metrics"
)

// StakeWeightedPrices defines the structure a proposer should use to calculate
Expand Down Expand Up @@ -264,6 +266,15 @@ func (h *ProposalHandler) GetBallotByDenom(ctx sdk.Context, ci abci.ExtendedComm
tmpPower = 0
}

telemetry.SetGaugeWithLabels(
[]string{"oracle", "price"},
float32(price.MustFloat64()),
[]metrics.Label{
telemetry.NewLabel("denom", base),
telemetry.NewLabel("validator", valAddr.String()),
},
)

votes[base] = append(votes[base],
types.NewVoteForTally(
price,
Expand Down
15 changes: 15 additions & 0 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"fmt"

"github.com/hashicorp/go-metrics"

gogotypes "github.com/cosmos/gogoproto/types"

"cosmossdk.io/errors"
Expand All @@ -11,6 +13,7 @@ import (
storetypes "cosmossdk.io/store/types"
"github.com/Team-Kujira/core/x/oracle/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
Expand Down Expand Up @@ -145,12 +148,24 @@ func (k Keeper) SetMissCounter(ctx sdk.Context, operator sdk.ValAddress, missCou
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&gogotypes.UInt64Value{Value: missCounter})
store.Set(types.GetMissCounterKey(operator), bz)

telemetry.SetGaugeWithLabels(
[]string{"oracle", "miss"},
float32(missCounter),
[]metrics.Label{telemetry.NewLabel("validator", operator.String())},
)
}

// DeleteMissCounter removes miss counter for the validator
func (k Keeper) DeleteMissCounter(ctx sdk.Context, operator sdk.ValAddress) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.GetMissCounterKey(operator))

telemetry.SetGaugeWithLabels(
[]string{"oracle", "miss"},
float32(0),
[]metrics.Label{telemetry.NewLabel("validator", operator.String())},
)
}

// IterateMissCounters iterates over the miss counters and performs a callback function.
Expand Down
30 changes: 30 additions & 0 deletions x/oracle/keeper/tally.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package keeper

import (
"github.com/hashicorp/go-metrics"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/Team-Kujira/core/x/oracle/types"
Expand Down Expand Up @@ -29,9 +32,36 @@ func Tally(_ sdk.Context,
spread := weightedMedian.Mul(maxDeviation)
spread = math.LegacyMaxDec(spread, standardDeviation)

if pb.Len() == 0 {
return weightedMedian, nil
}

labels := []metrics.Label{
telemetry.NewLabel("denom", pb[0].Denom),
}

telemetry.SetGaugeWithLabels(
[]string{"oracle", "median"},
float32(weightedMedian.MustFloat64()),
labels,
)

telemetry.SetGaugeWithLabels(
[]string{"oracle", "stddev"},
float32(standardDeviation.MustFloat64()),
labels,
)

telemetry.SetGaugeWithLabels(
[]string{"oracle", "spread"},
float32(spread.MustFloat64()),
labels,
)

for _, vote := range pb {
key := vote.Voter.String()
claim := validatorClaimMap[key]

// Filter ballot winners & abstain voters
if (vote.ExchangeRate.GTE(weightedMedian.Sub(spread)) &&
vote.ExchangeRate.LTE(weightedMedian.Add(spread))) ||
Expand Down
8 changes: 4 additions & 4 deletions x/oracle/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const (

// Default parameter values
var (
DefaultVoteThreshold = math.LegacyNewDecWithPrec(50, 2) // 50%
DefaultMaxDeviation = math.LegacyNewDecWithPrec(2, 1) // 2% (-1, 1)
DefaultVoteThreshold = math.LegacyNewDecWithPrec(5, 1) // 0.5 (50%)
DefaultMaxDeviation = math.LegacyNewDecWithPrec(2, 2) // 0.02 ( 2%)
DefaultRequiredSymbols = []Symbol{}
DefaultSlashFraction = math.LegacyNewDecWithPrec(1, 4) // 0.01%
DefaultMinValidPerWindow = math.LegacyNewDecWithPrec(5, 2) // 5%
DefaultSlashFraction = math.LegacyNewDecWithPrec(1, 4) // 0.0001 (0.01%)
DefaultMinValidPerWindow = math.LegacyNewDecWithPrec(5, 2) // 0.05 (5%)
)

var _ paramstypes.ParamSet = &Params{}
Expand Down

0 comments on commit 15eade8

Please sign in to comment.