Skip to content

Commit

Permalink
feat: removed soft opt-out (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Aug 8, 2024
1 parent 2cac301 commit 9bcfad0
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 366 deletions.
9 changes: 0 additions & 9 deletions pkg/app_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ func NewAppManager(
config.Intervals.SlashingParams*time.Second,
managerLogger,
),
constants.PopulatorSoftOptOutThreshold: populatorsPkg.NewWrapper(
populatorsPkg.NewSoftOptOutThresholdPopulator(config, dataManager, stateManager, metricsManager, managerLogger),
config.Intervals.SoftOptOutThreshold*time.Second,
managerLogger,
),
constants.PopulatorTrimDatabase: populatorsPkg.NewWrapper(
populatorsPkg.NewTrimDatabasePopulator(stateManager),
config.Intervals.Trim*time.Second,
Expand Down Expand Up @@ -104,10 +99,6 @@ func (a *AppManager) Start() {
a.Config.StoreBlocks,
)

if a.Config.IsConsumer.Bool {
a.MetricsManager.LogConsumerSoftOutThreshold(a.Config.Name, a.Config.ConsumerSoftOptOut)
}

a.MetricsManager.LogChainInfo(a.Config.Name, a.Config.GetName())

for _, reporter := range a.Reporters {
Expand Down
1 change: 0 additions & 1 deletion pkg/config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type ChainConfig struct {
ProviderRPCEndpoints []string `toml:"provider-rpc-endpoints"`
ConsumerValidatorPrefix string `toml:"consumer-validator-prefix"`
ConsumerChainID string `toml:"consumer-chain-id"`
ConsumerSoftOptOut float64 `default:"0.05" toml:"consumer-soft-opt-out"`

FetcherType string `default:"cosmos-rpc" toml:"fetcher-type"`
LCDEndpoints []string `toml:"lcd-endpoints"`
Expand Down
7 changes: 3 additions & 4 deletions pkg/config/intervals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package config
import "time"

type IntervalsConfig struct {
Blocks time.Duration `default:"30" toml:"blocks"`
Trim time.Duration `default:"300" toml:"trim"`
SlashingParams time.Duration `default:"300" toml:"slashing-params"`
SoftOptOutThreshold time.Duration `default:"300" toml:"soft-opt-out-threshold"`
Blocks time.Duration `default:"30" toml:"blocks"`
Trim time.Duration `default:"300" toml:"trim"`
SlashingParams time.Duration `default:"300" toml:"slashing-params"`
}
5 changes: 2 additions & 3 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ const (
FetcherTypeCosmosRPC string = "cosmos-rpc"
FetcherTypeCosmosLCD string = "cosmos-lcd"

PopulatorSlashingParams = "slashing-params-populator"
PopulatorSoftOptOutThreshold = "soft-opt-out-threshold-populator"
PopulatorTrimDatabase = "trim-database-populator"
PopulatorSlashingParams = "slashing-params-populator"
PopulatorTrimDatabase = "trim-database-populator"
)

func GetEventNames() []EventName {
Expand Down
2 changes: 0 additions & 2 deletions pkg/data/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"main/pkg/data/fetchers"
"main/pkg/metrics"

paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
providerTypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
Expand All @@ -20,7 +19,6 @@ type Fetcher interface {
height int64,
) (*providerTypes.QueryAllPairsValConAddrByConsumerChainIDResponse, error)
GetSlashingParams(height int64) (*slashingTypes.QueryParamsResponse, error)
GetConsumerSoftOutOutThreshold(height int64) (*paramsTypes.QueryParamsResponse, error)
}

func GetFetcher(
Expand Down
29 changes: 0 additions & 29 deletions pkg/data/fetchers/cosmos_lcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codecTypes "github.com/cosmos/cosmos-sdk/codec/types"

paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
providerTypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
Expand Down Expand Up @@ -185,34 +184,6 @@ func (f *CosmosLCDFetcher) GetSlashingParams(height int64) (*slashingTypes.Query
return &response, nil
}

func (f *CosmosLCDFetcher) GetConsumerSoftOutOutThreshold(height int64) (*paramsTypes.QueryParamsResponse, error) {
var response paramsTypes.QueryParamsResponse

if err := f.Get(
"/cosmos/params/v1beta1/params?subspace=ccvconsumer&key=SoftOptOutThreshold",
constants.QueryTypeSubspaceParams,
&response,
f.clients,
height,
func(v interface{}) error {
response, ok := v.(*paramsTypes.QueryParamsResponse)
if !ok {
return errors.New("error converting subspace param response")
}

if response.Param.Value == "" {
return errors.New("malformed response: got empty subspace param")
}

return nil
},
); err != nil {
return nil, err
}

return &response, nil
}

func (f *CosmosLCDFetcher) Get(
url string,
queryType constants.QueryType,
Expand Down
22 changes: 0 additions & 22 deletions pkg/data/fetchers/cosmos_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

queryTypes "github.com/cosmos/cosmos-sdk/types/query"

paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
providerTypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
Expand Down Expand Up @@ -198,27 +197,6 @@ func (f *CosmosRPCFetcher) GetSlashingParams(height int64) (*slashingTypes.Query
return &response, nil
}

func (f *CosmosRPCFetcher) GetConsumerSoftOutOutThreshold(height int64) (*paramsTypes.QueryParamsResponse, error) {
query := paramsTypes.QueryParamsRequest{
Subspace: "ccvconsumer",
Key: "SoftOptOutThreshold",
}

var response paramsTypes.QueryParamsResponse
if err := f.AbciQuery(
"/cosmos.params.v1beta1.Query/Params",
&query,
height,
constants.QueryTypeSubspaceParams,
&response,
f.clients,
); err != nil {
return nil, err
}

return &response, nil
}

func (f *CosmosRPCFetcher) Get(
url string,
queryType constants.QueryType,
Expand Down
5 changes: 0 additions & 5 deletions pkg/data/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"main/pkg/utils"
"sync"

paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
providerTypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"

slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -237,10 +236,6 @@ func (manager *Manager) GetSlashingParams(height int64) (*slashingTypes.QueryPar
return manager.fetcher.GetSlashingParams(height)
}

func (manager *Manager) GetConsumerSoftOutOutThreshold(height int64) (*paramsTypes.QueryParamsResponse, error) {
return manager.fetcher.GetConsumerSoftOutOutThreshold(height)
}

func (manager *Manager) GetActiveSetAtBlock(height int64) (map[string]bool, error) {
return manager.rpc.GetActiveSetAtBlock(height)
}
Expand Down
22 changes: 3 additions & 19 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ type Manager struct {
appVersionGauge *prometheus.GaugeVec
startTimeGauge *prometheus.GaugeVec

chainInfoGauge *prometheus.GaugeVec
signedBlocksWindowGauge *prometheus.GaugeVec
minSignedPerWindowGauge *prometheus.GaugeVec
softOptOutThresholdGauge *prometheus.GaugeVec
chainInfoGauge *prometheus.GaugeVec
signedBlocksWindowGauge *prometheus.GaugeVec
minSignedPerWindowGauge *prometheus.GaugeVec

storeBlocksGauge *prometheus.GaugeVec
}
Expand Down Expand Up @@ -165,10 +164,6 @@ func NewManager(logger zerolog.Logger, config configPkg.MetricsConfig) *Manager
Name: constants.PrometheusMetricsPrefix + "min_signed",
Help: "A % of blocks validator needs to sign within window",
}, []string{"chain"})
softOptOutThresholdGauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: constants.PrometheusMetricsPrefix + "soft_opt_out_threshold",
Help: "Soft opt out threshold for consumer chains",
}, []string{"chain"})
chainInfoGauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: constants.PrometheusMetricsPrefix + "chain_info",
Help: "Chain info, with constant 1 as value and pretty_name and chain as labels",
Expand Down Expand Up @@ -200,7 +195,6 @@ func NewManager(logger zerolog.Logger, config configPkg.MetricsConfig) *Manager
registry.MustRegister(signedBlocksWindowGauge)
registry.MustRegister(storeBlocksGauge)
registry.MustRegister(minSignedPerWindowGauge)
registry.MustRegister(softOptOutThresholdGauge)
registry.MustRegister(chainInfoGauge)

startTimeGauge.
Expand Down Expand Up @@ -237,7 +231,6 @@ func NewManager(logger zerolog.Logger, config configPkg.MetricsConfig) *Manager
signedBlocksWindowGauge: signedBlocksWindowGauge,
storeBlocksGauge: storeBlocksGauge,
minSignedPerWindowGauge: minSignedPerWindowGauge,
softOptOutThresholdGauge: softOptOutThresholdGauge,
chainInfoGauge: chainInfoGauge,
}
}
Expand Down Expand Up @@ -482,15 +475,6 @@ func (m *Manager) LogSlashingParams(
Set(float64(storeBlocks))
}

func (m *Manager) LogConsumerSoftOutThreshold(
chain string,
threshold float64,
) {
m.softOptOutThresholdGauge.
With(prometheus.Labels{"chain": chain}).
Set(threshold)
}

func (m *Manager) LogChainInfo(chain string, prettyName string) {
m.chainInfoGauge.
With(prometheus.Labels{"chain": chain, "pretty_name": prettyName}).
Expand Down
75 changes: 0 additions & 75 deletions pkg/populators/soft_opt_out_threshold_populator.go

This file was deleted.

14 changes: 4 additions & 10 deletions pkg/reporters/discord/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ func (reporter *Reporter) GetParamsCommand() *Command {
}

activeValidators := snapshot.Entries.GetActive()
var amount int
if reporter.Config.IsConsumer.Bool {
_, amount = snapshot.Entries.GetSoftOutOutThreshold(reporter.Config.ConsumerSoftOptOut)
}

template, err := reporter.TemplatesManager.Render("Params", paramsRender{
Config: reporter.Config,
BlockTime: blockTime,
MaxTimeToJail: maxTimeToJail,
ConsumerOptOutValidators: amount,
ValidatorsCount: len(activeValidators),
Config: reporter.Config,
BlockTime: blockTime,
MaxTimeToJail: maxTimeToJail,
ValidatorsCount: len(activeValidators),
})
if err != nil {
reporter.Logger.Error().Err(err).Msg("Error rendering params template")
Expand Down
17 changes: 4 additions & 13 deletions pkg/reporters/discord/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ func (e missingValidatorsEntry) FormatMissed() string {
}

type paramsRender struct {
Config *config.ChainConfig
BlockTime time.Duration
MaxTimeToJail time.Duration
ConsumerOptOutValidators int
ValidatorsCount int
Config *config.ChainConfig
BlockTime time.Duration
MaxTimeToJail time.Duration
ValidatorsCount int
}

func (r paramsRender) FormatMinSignedPerWindow() string {
Expand All @@ -62,14 +61,6 @@ func (r paramsRender) FormatGroupPercent(group *config.MissedBlocksGroup) string
)
}

func (r paramsRender) FormatSoftOptOut() string {
return fmt.Sprintf("%.2f", r.Config.ConsumerSoftOptOut*100)
}

func (r paramsRender) GetConsumerRequiredValidators() int {
return r.ValidatorsCount - r.ConsumerOptOutValidators
}

func (r paramsRender) FormatSnapshotInterval() string {
if r.Config.SnapshotsInterval == 1 {
return "every block"
Expand Down
14 changes: 4 additions & 10 deletions pkg/reporters/telegram/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@ func (reporter *Reporter) HandleParams(c tele.Context) error {
}

activeValidators := snapshot.Entries.GetActive()
var amount int
if reporter.Config.IsConsumer.Bool {
_, amount = snapshot.Entries.GetSoftOutOutThreshold(reporter.Config.ConsumerSoftOptOut)
}

template, err := reporter.TemplatesManager.Render("Params", paramsRender{
Config: reporter.Config,
BlockTime: blockTime,
MaxTimeToJail: maxTimeToJail,
ConsumerOptOutValidators: amount,
ValidatorsCount: len(activeValidators),
Config: reporter.Config,
BlockTime: blockTime,
MaxTimeToJail: maxTimeToJail,
ValidatorsCount: len(activeValidators),
})
if err != nil {
return err
Expand Down
Loading

0 comments on commit 9bcfad0

Please sign in to comment.