Skip to content

Commit

Permalink
improve logs, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Nov 17, 2023
1 parent 2a5d6f7 commit e80a36a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions signer/sign_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func newStepRegressionError(height, round int64, regressed, last int8) *StepRegr
}
}

var EmptySignBytesError = errors.New("no SignBytes found")
var ErrEmptySignBytes = errors.New("no SignBytes found")

// CheckHRS checks the given height, round, step (HRS) against that of the
// SignState. It returns an error if the arguments constitute a regression,
Expand Down Expand Up @@ -376,7 +376,7 @@ func (signState *SignState) CheckHRS(hrst HRSTKey) (bool, error) {
}
return true, nil
}
return false, EmptySignBytesError
return false, ErrEmptySignBytes
}
}
}
Expand Down
34 changes: 16 additions & 18 deletions signer/threshold_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ func (pv *ThresholdValidator) proxyIfNecessary(
func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Block) ([]byte, time.Time, error) {
height, round, step, stamp, signBytes := block.Height, block.Round, block.Step, block.Timestamp, block.SignBytes

log := pv.logger.With(
"chain_id", chainID,
"height", height,
"round", round,
"type", signType(step),
)

if err := pv.LoadSignStateIfNecessary(chainID); err != nil {
return nil, stamp, err
}
Expand All @@ -623,13 +630,8 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl
}

totalRaftLeader.Inc()
pv.logger.Debug(
"I am the leader. Managing the sign process for this block",
"chain_id", chainID,
"height", height,
"round", round,
"step", step,
)

log.Debug("I am the leader. Managing the sign process for this block")

timeStartSignBlock := time.Now()

Expand All @@ -646,7 +648,7 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl
return nil, stamp, fmt.Errorf("error saving last sign state initiated: %w", err)
}
if existingSignature != nil {
pv.logger.Debug("Returning existing signature", "signature", fmt.Sprintf("%x", existingSignature))
log.Debug("Returning existing signature", "signature", fmt.Sprintf("%x", existingSignature))
return existingSignature, existingTimestamp, nil
}

Expand Down Expand Up @@ -723,9 +725,9 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl
SignBytes: signBytes,
})
if err != nil {
pv.logger.Error(
log.Error(
"Cosigner failed to set nonces and sign",
"id", cosigner.GetID(),
"cosigner", cosigner.GetID(),
"err", err.Error(),
)

Expand All @@ -735,7 +737,7 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl

// TODO how can we determine error type when it's wrapped in an RPCError?
if !strings.Contains(err.Error(), "regression") &&
!strings.Contains(err.Error(), EmptySignBytesError.Error()) &&
!strings.Contains(err.Error(), ErrEmptySignBytes.Error()) &&
!strings.Contains(err.Error(), "refusing to sign") &&
!strings.Contains(err.Error(), "differing block IDs") &&
!strings.Contains(err.Error(), "conflicting data") &&
Expand Down Expand Up @@ -842,20 +844,16 @@ func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Bl
if err != nil {
// this is not required for double sign protection, so we don't need to return an error here.
// this is only an additional mechanism that will catch double signs earlier in the sign process.
pv.logger.Error("Error emitting LSS", err.Error())
log.Error("Error emitting LSS", err.Error())
}

timeSignBlock := time.Since(timeStartSignBlock)
timeSignBlockSec := timeSignBlock.Seconds()
timedSignBlockLag.Observe(timeSignBlockSec)

pv.logger.Info(
log.Info(
"Signed",
"chain_id", chainID,
"height", height,
"round", round,
"type", signType(step),
"duration_ms", timeSignBlock.Round(time.Millisecond),
"duration_ms", float64(timeSignBlock.Microseconds())/1000,
)

return signature, stamp, nil
Expand Down

0 comments on commit e80a36a

Please sign in to comment.