Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Jan 9, 2024
1 parent 71b0045 commit f8a45c6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
3 changes: 2 additions & 1 deletion signer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ func (pv *FilePV) GetPubKey() (crypto.PubKey, error) {
}

func (pv *FilePV) Sign(block Block) ([]byte, []byte, time.Time, error) {
height, round, step, signBytes, voteExtensionSignBytes := block.Height, int32(block.Round), block.Step, block.SignBytes, block.VoteExtensionSignBytes
height, round, step := block.Height, int32(block.Round), block.Step
signBytes, voteExtensionSignBytes := block.SignBytes, block.VoteExtensionSignBytes

lss := pv.LastSignState

Expand Down
8 changes: 7 additions & 1 deletion signer/remote_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ func (rs *ReconnRemoteSigner) handleSignVoteRequest(chainID string, vote *cometp
Error: nil,
}}

sig, voteExtSig, timestamp, err := signAndTrack(context.TODO(), rs.Logger, rs.privVal, chainID, VoteToBlock(chainID, vote))
sig, voteExtSig, timestamp, err := signAndTrack(
context.TODO(),
rs.Logger,
rs.privVal,
chainID,
VoteToBlock(chainID, vote),
)
if err != nil {
msgSum.SignedVoteResponse.Error = getRemoteSignerError(err)
return cometprotoprivval.Message{Sum: msgSum}
Expand Down
10 changes: 9 additions & 1 deletion signer/single_signer_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ func (pv *SingleSignerValidator) GetPubKey(_ context.Context, chainID string) ([
}

// SignVote implements types.PrivValidator
func (pv *SingleSignerValidator) Sign(_ context.Context, chainID string, block Block) ([]byte, []byte, time.Time, error) {
func (pv *SingleSignerValidator) Sign(
_ context.Context,
chainID string,
block Block) (
[]byte,
[]byte,
time.Time,
error,
) {
chainState, err := pv.loadChainStateIfNecessary(chainID)
if err != nil {
return nil, nil, block.Timestamp, err
Expand Down
3 changes: 2 additions & 1 deletion signer/single_signer_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestSingleSignerValidator(t *testing.T) {

require.True(t, privateKey.PubKey().VerifySignature(block.SignBytes, sig), "signature verification failed")

require.True(t, privateKey.PubKey().VerifySignature(block.VoteExtensionSignBytes, voteExtSig), "vote extension signature verification failed")
require.True(t, privateKey.PubKey().VerifySignature(block.VoteExtensionSignBytes, voteExtSig),
"vote extension signature verification failed")

}
25 changes: 19 additions & 6 deletions signer/threshold_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ func (pv *ThresholdValidator) mustLoadChainState(chainID string) ChainSignState
// sign process if it is greater than the current high watermark. A mutex is used to avoid concurrent
// state updates. The disk write is scheduled in a separate goroutine which will perform an atomic write.
// pendingDiskWG is used upon termination in pendingDiskWG to ensure all writes have completed.
func (pv *ThresholdValidator) SaveLastSignedStateInitiated(chainID string, block *Block) ([]byte, []byte, time.Time, error) {
func (pv *ThresholdValidator) SaveLastSignedStateInitiated(
chainID string,
block *Block,
) ([]byte, []byte, time.Time, error) {
css := pv.mustLoadChainState(chainID)

height, round, step := block.Height, block.Round, block.Step
Expand All @@ -158,7 +161,8 @@ func (pv *ThresholdValidator) SaveLastSignedStateInitiated(chainID string, block
}

// There was an error saving the last sign state, so check if there is an existing signature for this block.
existingSignature, existingVoteExtSignature, existingTimestamp, sameBlockErr := pv.getExistingBlockSignature(chainID, block)
existingSignature, existingVoteExtSignature,
existingTimestamp, sameBlockErr := pv.getExistingBlockSignature(chainID, block)

if _, ok := err.(*SameHRSError); !ok {
if sameBlockErr == nil {
Expand Down Expand Up @@ -208,7 +212,8 @@ func (pv *ThresholdValidator) SaveLastSignedStateInitiated(chainID string, block
continue
}

existingSignature, existingVoteExtSignature, existingTimestamp, sameBlockErr = pv.compareBlockSignatureAgainstSSC(chainID, block, &ssc)
existingSignature, existingVoteExtSignature,
existingTimestamp, sameBlockErr = pv.compareBlockSignatureAgainstSSC(chainID, block, &ssc)
if sameBlockErr == nil {
return existingSignature, existingVoteExtSignature, existingTimestamp, nil
}
Expand Down Expand Up @@ -397,7 +402,10 @@ func (pv *ThresholdValidator) LoadSignStateIfNecessary(chainID string) error {
// getExistingBlockSignature returns the existing block signature and no error if the signature is valid for the block.
// It returns nil signature and nil error if there is no signature and it's okay to sign (fresh or again).
// It returns an error if we have already signed a greater block, or if we are still waiting for in in-progress sign.
func (pv *ThresholdValidator) getExistingBlockSignature(chainID string, block *Block) ([]byte, []byte, time.Time, error) {
func (pv *ThresholdValidator) getExistingBlockSignature(
chainID string,
block *Block,
) ([]byte, []byte, time.Time, error) {
css := pv.mustLoadChainState(chainID)

latestBlock, existingSignature := css.lastSignState.GetFromCache(block.HRSKey())
Expand Down Expand Up @@ -615,8 +623,13 @@ func (pv *ThresholdValidator) proxyIfNecessary(
return true, signRes.Signature, signRes.VoteExtensionSignature, stamp, nil
}

func (pv *ThresholdValidator) Sign(ctx context.Context, chainID string, block Block) ([]byte, []byte, time.Time, error) {
height, round, step, stamp, signBytes, voteExtensionSignBytes := block.Height, block.Round, block.Step, block.Timestamp, block.SignBytes, block.VoteExtensionSignBytes
func (pv *ThresholdValidator) Sign(
ctx context.Context,
chainID string,
block Block,
) ([]byte, []byte, time.Time, error) {
height, round, step, stamp := block.Height, block.Round, block.Step, block.Timestamp
signBytes, voteExtensionSignBytes := block.SignBytes, block.VoteExtensionSignBytes

log := pv.logger.With(
"chain_id", chainID,
Expand Down
2 changes: 0 additions & 2 deletions signer/threshold_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ func testThresholdValidatorLeaderElection(t *testing.T, threshold, total uint8)
if !pubKey.VerifySignature(voteExtSignBytes, voteExtSig) {
t.Log("PreCommit vote extension signature verification failed")
return
} else {
t.Log("PreCommit vote extension signature verification succeeded")
}

mu.Lock()
Expand Down

0 comments on commit f8a45c6

Please sign in to comment.