Skip to content

Commit 327b898

Browse files
committed
Add slot timing metrics
1 parent 0589b9d commit 327b898

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

rolling-shutter/keyperimpl/gnosis/messagingmiddleware.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"database/sql"
77
"fmt"
8+
"time"
89

910
"github.com/jackc/pgx/v4"
1011
"github.com/jackc/pgx/v4/pgxpool"
@@ -17,6 +18,7 @@ import (
1718
corekeyperdatabase "github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database"
1819
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/gnosis/database"
1920
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/gnosis/gnosisssztypes"
21+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley"
2022
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/identitypreimage"
2123
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/retry"
2224
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
@@ -173,14 +175,21 @@ func (i *MessagingMiddleware) interceptDecryptionKeyShares(
173175
)
174176
}
175177

176-
msg := proto.Clone(originalMsg).(*p2pmsg.DecryptionKeyShares)
177-
msg.Extra = &p2pmsg.DecryptionKeyShares_Gnosis{
178-
Gnosis: &p2pmsg.GnosisDecryptionKeySharesExtra{
179-
Slot: uint64(currentDecryptionTrigger.Slot),
180-
TxPointer: uint64(currentDecryptionTrigger.TxPointer),
181-
Signature: signature,
182-
},
178+
extra := &p2pmsg.GnosisDecryptionKeySharesExtra{
179+
Slot: uint64(currentDecryptionTrigger.Slot),
180+
TxPointer: uint64(currentDecryptionTrigger.TxPointer),
181+
Signature: signature,
183182
}
183+
msg := proto.Clone(originalMsg).(*p2pmsg.DecryptionKeyShares)
184+
msg.Extra = &p2pmsg.DecryptionKeyShares_Gnosis{Gnosis: extra}
185+
slotStartTimestamp := medley.SlotToTimestamp(
186+
extra.Slot,
187+
i.config.Gnosis.GenesisSlotTimestamp,
188+
i.config.Gnosis.SecondsPerSlot,
189+
)
190+
slotStartTime := time.Unix(int64(slotStartTimestamp), 0)
191+
delta := time.Since(slotStartTime)
192+
metricsKeySharesSentTimeDelta.WithLabelValues(fmt.Sprint(originalMsg.Eon)).Observe(delta.Seconds())
184193
return msg, nil
185194
}
186195

@@ -267,6 +276,15 @@ func (i *MessagingMiddleware) interceptDecryptionKeys(
267276
Int("num-signatures", len(signaturesDB)).
268277
Int("num-keys", len(msg.Keys)).
269278
Msg("sending keys")
279+
280+
slotStartTimestamp := medley.SlotToTimestamp(
281+
extra.Slot,
282+
i.config.Gnosis.GenesisSlotTimestamp,
283+
i.config.Gnosis.SecondsPerSlot,
284+
)
285+
slotStartTime := time.Unix(int64(slotStartTimestamp), 0)
286+
delta := time.Since(slotStartTime)
287+
metricsKeysSentTimeDelta.WithLabelValues(fmt.Sprint(originalMsg.Eon)).Observe(delta.Seconds())
270288
return msg, nil
271289
}
272290

rolling-shutter/keyperimpl/gnosis/metrics.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,37 @@ var metricsNumValidatorRegistrations = prometheus.NewGauge(
5959
},
6060
)
6161

62+
var slotTimeDeltaBuckets = []float64{-5, -4.5, -4.0, -3.5, -3.0, -2.5, -2.0, -1.5, -1.0, -0.5, -0, 1.0, 100}
63+
64+
var metricsKeysSentTimeDelta = prometheus.NewHistogramVec(
65+
prometheus.HistogramOpts{
66+
Namespace: "shutter",
67+
Subsystem: "gnosis",
68+
Name: "keys_sent_time_delta_seconds",
69+
Help: "Time at which keys are sent relative to slot",
70+
Buckets: slotTimeDeltaBuckets,
71+
},
72+
[]string{"eon"},
73+
)
74+
75+
var metricsKeySharesSentTimeDelta = prometheus.NewHistogramVec(
76+
prometheus.HistogramOpts{
77+
Namespace: "shutter",
78+
Subsystem: "gnosis",
79+
Name: "key_shares_sent_time_delta_seconds",
80+
Help: "Time at which key shares are sent relative to slot",
81+
Buckets: slotTimeDeltaBuckets,
82+
},
83+
[]string{"eon"},
84+
)
85+
6286
func init() {
6387
prometheus.MustRegister(metricsTxPointer)
6488
prometheus.MustRegister(metricsTxPointerAge)
6589
prometheus.MustRegister(metricsLatestTxSubmittedEventIndex)
6690
prometheus.MustRegister(metricsTxSubmittedEventsSyncedUntil)
6791
prometheus.MustRegister(metricsValidatorRegistrationsSyncedUntil)
6892
prometheus.MustRegister(metricsNumValidatorRegistrations)
93+
prometheus.MustRegister(metricsKeysSentTimeDelta)
94+
prometheus.MustRegister(metricsKeySharesSentTimeDelta)
6995
}

rolling-shutter/medley/slots.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ func BlockTimestampToSlot(blockTimestamp uint64, genesisSlotTimestamp uint64, se
77
func SlotToEpoch(slot uint64, slotsPerEpoch uint64) uint64 {
88
return slot / slotsPerEpoch
99
}
10+
11+
func SlotToTimestamp(slot uint64, genesisSlotTimestamp uint64, secondsPerSlot uint64) uint64 {
12+
return genesisSlotTimestamp + slot*secondsPerSlot
13+
}

0 commit comments

Comments
 (0)