Skip to content

Commit

Permalink
Merge pull request cosmostation#38 from Jeongseup/fix/babylon-monitor…
Browse files Browse the repository at this point in the history
…ing-packages

fix: babylon monitoring packages
  • Loading branch information
Jeongseup authored Feb 5, 2025
2 parents dc75426 + 4802a2d commit 8109dab
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 6,
"id": 5,
"links": [],
"panels": [
{
Expand All @@ -43,7 +43,7 @@
"content": "<!-- Main content -->\n<div style=\"display: flex; justify-content: space-between; align-items: center;\">\n <!-- H2 with a link -->\n <a href=\"https://github.com/cosmostation/cvms\" target=\"_blank\" style=\"text-decoration: none; color: inherit;\">\n <h2 style=\"margin-right: 10px;\">Cosmos Validator Monitoring Service (CVMS) 🌌 🔭</h2>\n </a> \n <!-- \"Powered by Cosmostation\" on the right -->\n <div style=\"display: flex; align-items: center;\">\n <a href=\"https://cosmostation.io\" target=\"_blank\" style=\"text-decoration: none; color: inherit;\">\n <span>Powered by Cosmostation </span>\n <img src=\"https://raw.githubusercontent.com/cosmostation/chainlist/refs/heads/main/resource/cosmostation/cosmostation_color.svg\" alt=\"Logo\" style=\"height: 30px; margin-left: 5px;\">\n </a>\n </div>\n</div>\n\n<!-- Paragraph below the header -->\n<p>\n The Cosmos Validator Monitoring Service (CVMS) is an open-source, integrated monitoring system designed for validators and network in the Cosmos app chain ecosystem.<br/>\n This public dashboard is a playground for developers and beta release testing for CVMS.\n</p>\n<p>\n <a href=\"https://github.com/cosmostation/cvms\" target=\"_blank\" style=\"text-decoration: none; color: #1E90FF;\">\n 👉 CVMS Github Link Here!\n </a> \n <a href=\"https://github.com/cosmostation/cvms/blob/release/docs/setup.md\" target=\"_blank\" style=\"text-decoration: none; color: #1E90FF;\">\n 👉 CVMS Setup Guide Here!!\n </a> \n</p>",
"mode": "html"
},
"pluginVersion": "11.3.0",
"pluginVersion": "11.5.0",
"title": "",
"transparent": true,
"type": "text"
Expand Down Expand Up @@ -244,11 +244,12 @@
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "11.3.0",
"pluginVersion": "11.5.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -412,9 +413,9 @@
"autorange": true
}
},
"onclick": "// Event handling\n/*\n// 'data', 'variables', 'options', 'utils', and 'event' are passed as arguments\n\ntry {\n const { type: eventType, data: eventData } = event;\n const { timeZone, dayjs, locationService, getTemplateSrv } = utils;\n\n switch (eventType) {\n case 'click':\n console.log('Click event:', eventData.points);\n break;\n case 'select':\n console.log('Selection event:', eventData.range);\n break;\n case 'zoom':\n console.log('Zoom event:', eventData);\n break;\n default:\n console.log('Unhandled event type:', eventType, eventData);\n }\n\n console.log('Current time zone:', timeZone);\n console.log('From time:', dayjs(variables.__from).format());\n console.log('To time:', dayjs(variables.__to).format());\n\n // Example of using locationService\n // locationService.partial({ 'var-example': 'test' }, true);\n\n} catch (error) {\n console.error('Error in onclick handler:', error);\n}\n*/\n ",
"onclick": "",
"resScale": 2,
"script": "// Extracting the SQL data\nlet series = data.series[0]; // Access the data series\nif (!series || series.length === 0 || series.fields[0].values.length === 0) {\n // Query result has no records, so skip the chart rendering\n return {\n data: [],\n layout: {\n title: 'No Data Available',\n height: 10, // Reduce panel height\n margin: {\n l: 20, // Left margin\n r: 20, // Right margin\n t: 40, // Top margin\n b: 40 // Bottom margin\n }\n }\n };\n}\n\n// Start data processing\nlet height = series.fields[0]; // Block height\nlet voted = series.fields[1]; // Voted status (0 = Inactive, 1 = Missed, 2 = Voted, 3 = Proposed)\nlet moniker = series.fields[2]; // Moniker (Validator name)\nlet epoch = series.fields[3]; // Moniker (Validator name)\n\n// Get unique monikers and heights from the dataset for rows and columns\nlet uniqueMonikers = [...new Set(moniker.values)].sort().reverse(); // Unique monikers for Y-axis\nlet uniqueHeights = [...new Set(height.values)].sort().reverse(); // Unique block heights for X-axis\n\n// Initialize the 2D array (zValues) for the heatmap, default to 0 (Inactive)\nlet zValues = Array(uniqueMonikers.length).fill(null).map(() => Array(uniqueHeights.length).fill(0));\nlet hoverText = Array(uniqueMonikers.length).fill(null).map(() => Array(uniqueHeights.length).fill(\"\"));\n\n// Populate zValues with voted data (0 = Inactive, 1 = Missed, 2 = Voted, 3 = Proposed)\nfor (let i = 0; i < height.values.length; i++) {\n let rowIndex = uniqueMonikers.indexOf(moniker.values[i]); // Find the correct row for the moniker\n let colIndex = uniqueHeights.indexOf(height.values[i]); // Find the correct column for the height\n zValues[rowIndex][colIndex] = voted.values[i]; // Assign the voted status\n let statusMeaning = getStatusMeaning(voted.values[i]); // Get the status meaning\n let epoch_number = epoch.values[i];\n hoverText[rowIndex][colIndex] = `x: ${height.values[i]}<br>y: ${moniker.values[i]}<br>z: ${statusMeaning}(epoch: ${epoch_number})`; // Custom hover info with status meaning \n}\n\n// Define a continuous color scale for smoother transitions\nlet colorScale = [\n [0, 'rgba(255, 0, 0, 0.5)'], // Inactive = gray\n [0.33, 'rgba(0, 0, 0, 0.5)'], // Missed = red\n [0.66, 'rgba(0, 0, 0, 0.5)'], // Voted = black\n [1, 'rgba(0, 0, 0, 0.5)'], // Nill = yellow\n];\n\n\n// Return the heatmap configuration for Plotly\nreturn {\n data: [{\n z: zValues, // 2D array of statuses (0, 1, 2, 3)\n x: uniqueHeights, // Block heights for X-axis\n y: uniqueMonikers, // Monikers for Y-axis\n type: 'heatmap', // Plotly heatmap type\n colorscale: colorScale, // Use only two colors for discrete values\n showscale: false, // Hide the color scale bar\n zmin: 0, // Set the minimum value for z (status)\n zmax: 3, // Set the maximum value for z (status)\n xgap: 5, // Add gap between cells along the X-axis (adjust the value for bigger gaps)\n ygap: 5, // Add gap between cells along the Y-axis (adjust the value for bigger gaps) \n text: hoverText, // Set the hoverText for the heatmap\n hoverinfo: 'text' // Display the hoverText \n }],\n layout: {\n xaxis: {\n type: 'category',\n tickmode: 'linear',\n showgrid: true, // Ensure gridlines on X-axis\n tickformat: '.0f',\n tickangle: -45, // Rotate labels for better readability\n },\n yaxis: {\n tickmode: 'array', // Use tickmode 'array' to manually set Y-axis labels\n tickvals: uniqueMonikers, // Set tick values to all unique monikers\n ticktext: uniqueMonikers, // Display all monikers as text on Y-axis\n showgrid: true // Ensure gridlines on Y-axis\n },\n margin: {\n l: 200, // Adjust margin for longer moniker names\n t: 20, // Reduce top margin\n b: 120, // Adjust bottom margin for X-axis labels\n }\n }\n};\n\nfunction getStatusMeaning(status) {\n switch(status) {\n case 0:\n return 'Absent';\n case 1:\n return 'Voted';\n default:\n return 'Unknown';\n }\n}",
"script": "// Extracting the SQL data\nlet series = data.series[0]; // Access the data series\nif (!series || series.length === 0 || series.fields[0].values.length === 0) {\n // Query result has no records, so skip the chart rendering\n return {\n data: [],\n layout: {\n title: 'No Data Available',\n height: 10, // Reduce panel height\n margin: {\n l: 20, // Left margin\n r: 20, // Right margin\n t: 40, // Top margin\n b: 40 // Bottom margin\n }\n }\n };\n}\n\n// Start data processing\nlet height = series.fields[0]; // Block height\nlet voted = series.fields[1]; // Voted status (0 = Inactive, 1 = Missed, 2 = Voted, 3 = Proposed)\nlet moniker = series.fields[2]; // Moniker (Validator name)\nlet epoch = series.fields[3]; // Moniker (Validator name)\n\n// Get unique monikers and heights from the dataset for rows and columns\nlet uniqueMonikers = [...new Set(moniker.values)].sort().reverse(); // Unique monikers for Y-axis\nlet uniqueHeights = [...new Set(height.values)].sort().reverse(); // Unique block heights for X-axis\n\n// Initialize the 2D array (zValues) for the heatmap, default to 0 (Inactive)\nlet zValues = Array(uniqueMonikers.length).fill(null).map(() => Array(uniqueHeights.length).fill(0));\nlet hoverText = Array(uniqueMonikers.length).fill(null).map(() => Array(uniqueHeights.length).fill(\"\"));\n\n// Populate zValues with voted data (0 = Inactive, 1 = Missed, 2 = Voted, 3 = Proposed)\nfor (let i = 0; i < height.values.length; i++) {\n let rowIndex = uniqueMonikers.indexOf(moniker.values[i]); // Find the correct row for the moniker\n let colIndex = uniqueHeights.indexOf(height.values[i]); // Find the correct column for the height\n zValues[rowIndex][colIndex] = voted.values[i]; // Assign the voted status\n let statusMeaning = getStatusMeaning(voted.values[i]); // Get the status meaning\n let epoch_number = epoch.values[i];\n hoverText[rowIndex][colIndex] = `x: ${height.values[i]}<br>y: ${moniker.values[i]}<br>z: ${statusMeaning}(epoch: ${epoch_number})`; // Custom hover info with status meaning \n}\n\n// Define a continuous color scale for smoother transitions\n// let colorScale = [\n// [0, 'rgba(255, 0, 0, 0.5)'], // Inactive = gray\n// [0.33, 'rgba(0, 0, 0, 0.5)'], // Missed = red\n// [0.66, 'rgba(0, 0, 0, 0.5)'], // Voted = black\n// [1, 'rgba(0, 0, 0, 0.5)'], // Nill = yellow\n// ];\n\n// Define a continuous color scale for smoother transitions\nlet colorScale = [\n [0, 'rgba(128, 128, 128, 0.5)'], // Inactive = gray\n [0.33, 'rgba(255, 0, 0, 0.5)'], // Missed = red\n [0.66, 'rgba(0, 0, 0, 0.5)'], // Voted = black\n [1, 'rgba(255, 255, 0, 0.5)'], // Nill = yellow\n];\n\n\n// Return the heatmap configuration for Plotly\nreturn {\n data: [{\n z: zValues, // 2D array of statuses (0, 1, 2, 3)\n x: uniqueHeights, // Block heights for X-axis\n y: uniqueMonikers, // Monikers for Y-axis\n type: 'heatmap', // Plotly heatmap type\n colorscale: colorScale, // Use only two colors for discrete values\n showscale: false, // Hide the color scale bar\n zmin: 0, // Set the minimum value for z (status)\n zmax: 3, // Set the maximum value for z (status)\n xgap: 5, // Add gap between cells along the X-axis (adjust the value for bigger gaps)\n ygap: 5, // Add gap between cells along the Y-axis (adjust the value for bigger gaps) \n text: hoverText, // Set the hoverText for the heatmap\n hoverinfo: 'text' // Display the hoverText \n }],\n layout: {\n xaxis: {\n type: 'category',\n tickmode: 'linear',\n showgrid: true, // Ensure gridlines on X-axis\n tickformat: '.0f',\n tickangle: -45, // Rotate labels for better readability\n },\n yaxis: {\n tickmode: 'array', // Use tickmode 'array' to manually set Y-axis labels\n tickvals: uniqueMonikers, // Set tick values to all unique monikers\n ticktext: uniqueMonikers, // Display all monikers as text on Y-axis\n showgrid: true // Ensure gridlines on Y-axis\n },\n margin: {\n l: 200, // Adjust margin for longer moniker names\n t: 20, // Reduce top margin\n b: 120, // Adjust bottom margin for X-axis labels\n }\n }\n};\n\n// Function to map the ve status to its corresponding meaning\n// ref; https://github.com/cometbft/cometbft/blob/v0.38.x/proto/tendermint/types/validator.pb.go\nfunction getStatusMeaning(status) {\n switch(status) {\n case 1:\n return 'Absent';\n case 2:\n return 'Commit';\n case 3:\n return 'Nil';\n default:\n return 'Unknown';\n }\n}",
"syncTimeRange": false,
"timeCol": ""
},
Expand Down
5 changes: 3 additions & 2 deletions internal/common/api/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"
"net/http"
"net/url"
"sync"
"time"

Expand Down Expand Up @@ -82,8 +83,8 @@ func GetBabylonFinalityProviderInfos(c common.CommonClient) ([]types.FinalityPro
fpInfoList = append(fpInfoList, fpInfos.FinalityProviders...)

if fpInfos.Pagination.NextKey != "" {
key = fpInfos.Pagination.NextKey
c.Debugf("there is next key, keep collecting finality providers")
key = url.QueryEscape(fpInfos.Pagination.NextKey)
c.Debugf("there is next key, keep collecting finality providers by using this path: %s", types.BabylonFinalityProviderInfosQueryPath(key))
} else {
// got all finality provider infos
c.Debugf("collected all finality providers")
Expand Down
32 changes: 24 additions & 8 deletions internal/common/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,28 @@ func GetStakingValidators(client common.CommonClient, chainName string, newStaki
return nil
}

func MakeFinalityProviderInfoList(
app common.CommonApp,
chainID string, chainInfoID int64,
chainName string, isConsumer bool,
newValidatorAddressMap map[string]bool,
height ...int64,
) ([]indexermodel.FinalityProviderInfo, error) {
return nil, nil
func MakeFinalityProviderInfoList(c common.CommonClient, chainInfoID int64, newFinalityProviderMap map[string]bool) ([]indexermodel.FinalityProviderInfo, error) {
fps, err := api.GetBabylonFinalityProviderInfos(c)
if err != nil {
return nil, errors.Cause(err)
}

fpInfoList := make([]indexermodel.FinalityProviderInfo, 0)
for _, fp := range fps {
// if found new btc pk, it need to add fp list for indexing
if newFinalityProviderMap[fp.BTCPK] {
fpInfoList = append(fpInfoList, indexermodel.FinalityProviderInfo{
ChainInfoID: chainInfoID,
Moniker: fp.Description.Moniker,
BTCPKs: fp.BTCPK,
OperatorAddress: fp.Address,
})
}
}

if len(fpInfoList) == 0 {
return nil, errors.New("unexpected err")
}

return fpInfoList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (repo *MetaRepository) InsertFinalityProviderInfoList(fpInfoList []model.Fi
ExcludeColumn("id").
Exec(ctx)
if err != nil {
return errors.Wrapf(err, "failed to insert validator info list")
return errors.Wrapf(err, "failed to insert validator info list: %v", fpInfoList)
}

return nil
Expand Down
54 changes: 0 additions & 54 deletions internal/packages/duty/finality-provider-indexer/indexer/api.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

commonapi "github.com/cosmostation/cvms/internal/common/api"
"github.com/cosmostation/cvms/internal/common/function"
indexertypes "github.com/cosmostation/cvms/internal/common/indexer/types"
"github.com/cosmostation/cvms/internal/helper"
"github.com/cosmostation/cvms/internal/packages/duty/finality-provider-indexer/model"
Expand Down Expand Up @@ -125,7 +126,7 @@ func (idx *FinalityProviderIndexer) batchSync(lastIndexPointerHeight int64) (
for pk := range item.FinalityProviderVotes {
_, exist := idx.Vim[pk]
if !exist {
// idx.Debugf("the miss finality provider %s isn't in current validator info table, it will be gonna added into the table", pk)
idx.Debugf("the miss finality provider %s isn't in current validator info table, it will be gonna added into the table", pk)
newFinalityProviderMap[pk] = true
isNewFinalityProvider = true
}
Expand All @@ -134,7 +135,7 @@ func (idx *FinalityProviderIndexer) batchSync(lastIndexPointerHeight int64) (

// this logic will be progressed only when there are new tendermint validators in this block
if isNewFinalityProvider {
newfpInfoList, err := GetFinalityProvidersInfo(idx.CommonClient, newFinalityProviderMap, idx.ChainInfoID)
newfpInfoList, err := function.MakeFinalityProviderInfoList(idx.CommonClient, idx.ChainInfoID, newFinalityProviderMap)
if err != nil {
errors.Wrap(err, "failed to make validator info list")
}
Expand Down Expand Up @@ -227,7 +228,7 @@ func makeBabylonFinalityProviderVoteList(
for btcPK, status := range fpVotes {
fpPKID, exist := validatorIDMap[btcPK]
if !exist {
return nil, errors.New("failed to find missed validators hex address id in validator id maps")
return nil, errors.Errorf("failed %s's id in validatorIDMap", btcPK)
}
if status == 0 {
l.Debugf("found missed finality provider idx: %d, address: %s in this block height: %d", validatorIDMap[btcPK], btcPK, missedBlockHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/cosmostation/cvms/internal/common"
"github.com/cosmostation/cvms/internal/common/api"
commonparser "github.com/cosmostation/cvms/internal/common/parser"
"github.com/cosmostation/cvms/internal/helper/logger"
"github.com/cosmostation/cvms/internal/packages/duty/finality-provider-indexer/repository"
Expand Down Expand Up @@ -91,10 +92,7 @@ func TestBatchSync(t *testing.T) {
func TestGetFinalityProvidersInfo(t *testing.T) {
app := common.NewCommonApp(p)
app.SetAPIEndPoint(BabylonBaseURL)

nm := make(map[string]bool, 0)
fpInfoList, err := GetFinalityProvidersInfo(app.CommonClient, nm, 1)

fpInfoList, err := api.GetBabylonFinalityProviderInfos(app.CommonClient)
assert.NoError(t, err)
t.Logf("new fp infos: %d", len(fpInfoList))
for idx, fp := range fpInfoList {
Expand Down
Loading

0 comments on commit 8109dab

Please sign in to comment.