Skip to content

Commit

Permalink
feat: isolate reporters by subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Mar 1, 2024
1 parent 76aaa0e commit d44f71b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 22 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ Additionally, for the ease of using commands, you can put the following list as
```
help - Display help message
status - Display nodes status
config - Display .toml config
alias - Add a wallet alias
aliases - List wallet aliases
```
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ func (c Chains) FindByChainID(chainID string) (*Chain, bool) {
return nil, false
}

func (c Chains) HasChain(name string) bool {
for _, chain := range c {
if chain.Name == name {
return true
}
}

return false
}

type Chain struct {
Name string
PrettyName string
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/types/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ func TestChainsFindByName(t *testing.T) {
require.Nil(t, chains.FindByName("name-2"))
}

func TestChainsHasByName(t *testing.T) {
t.Parallel()

chains := types.Chains{
{Name: "name"},
}

require.True(t, chains.HasChain("name"))
require.False(t, chains.HasChain("name-2"))
}

func TestChainsFindByChainID(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const (
ReporterQueryHelp ReporterQuery = "help"
ReporterQueryGetAliases ReporterQuery = "get_aliases"
ReporterQuerySetAlias ReporterQuery = "set_alias"
ReporterQueryGetConfig ReporterQuery = "get_config"
ReporterQueryNodesStatus ReporterQuery = "nodes_status"
)

Expand Down
19 changes: 19 additions & 0 deletions pkg/data_fetcher/data_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,22 @@ func (f *DataFetcher) FindSubscriptionByReporter(

return nil, false
}

func (f *DataFetcher) FindChainsByReporter(
reporterName string,
) configTypes.Chains {
chains := make(configTypes.Chains, 0)

for _, subscription := range f.Config.Subscriptions {
if subscription.Reporter != reporterName {
continue
}

for _, chainSubscription := range subscription.ChainSubscriptions {
chain := f.Config.Chains.FindByName(chainSubscription.Chain)
chains = append(chains, chain)
}
}

return chains
}
1 change: 1 addition & 0 deletions pkg/data_fetcher/populate_proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package data_fetcher
19 changes: 0 additions & 19 deletions pkg/reporters/telegram/get_config.go

This file was deleted.

9 changes: 9 additions & 0 deletions pkg/reporters/telegram/list_nodes_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ func (reporter *Reporter) HandleListNodesStatus(c tele.Context) error {

reporter.MetricsManager.LogReporterQuery(reporter.Name(), constants.ReporterQueryNodesStatus)

chains := reporter.DataFetcher.FindChainsByReporter(reporter.Name())
if len(chains) == 0 {
return reporter.BotReply(c, "This reporter is not linked to any chains!")
}

statuses := map[string]map[string]types.TendermintRPCStatus{}

for chain, chainNodes := range reporter.NodesManager.Nodes {
if !chains.HasChain(chain) {
continue
}

statuses[chain] = map[string]types.TendermintRPCStatus{}
for _, node := range chainNodes {
statuses[chain][node.URL] = node.Status()
Expand Down
1 change: 0 additions & 1 deletion pkg/reporters/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func (reporter *Reporter) Init() {
bot.Handle("/help", reporter.HandleHelp)
bot.Handle("/start", reporter.HandleHelp)
bot.Handle("/status", reporter.HandleListNodesStatus)
bot.Handle("/config", reporter.HandleGetConfig)
bot.Handle("/alias", reporter.HandleSetAlias)
bot.Handle("/aliases", reporter.HandleGetAliases)

Expand Down
3 changes: 3 additions & 0 deletions pkg/types/data_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ type DataFetcher interface {
chain *configTypes.Chain,
validatorLink *configTypes.Link,
)
FindChainsByReporter(
reporterName string,
) configTypes.Chains
}

0 comments on commit d44f71b

Please sign in to comment.