Skip to content

Commit 1ef16a4

Browse files
authored
Merge branch 'cosmostation:develop' into develop
2 parents dd16b50 + 3db36e5 commit 1ef16a4

File tree

5 files changed

+92
-41
lines changed

5 files changed

+92
-41
lines changed

internal/common/api/babylon.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,23 @@ func GetFinalityProviderUptime(c common.CommonClient, fpInfoList []types.Finalit
115115
active := item.Active
116116
vp := item.VotingPower
117117
slashedBTCHeight := item.SlashedBTCHeight
118-
status := "active"
118+
status := 1 // default status is 1, 1 means active
119119
queryPath := types.BabylonFinalityProviderSigninInfoQueryPath(item.BTCPK)
120120
go func(ch chan helper.Result) {
121121
defer helper.HandleOutOfNilResponse(c.Entry)
122122
defer wg.Done()
123123

124124
if jailed {
125-
status = "jailed"
125+
status = 0 // 0 means jailed
126126
}
127127

128128
if slashedBTCHeight > 0 {
129-
status = "slashed"
129+
status = -1 // -1 means slashed
130+
}
131+
132+
activeValue := float64(1)
133+
if !active {
134+
activeValue = float64(0)
130135
}
131136

132137
if !active {
@@ -137,8 +142,8 @@ func GetFinalityProviderUptime(c common.CommonClient, fpInfoList []types.Finalit
137142
Address: Address,
138143
BTCPK: BTCPK,
139144
MissedBlockCounter: 0,
140-
Status: status,
141-
Active: strconv.FormatBool(active),
145+
Status: float64(status),
146+
Active: activeValue,
142147
VotingPower: 0,
143148
}}
144149

@@ -176,8 +181,8 @@ func GetFinalityProviderUptime(c common.CommonClient, fpInfoList []types.Finalit
176181
Address: Address,
177182
BTCPK: BTCPK,
178183
MissedBlockCounter: missedBlockCounter,
179-
Status: status,
180-
Active: strconv.FormatBool(active),
184+
Status: float64(status),
185+
Active: activeValue,
181186
VotingPower: vp,
182187
}}
183188
}(ch)

internal/packages/babylon/btc-lightclient/indexer/indexer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func (idx *BTCLightClientIndexer) Loop(indexPoint int64) {
141141
} else {
142142
// when node already catched up, sleep 5 sec
143143
idx.Infof("updated index pointer to %d and sleep %s sec...", indexPoint, indexertypes.DefaultSleepDuration.String())
144+
time.Sleep(indexertypes.DefaultSleepDuration)
144145
}
145146
}
146147
}

internal/packages/babylon/checkpoint/indexer/batch_sync.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (idx *CheckpointIndexer) batchSync(lastIndexPointerEpoch int64) (
6868

6969
idx.Infof("last finalized epoch(current_epoch -1) is %d and last index pointer epoch is %d", lastFinalizedEpoch, newIndexerPointerEpoch)
7070
for epoch := int64(0); epoch <= lastFinalizedEpoch; epoch++ {
71-
if epoch <= 1 {
71+
if epoch < 1 {
7272
continue
7373
}
7474

@@ -78,7 +78,7 @@ func (idx *CheckpointIndexer) batchSync(lastIndexPointerEpoch int64) (
7878
}
7979

8080
idx.Debugf("sync epoch: %d", epoch)
81-
resp, err := requester.Get(EpochQueryPath(epoch))
81+
resp, err := requester.Get(EpochQueryPath(epoch + 1)) // NOTE: for finding the first block for this epoch, we should use epoch + 1
8282
if err != nil {
8383
return lastIndexPointerEpoch, errors.Wrap(err, "failed to get epoch data")
8484
}
@@ -88,6 +88,8 @@ func (idx *CheckpointIndexer) batchSync(lastIndexPointerEpoch int64) (
8888
return lastIndexPointerEpoch, errors.Wrap(err, "failed to get epoch data")
8989
}
9090

91+
idx.Debugf("found %d first block height in %d epoch", firstBlockHeightInEpoch, epoch)
92+
9193
prevBlockHeight, preBlockTimestamp, preBlockProposerAddress, _, _, _, err := api.GetBlock(idx.CommonClient, firstBlockHeightInEpoch-1)
9294
if err != nil {
9395
idx.Errorf("failed to call at %d height data, %s", prevBlockHeight, err)

internal/packages/babylon/finality-provider/collector/collector.go

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const (
2222
UnHealthSleep = 10 * time.Second
2323

2424
MissedVotesCounterMetricName = "missed_votes_counter"
25+
ActiveMetricName = "active"
26+
StatusMetricName = "status"
27+
2528
VotingPowerMetricName = "voting_power"
2629
SignedVotesWindowMetricName = "signed_votes_window"
2730
MinSignedPerWindowMetricName = "min_signed_per_window"
@@ -66,8 +69,30 @@ func loop(exporter *common.Exporter, p common.Packager) {
6669
common.MonikerLabel,
6770
common.OrchestratorAddressLabel,
6871
common.BTCPKLabel,
69-
common.StatusLabel,
70-
common.ActiveLabel,
72+
})
73+
74+
activeMetric := p.Factory.NewGaugeVec(prometheus.GaugeOpts{
75+
Namespace: common.Namespace,
76+
Subsystem: Subsystem,
77+
Name: ActiveMetricName,
78+
ConstLabels: packageLabels,
79+
Help: "active status of finality provider, 1 means active, 0 means inactive",
80+
}, []string{
81+
common.MonikerLabel,
82+
common.OrchestratorAddressLabel,
83+
common.BTCPKLabel,
84+
})
85+
86+
statusMetric := p.Factory.NewGaugeVec(prometheus.GaugeOpts{
87+
Namespace: common.Namespace,
88+
Subsystem: Subsystem,
89+
Name: StatusMetricName,
90+
ConstLabels: packageLabels,
91+
Help: "specific status of finality provider, 1 means active, 0 means jailed, -1 means slashed",
92+
}, []string{
93+
common.MonikerLabel,
94+
common.OrchestratorAddressLabel,
95+
common.BTCPKLabel,
7196
})
7297

7398
vpMetric := p.Factory.NewGaugeVec(prometheus.GaugeOpts{
@@ -79,8 +104,6 @@ func loop(exporter *common.Exporter, p common.Packager) {
79104
common.MonikerLabel,
80105
common.OrchestratorAddressLabel,
81106
common.BTCPKLabel,
82-
common.StatusLabel,
83-
common.ActiveLabel,
84107
})
85108

86109
// metrics for each chain
@@ -183,22 +206,32 @@ func loop(exporter *common.Exporter, p common.Packager) {
183206
common.MonikerLabel: item.Moniker,
184207
common.BTCPKLabel: item.BTCPK,
185208
common.OrchestratorAddressLabel: item.Address,
186-
common.StatusLabel: item.Status,
187-
common.ActiveLabel: item.Active,
188209
}).
189210
Set(float64(item.MissedBlockCounter))
190211

191-
if item.VotingPower != 0 {
192-
vpMetric.
193-
With(prometheus.Labels{
194-
common.MonikerLabel: item.Moniker,
195-
common.BTCPKLabel: item.BTCPK,
196-
common.OrchestratorAddressLabel: item.Address,
197-
common.StatusLabel: item.Status,
198-
common.ActiveLabel: item.Active,
199-
}).
200-
Set(item.VotingPower)
201-
}
212+
vpMetric.
213+
With(prometheus.Labels{
214+
common.MonikerLabel: item.Moniker,
215+
common.BTCPKLabel: item.BTCPK,
216+
common.OrchestratorAddressLabel: item.Address,
217+
}).
218+
Set(item.VotingPower)
219+
220+
activeMetric.
221+
With(prometheus.Labels{
222+
common.MonikerLabel: item.Moniker,
223+
common.BTCPKLabel: item.BTCPK,
224+
common.OrchestratorAddressLabel: item.Address,
225+
}).
226+
Set(item.Active)
227+
228+
statusMetric.
229+
With(prometheus.Labels{
230+
common.MonikerLabel: item.Moniker,
231+
common.BTCPKLabel: item.BTCPK,
232+
common.OrchestratorAddressLabel: item.Address,
233+
}).
234+
Set(item.Status)
202235
}
203236

204237
fpTotalMetric.With(prometheus.Labels{common.StatusLabel: "active"}).Set(float64(status.FinalityProviderTotal.Active))
@@ -213,22 +246,32 @@ func loop(exporter *common.Exporter, p common.Packager) {
213246
common.MonikerLabel: item.Moniker,
214247
common.BTCPKLabel: item.BTCPK,
215248
common.OrchestratorAddressLabel: item.Address,
216-
common.StatusLabel: item.Status,
217-
common.ActiveLabel: item.Active,
218249
}).
219250
Set(float64(item.MissedBlockCounter))
220251

221-
if item.VotingPower != 0 {
222-
vpMetric.
223-
With(prometheus.Labels{
224-
common.MonikerLabel: item.Moniker,
225-
common.BTCPKLabel: item.BTCPK,
226-
common.OrchestratorAddressLabel: item.Address,
227-
common.StatusLabel: item.Status,
228-
common.ActiveLabel: item.Active,
229-
}).
230-
Set(item.VotingPower)
231-
}
252+
vpMetric.
253+
With(prometheus.Labels{
254+
common.MonikerLabel: item.Moniker,
255+
common.BTCPKLabel: item.BTCPK,
256+
common.OrchestratorAddressLabel: item.Address,
257+
}).
258+
Set(item.VotingPower)
259+
260+
activeMetric.
261+
With(prometheus.Labels{
262+
common.MonikerLabel: item.Moniker,
263+
common.BTCPKLabel: item.BTCPK,
264+
common.OrchestratorAddressLabel: item.Address,
265+
}).
266+
Set(item.Active)
267+
268+
statusMetric.
269+
With(prometheus.Labels{
270+
common.MonikerLabel: item.Moniker,
271+
common.BTCPKLabel: item.BTCPK,
272+
common.OrchestratorAddressLabel: item.Address,
273+
}).
274+
Set(item.Status)
232275
}
233276
}
234277
}

internal/packages/babylon/finality-provider/types/status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type FinalityProviderUptimeStatus struct {
1313
Address string
1414
BTCPK string
1515
MissedBlockCounter float64
16-
Active string
17-
Status string
16+
Active float64
17+
Status float64
1818
VotingPower float64
1919
}
2020

0 commit comments

Comments
 (0)