This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix consensus failure when remote signer drops (#153)
* consensus failure when remote signer drops;cherry-pick d85e2e52d; * privval: if remote signer errors, don't retry Refs #5112 * only retrieve pubkey once for all validators;cherry-pick 61ab6718e; * Only call privValidator.GetPubKey once per block; cherry-pick 5ba30e6f5; * fix text Co-authored-by: Anton Kaliaev <[email protected]> Co-authored-by: Joe Bowman <[email protected]>
- Loading branch information
1 parent
5a811c3
commit 2fd279d
Showing
7 changed files
with
194 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package privval | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/tendermint/tendermint/crypto" | ||
"github.com/tendermint/tendermint/types" | ||
) | ||
|
||
// RetrySignerClient wraps SignerClient adding retry for each operation (except | ||
// Ping) w/ a timeout. | ||
type RetrySignerClient struct { | ||
next *SignerClient | ||
retries int | ||
timeout time.Duration | ||
} | ||
|
||
// NewRetrySignerClient returns RetrySignerClient. If +retries+ is 0, the | ||
// client will be retrying each operation indefinitely. | ||
func NewRetrySignerClient(sc *SignerClient, retries int, timeout time.Duration) *RetrySignerClient { | ||
return &RetrySignerClient{sc, retries, timeout} | ||
} | ||
|
||
var _ types.PrivValidator = (*RetrySignerClient)(nil) | ||
|
||
func (sc *RetrySignerClient) Close() error { | ||
return sc.next.Close() | ||
} | ||
|
||
func (sc *RetrySignerClient) IsConnected() bool { | ||
return sc.next.IsConnected() | ||
} | ||
|
||
func (sc *RetrySignerClient) WaitForConnection(maxWait time.Duration) error { | ||
return sc.next.WaitForConnection(maxWait) | ||
} | ||
|
||
//-------------------------------------------------------- | ||
// Implement PrivValidator | ||
|
||
func (sc *RetrySignerClient) Ping() error { | ||
return sc.next.Ping() | ||
} | ||
|
||
func (sc *RetrySignerClient) GetPubKey() crypto.PubKey { | ||
for i := 0; i < sc.retries || sc.retries == 0; i++ { | ||
pk := sc.next.GetPubKey() | ||
if pk != nil { | ||
return pk | ||
} | ||
time.Sleep(sc.timeout) | ||
} | ||
return nil | ||
} | ||
|
||
func (sc *RetrySignerClient) SignVote(chainID string, vote *types.Vote) error { | ||
for i := 0; i < sc.retries || sc.retries == 0; i++ { | ||
err := sc.next.SignVote(chainID, vote) | ||
if err == nil { | ||
return nil | ||
} | ||
// If remote signer errors, we don't retry. | ||
if _, ok := err.(*RemoteSignerError); ok { | ||
return err | ||
} | ||
time.Sleep(sc.timeout) | ||
} | ||
return errors.New("exhausted all attempts to sign vote") | ||
} | ||
|
||
func (sc *RetrySignerClient) SignProposal(chainID string, proposal *types.Proposal) error { | ||
for i := 0; i < sc.retries || sc.retries == 0; i++ { | ||
err := sc.next.SignProposal(chainID, proposal) | ||
if err == nil { | ||
return nil | ||
} | ||
// If remote signer errors, we don't retry. | ||
if _, ok := err.(*RemoteSignerError); ok { | ||
return err | ||
} | ||
time.Sleep(sc.timeout) | ||
} | ||
return errors.New("exhausted all attempts to sign proposal") | ||
} |
Oops, something went wrong.