diff --git a/signer/sign_state.go b/signer/sign_state.go index 825ddf35..b8bcf1ba 100644 --- a/signer/sign_state.go +++ b/signer/sign_state.go @@ -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, @@ -376,7 +376,7 @@ func (signState *SignState) CheckHRS(hrst HRSTKey) (bool, error) { } return true, nil } - return false, EmptySignBytesError + return false, ErrEmptySignBytes } } } diff --git a/signer/threshold_validator.go b/signer/threshold_validator.go index 723723d1..55449c59 100644 --- a/signer/threshold_validator.go +++ b/signer/threshold_validator.go @@ -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 } @@ -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() @@ -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 } @@ -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(), ) @@ -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") && @@ -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