Skip to content

Commit aed19fb

Browse files
authored
Merge pull request #407 from shutter-network/ezdac/shmtlogging
feat: improve logging in shuttermint
2 parents fda9cd0 + fe1e8bf commit aed19fb

File tree

5 files changed

+85
-21
lines changed

5 files changed

+85
-21
lines changed

rolling-shutter/keyper/fx/send.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func SendShutterMessages(
3333
if err != nil {
3434
return err // XXX retry
3535
}
36-
log.Info().Int32("id", outgoing.ID).Str("description", outgoing.Description).
36+
log.Info().Int32("id", outgoing.ID).
37+
Str("description", outgoing.Description).
3738
Msg("send shuttermint message")
3839
err = queries.DeleteShutterMessage(ctx, outgoing.ID)
3940
if err != nil {

rolling-shutter/keyper/keyper.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keyper
33

44
import (
55
"context"
6+
"fmt"
67
"time"
78

89
"github.com/ethereum/go-ethereum/ethclient"
@@ -172,7 +173,7 @@ func (kpr *keyper) handleOnChainChanges(
172173
tx pgx.Tx,
173174
l1BlockNumber uint64,
174175
) error {
175-
log.Info().Uint64("l1-block-number", l1BlockNumber).Msg("handle on chain changes")
176+
log.Debug().Uint64("l1-block-number", l1BlockNumber).Msg("handle on chain changes")
176177
err := kpr.handleOnChainKeyperSetChanges(ctx, tx, l1BlockNumber)
177178
if err != nil {
178179
return err
@@ -208,7 +209,11 @@ func (kpr *keyper) sendNewBlockSeen(ctx context.Context, tx pgx.Tx, l1BlockNumbe
208209
}
209210

210211
blockSeenMsg := shmsg.NewBlockSeen(l1BlockNumber)
211-
err = q.ScheduleShutterMessage(ctx, "block seen", blockSeenMsg)
212+
err = q.ScheduleShutterMessage(
213+
ctx,
214+
fmt.Sprintf("block seen (block=%d)", l1BlockNumber),
215+
blockSeenMsg,
216+
)
212217
if err != nil {
213218
return err
214219
}
@@ -289,7 +294,12 @@ func (kpr *keyper) handleOnChainKeyperSetChanges(
289294
uint64(keyperSet.Threshold),
290295
uint64(keyperSet.KeyperConfigIndex),
291296
)
292-
err = q.ScheduleShutterMessage(ctx, "new batch config", batchConfigMsg)
297+
err = q.ScheduleShutterMessage(
298+
ctx,
299+
fmt.Sprintf("new batch config (activation-block-number=%d, config-index=%d)",
300+
keyperSet.ActivationBlockNumber, keyperSet.KeyperConfigIndex),
301+
batchConfigMsg,
302+
)
293303
if err != nil {
294304
return err
295305
}

rolling-shutter/keyper/shutterevents/events.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type Accusation struct {
3030

3131
func (acc *Accusation) String() string {
3232
return fmt.Sprintf(
33-
"Accusation{Height: %d, Eon: %d, Sender: %s, Accused: %s}",
34-
acc.Height, acc.Eon, acc.Sender, acc.Accused)
33+
"Accusation{Height=%d, Eon=%d, Sender=%s, Accused=%s}",
34+
acc.Height, acc.Eon, acc.Sender.String(), encodeAddresses(acc.Accused))
3535
}
3636

3737
func (acc Accusation) MakeABCIEvent() abcitypes.Event {
@@ -104,8 +104,8 @@ type Apology struct {
104104

105105
func (msg *Apology) String() string {
106106
return fmt.Sprintf(
107-
"Apology{Height: %d, Eon: %d, Sender: %s, Accusers: %s}",
108-
msg.Height, msg.Eon, msg.Sender, msg.Accusers)
107+
"Apology{Height=%d, Eon=%d, Sender=%s, Accusers=%s}",
108+
msg.Height, msg.Eon, msg.Sender, encodeAddresses(msg.Accusers))
109109
}
110110

111111
func (msg Apology) MakeABCIEvent() abcitypes.Event {
@@ -178,6 +178,19 @@ type BatchConfig struct {
178178
ValidatorsUpdated bool
179179
}
180180

181+
func (bc *BatchConfig) String() string {
182+
return fmt.Sprintf(
183+
"BatchConfig{Height=%d, Keypers=%s, ActivationBlockNumber=%d, Threshold=%d, ConfigIndex=%d, Started=%t, ValidatorsUpdated=%t}",
184+
bc.Height,
185+
encodeAddresses(bc.Keypers),
186+
bc.ActivationBlockNumber,
187+
bc.Threshold,
188+
bc.KeyperConfigIndex,
189+
bc.Started,
190+
bc.ValidatorsUpdated,
191+
)
192+
}
193+
181194
func (bc BatchConfig) MakeABCIEvent() abcitypes.Event {
182195
return abcitypes.Event{
183196
Type: evtype.BatchConfig,
@@ -255,6 +268,14 @@ func (bcs BatchConfigStarted) MakeABCIEvent() abcitypes.Event {
255268
}
256269
}
257270

271+
func (bcs *BatchConfigStarted) String() string {
272+
return fmt.Sprintf(
273+
"BatchConfigStarted{Height=%d, ConfigIndex=%d}",
274+
bcs.Height,
275+
bcs.KeyperConfigIndex,
276+
)
277+
}
278+
258279
// makeBatchConfigStarted creates a BatchConfigEvent from the given tendermint event of type
259280
// "shutter.batch-config-started".
260281
func makeBatchConfigStarted(ev abcitypes.Event, height int64) (*BatchConfigStarted, error) {
@@ -292,6 +313,14 @@ func (msg CheckIn) MakeABCIEvent() abcitypes.Event {
292313
}
293314
}
294315

316+
func (msg *CheckIn) String() string {
317+
return fmt.Sprintf(
318+
"CheckIn{Height=%d, Sender=%s}",
319+
msg.Height,
320+
msg.Sender.String(),
321+
)
322+
}
323+
295324
// makeCheckIn creates a CheckInEvent from the given tendermint event of type "shutter.check-in".
296325
func makeCheckIn(ev abcitypes.Event, height int64) (*CheckIn, error) {
297326
err := expectAttributes(ev, "Sender", "EncryptionPublicKey")
@@ -335,6 +364,16 @@ func (msg EonStarted) MakeABCIEvent() abcitypes.Event {
335364
}
336365
}
337366

367+
func (msg *EonStarted) String() string {
368+
return fmt.Sprintf(
369+
"EonStarted{Height=%d, Eon=%d, ActivationBlockNumber=%d, ConfigIndex=%d}",
370+
msg.Height,
371+
msg.Eon,
372+
msg.ActivationBlockNumber,
373+
msg.KeyperConfigIndex,
374+
)
375+
}
376+
338377
// PolyCommitment represents a broadcasted polynomial commitment message.
339378
type PolyCommitment struct {
340379
Height int64
@@ -348,7 +387,7 @@ func (msg *PolyCommitment) String() string {
348387
"PolyCommitment{Height=%d, Eon=%d, Sender=%s}",
349388
msg.Height,
350389
msg.Eon,
351-
msg.Sender,
390+
msg.Sender.String(),
352391
)
353392
}
354393

@@ -402,11 +441,11 @@ type PolyEval struct {
402441

403442
func (msg *PolyEval) String() string {
404443
return fmt.Sprintf(
405-
"PolyEval{Height: %d, Sender: %s, Eon: %d, Receivers: %s}",
444+
"PolyEval{Height=%d, Sender=%s, Eon=%d, Receivers=%s}",
406445
msg.Height,
407446
msg.Sender,
408447
msg.Eon,
409-
msg.Receivers)
448+
encodeAddresses(msg.Receivers))
410449
}
411450

412451
func (msg PolyEval) MakeABCIEvent() abcitypes.Event {
@@ -459,6 +498,7 @@ func makePolyEval(ev abcitypes.Event, height int64) (*PolyEval, error) {
459498
// IEvent is an interface for the event types declared above.
460499
type IEvent interface {
461500
MakeABCIEvent() abcitypes.Event
501+
String() string
462502
}
463503

464504
// makeEonStarted creates a EonStartedEvent from the given tendermint event of type

rolling-shutter/keyper/smobserver/smstate.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/ed25519"
66
"crypto/rand"
77
"database/sql"
8+
"encoding/hex"
89
"fmt"
910
"math"
1011
"math/big"
@@ -199,7 +200,7 @@ func (st *ShuttermintState) sendPolyEvals(ctx context.Context, queries *kprdb.Qu
199200
}()
200201
return queries.ScheduleShutterMessage(
201202
ctx,
202-
fmt.Sprintf("poly eval eon=%d", currentEon),
203+
fmt.Sprintf("poly eval (eon=%d)", currentEon),
203204
shmsg.NewPolyEval(uint64(currentEon), receivers, encryptedEvals),
204205
)
205206
}
@@ -248,11 +249,12 @@ func (st *ShuttermintState) handleBatchConfig(
248249
return nil
249250
}
250251
st.isKeyper = true
252+
pubKey := st.config.GetValidatorPublicKey()
251253
err := queries.ScheduleShutterMessage(
252254
ctx,
253-
"check-in",
255+
fmt.Sprintf("check-in (validator-pub-key=%s)", hex.EncodeToString(pubKey)),
254256
shmsg.NewCheckIn(
255-
st.config.GetValidatorPublicKey(),
257+
pubKey,
256258
&st.config.GetEncryptionKey().PublicKey,
257259
),
258260
)
@@ -362,7 +364,7 @@ func (st *ShuttermintState) startPhase1Dealing(
362364
dkg.markDirty()
363365
err = queries.ScheduleShutterMessage(
364366
ctx,
365-
fmt.Sprintf("poly commitment, eon=%d", eon),
367+
fmt.Sprintf("poly commitment (eon=%d)", eon),
366368
shmsg.NewPolyCommitment(eon, commitment.Gammas),
367369
)
368370
if err != nil {
@@ -394,7 +396,7 @@ func (st *ShuttermintState) startPhase2Accusing(
394396
}
395397
err := queries.ScheduleShutterMessage(
396398
ctx,
397-
fmt.Sprintf("accusations, eon=%d, count=%d", eon, len(accusations)),
399+
fmt.Sprintf("accusations (eon=%d, count=%d)", eon, len(accusations)),
398400
shmsg.NewAccusation(eon, accused),
399401
)
400402
if err != nil {
@@ -423,7 +425,7 @@ func (st *ShuttermintState) startPhase3Apologizing(
423425

424426
err := queries.ScheduleShutterMessage(
425427
ctx,
426-
fmt.Sprintf("apologies, eon=%d, count=%d", eon, len(apologies)),
428+
fmt.Sprintf("apologies (eon=%d, count=%d)", eon, len(apologies)),
427429
shmsg.NewApology(eon, accusers, polyEvals),
428430
)
429431
if err != nil {
@@ -485,7 +487,7 @@ func (st *ShuttermintState) finalizeDKG(
485487

486488
err = queries.ScheduleShutterMessage(
487489
ctx,
488-
"reporting DKG result",
490+
fmt.Sprintf("reporting DKG result (eon=%d)", dkgresult.Eon),
489491
dkgresultmsg,
490492
)
491493
if err != nil {
@@ -737,6 +739,7 @@ func (st *ShuttermintState) HandleEvent(
737739
ctx context.Context, queries *kprdb.Queries, event shutterevents.IEvent,
738740
) error {
739741
var err error
742+
log.Info().Str("event", event.String()).Msg("handle shuttermint event")
740743
switch e := event.(type) {
741744
case *shutterevents.CheckIn:
742745
err = st.handleCheckIn(ctx, queries, e)

rolling-shutter/snapshotkeyper/snapshotkeyper.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package snapshotkeyper
33

44
import (
55
"context"
6+
"fmt"
67
"time"
78

89
"github.com/ethereum/go-ethereum/ethclient"
@@ -139,7 +140,7 @@ func (snkpr *snapshotkeyper) handleContractEvents(ctx context.Context) error {
139140
}
140141

141142
func (snkpr *snapshotkeyper) handleOnChainChanges(ctx context.Context, tx pgx.Tx, l1BlockNumber uint64) error {
142-
log.Info().Uint64("l1-block-number", l1BlockNumber).Msg("handle on chain changes")
143+
log.Debug().Uint64("l1-block-number", l1BlockNumber).Msg("handle on chain changes")
143144
err := snkpr.handleOnChainKeyperSetChanges(ctx, tx, l1BlockNumber)
144145
if err != nil {
145146
return err
@@ -179,7 +180,11 @@ func (snkpr *snapshotkeyper) sendNewBlockSeen(
179180
}
180181

181182
blockSeenMsg := shmsg.NewBlockSeen(l1BlockNumber)
182-
err = q.ScheduleShutterMessage(ctx, "block seen", blockSeenMsg)
183+
err = q.ScheduleShutterMessage(
184+
ctx,
185+
fmt.Sprintf("block seen (block=%d)", l1BlockNumber),
186+
blockSeenMsg,
187+
)
183188
if err != nil {
184189
return err
185190
}
@@ -253,7 +258,12 @@ func (snkpr *snapshotkeyper) handleOnChainKeyperSetChanges(ctx context.Context,
253258
uint64(keyperSet.Threshold),
254259
uint64(keyperSet.KeyperConfigIndex),
255260
)
256-
err = q.ScheduleShutterMessage(ctx, "new batch config", batchConfigMsg)
261+
err = q.ScheduleShutterMessage(
262+
ctx,
263+
fmt.Sprintf("new batch config (activation-block-number=%d, config-index=%d)",
264+
keyperSet.ActivationBlockNumber, keyperSet.KeyperConfigIndex),
265+
batchConfigMsg,
266+
)
257267
if err != nil {
258268
return err
259269
}

0 commit comments

Comments
 (0)