Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ jobs:
CIRCLE_BRANCH=${BRANCHES##*/}
echo "CIRCLE_BRANCH is empty, trying to set it from git, result: $CIRCLE_BRANCH"
fi
if [[ $CIRCLE_BRANCH != "main" && ! $CIRCLE_TAG =~ (a|b|rc) ]]; then
echo "Final release tags are only allowed on main branch."
if [[ $CIRCLE_BRANCH != "main" && \
! $CIRCLE_BRANCH =~ ^release/v[0-9]+\.[0-9]+(\.[0-9]+)?$ && \
! $CIRCLE_TAG =~ (a|b|rc) ]]; then
echo "Final release tags are only allowed from main or release/vX.Y(.Z) branches."
exit 1
else
DOCKER_TAG=${DOCKER_BASE}/keyper:${CIRCLE_TAG}
Expand Down
29 changes: 29 additions & 0 deletions rolling-shutter/keyper/keypermetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import (
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync"
)

const (
DKGMessageTypePolyEval = "poly_eval"
DKGMessageTypePolyCommitment = "poly_commitment"
DKGMessageTypeAccusation = "accusation"
DKGMessageTypeApology = "apology"
)

var MetricsKeyperCurrentBlockL1 = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "shutter",
Expand Down Expand Up @@ -71,6 +78,26 @@ var MetricsKeyperCurrentPhase = prometheus.NewGaugeVec(
[]string{"eon", "phase"},
)

var MetricsKeyperDKGMessagesSent = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "shutter",
Subsystem: "keyper",
Name: "dkg_messages_sent",
Help: "Number of DKG messages scheduled for sending for the given eon, partitioned by message type",
},
[]string{"eon", "message_type"},
)

var MetricsKeyperDKGMessagesReceived = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "shutter",
Subsystem: "keyper",
Name: "dkg_messages_received",
Help: "Number of DKG messages received for the given eon, partitioned by message type",
},
[]string{"eon", "message_type"},
)

var MetricsKeyperCurrentBatchConfigIndex = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "shutter",
Expand Down Expand Up @@ -128,6 +155,8 @@ func InitMetrics(dbpool *pgxpool.Pool, config kprconfig.Config) {
prometheus.MustRegister(MetricsKeyperDKGStatus)
prometheus.MustRegister(MetricsKeyperEthAddress)
prometheus.MustRegister(MetricsExecutionClientVersion)
prometheus.MustRegister(MetricsKeyperDKGMessagesSent)
prometheus.MustRegister(MetricsKeyperDKGMessagesReceived)

ctx := context.Background()
queries := database.New(dbpool)
Expand Down
10 changes: 9 additions & 1 deletion rolling-shutter/keyper/smobserver/smdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ func (smdrv *ShuttermintDriver) handleBlock(
block *coretypes.ResultBlockResults,
lastCommittedHeight int64,
) error {
err := smdrv.shuttermintState.Load(ctx, queries)
if err != nil {
return err
}
oldMeta, err := queries.TMGetSyncMeta(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -217,7 +221,11 @@ func (smdrv *ShuttermintDriver) handleBlock(
return err
}

return nil
err = smdrv.shuttermintState.BeforeSaveHook(ctx, queries)
if err != nil {
return err
}
return smdrv.shuttermintState.Save(ctx, queries)
}

func (smdrv *ShuttermintDriver) innerHandleTransactions(
Expand Down
54 changes: 52 additions & 2 deletions rolling-shutter/keyper/smobserver/smstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,22 @@ func (st *ShuttermintState) sendPolyEvals(ctx context.Context, queries *database
receivers = nil
encryptedEvals = nil
}()
return queries.ScheduleShutterMessage(
eonLabel := strconv.FormatInt(currentEon, 10)
err := queries.ScheduleShutterMessage(
ctx,
fmt.Sprintf("poly eval (eon=%d)", currentEon),
shmsg.NewPolyEval(uint64(currentEon), receivers, encryptedEvals),
)
if err != nil {
return err
}
for range receivers {
keypermetrics.MetricsKeyperDKGMessagesSent.WithLabelValues(
eonLabel,
keypermetrics.DKGMessageTypePolyEval,
).Inc()
}
Comment on lines +214 to +219
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use .Add() instead to pass a number directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't like add because it takes a float, but I guess that just means it's float internally anyway

return nil
}

for _, eval := range evals {
Expand All @@ -218,7 +229,10 @@ func (st *ShuttermintState) sendPolyEvals(ctx context.Context, queries *database
currentEon = eval.Eon
}

fmt.Printf("SEND POLY EVALS: eon=%d receiver=%s\n", eval.Eon, eval.ReceiverAddress)
log.Info().
Int64("eon", eval.Eon).
Str("receiverAddress", eval.ReceiverAddress).
Msg("sending poly eval")
receiver, err := shdb.DecodeAddress(eval.ReceiverAddress)
if err != nil {
return err
Expand Down Expand Up @@ -386,6 +400,7 @@ func (st *ShuttermintState) startPhase1Dealing(
log.Fatal().Err(err).Msg("aborting due to unexpected error")
}
dkg.markDirty()
eonLabel := strconv.FormatUint(eon, 10)
err = queries.ScheduleShutterMessage(
ctx,
fmt.Sprintf("poly commitment (eon=%d)", eon),
Expand All @@ -394,6 +409,10 @@ func (st *ShuttermintState) startPhase1Dealing(
if err != nil {
return err
}
keypermetrics.MetricsKeyperDKGMessagesSent.WithLabelValues(
eonLabel,
keypermetrics.DKGMessageTypePolyCommitment,
).Inc()

for _, eval := range polyEvals {
err = queries.InsertPolyEval(ctx, database.InsertPolyEvalParams{
Expand All @@ -413,9 +432,14 @@ func (st *ShuttermintState) startPhase2Accusing(
) error {
accusations := dkg.pure.StartPhase2Accusing()
dkg.markDirty()
eonLabel := strconv.FormatUint(eon, 10)
if len(accusations) > 0 {
var accused []common.Address
for _, a := range accusations {
keypermetrics.MetricsKeyperDKGMessagesSent.WithLabelValues(
eonLabel,
keypermetrics.DKGMessageTypeAccusation,
).Inc()
accused = append(accused, dkg.keypers[a.Accused])
}
err := queries.ScheduleShutterMessage(
Expand All @@ -438,11 +462,16 @@ func (st *ShuttermintState) startPhase3Apologizing(
) error {
apologies := dkg.pure.StartPhase3Apologizing()
dkg.markDirty()
eonLabel := strconv.FormatUint(eon, 10)
if len(apologies) > 0 {
var accusers []common.Address
var polyEvals []*big.Int

for _, a := range apologies {
keypermetrics.MetricsKeyperDKGMessagesSent.WithLabelValues(
eonLabel,
keypermetrics.DKGMessageTypeApology,
).Inc()
accusers = append(accusers, dkg.keypers[a.Accuser])
polyEvals = append(polyEvals, a.Eval)
}
Expand Down Expand Up @@ -621,6 +650,10 @@ func (st *ShuttermintState) handlePolyCommitment(
return nil
}
dkg.markDirty()
keypermetrics.MetricsKeyperDKGMessagesReceived.WithLabelValues(
strconv.FormatUint(e.Eon, 10),
keypermetrics.DKGMessageTypePolyCommitment,
).Inc()
return nil
}

Expand All @@ -642,6 +675,7 @@ func (st *ShuttermintState) handlePolyEval(
Msg("event for non existent eon received")
return nil
}
eonLabel := strconv.FormatUint(e.Eon, 10)
sender, err := medley.FindAddressIndex(dkg.keypers, e.Sender)
if err != nil {
return nil
Expand Down Expand Up @@ -678,6 +712,10 @@ func (st *ShuttermintState) handlePolyEval(
}
log.Info().Str("event", e.String()).Int("keyper", sender).
Msg("got poly eval message")
keypermetrics.MetricsKeyperDKGMessagesReceived.WithLabelValues(
eonLabel,
keypermetrics.DKGMessageTypePolyEval,
).Inc()
dkg.markDirty()
return nil
}
Expand All @@ -697,6 +735,7 @@ func (st *ShuttermintState) handleAccusation(
Msg("received accusation in wrong phase")
return nil
}
eonLabel := strconv.FormatUint(e.Eon, 10)
sender, err := medley.FindAddressIndex(dkg.keypers, e.Sender)
if err != nil {
log.Info().Str("event", e.String()).
Expand All @@ -721,7 +760,12 @@ func (st *ShuttermintState) handleAccusation(
if err != nil {
log.Info().Str("event", e.String()).Err(err).
Msg("cannot handle accusation")
continue
}
keypermetrics.MetricsKeyperDKGMessagesReceived.WithLabelValues(
eonLabel,
keypermetrics.DKGMessageTypeAccusation,
).Inc()
}
dkg.markDirty()
return nil
Expand All @@ -741,6 +785,7 @@ func (st *ShuttermintState) handleApology(
Msg("Warning: received apology in wrong phase")
return nil
}
eonLabel := strconv.FormatUint(e.Eon, 10)
sender, err := medley.FindAddressIndex(dkg.keypers, e.Sender)
if err != nil {
log.Info().Str("event", e.String()).Msg("failed to handle apology. bad sender")
Expand All @@ -763,7 +808,12 @@ func (st *ShuttermintState) handleApology(
})
if err != nil {
log.Info().Str("event", e.String()).Err(err).Msg("failed to handle apology")
continue
}
keypermetrics.MetricsKeyperDKGMessagesReceived.WithLabelValues(
eonLabel,
keypermetrics.DKGMessageTypeApology,
).Inc()
}
dkg.markDirty()
return nil
Expand Down