Compare commits

...

26 Commits

Author SHA1 Message Date
Ismail Khoffi
7479871402 reintroduce mtx for remote signer calls 2018-12-18 18:05:27 +01:00
Ismail Khoffi
5d6f468b2a revert all changes related to removing GetAddress() from interface 2018-12-18 15:17:53 +01:00
Ismail Khoffi
138a57258f address review comments
- remove lock from remote signer
 - remove some require.NoError's
2018-12-18 12:05:55 +01:00
Ismail Khoffi
f9a564cfc3 merge in origin/develop 2018-12-17 12:29:53 +01:00
Ismail Khoffi
0c8111869f review comments:
- remove superfluous vars
2018-12-17 12:28:01 +01:00
Ismail Khoffi
8a993c6486 merge develop and update changelog pending 2018-12-12 14:19:15 +01:00
Ismail Khoffi
3547ce2516 Rework PR to memoize public key on init:
- split PubKeyMsg into PubKeyRequest / PubKeyResponse like other msgs
 - NewRemoteSignerClient sends a pubkey request (once), return this err
 OnStart()
 - NewRemoteSignerClient returns an error if retrieving the pubkey fails
 - remove GetAddress from PrivValidator interface
 - GetPublicKey doesn't err but returns memoized public key from init
 - fix tests
2018-12-12 13:59:40 +01:00
Ismail Khoffi
3d5e06ff7c Anton's suggested changes 2018-12-10 11:19:02 +01:00
Ismail Khoffi
e33f256359 fix unused import 2018-12-09 13:03:06 +01:00
Ismail Khoffi
5c09275691 wrap error in remote signer only 2018-12-07 12:17:49 +01:00
Ismail Khoffi
094699f9bc only use "github.com/pkg/errors" to avoid aliasing 2018-12-07 11:52:40 +01:00
Ismail Khoffi
c8ab062ce9 Merge branch 'develop' into 2926_dont_panic 2018-12-07 11:32:28 +01:00
Ismail Khoffi
1765eb2cd2 more review comments:
- consistently wrap error
 - add changelog entry
2018-12-07 11:31:14 +01:00
Ismail Khoffi
df20323cd2 a few uncaught asserts replaced with require 2018-12-03 12:08:20 +01:00
Ismail Khoffi
f17c04c892 more review comments: require instead assert & wrap errors 2018-12-03 12:03:50 +01:00
Ismail Khoffi
50ac191f9d Address more review comments: require instead assert & wrap errors 2018-12-01 12:26:40 +01:00
Ismail Khoffi
977a138b1f Review comments: wrap errors 2018-12-01 12:08:57 +01:00
Anton Kaliaev
1c6ed0e7d0 Review comments: @melekes suggestions
use require instead of assert

Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:59:36 +01:00
Anton Kaliaev
80c464c9b4 Review comments: @melekes suggestions
require instead of assert

Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:59:11 +01:00
Anton Kaliaev
5233ac154f Review comments: @melekes suggestions
require instead of assert

Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:58:56 +01:00
Anton Kaliaev
db04ff4896 Review comments: @melekes suggestions
require instead of assert

Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:58:40 +01:00
Anton Kaliaev
394edc9230 Review comments: @melekes suggestions
require instead of assert

Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:58:25 +01:00
Anton Kaliaev
1fa463ecab Review comments: @melekes suggestions
require instead of assert

Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:58:00 +01:00
Anton Kaliaev
d79d2093ff Review comments: @melekes suggestions
require instead of assert

Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:57:39 +01:00
Anton Kaliaev
78b7a41319 Review comments: @melekes suggestions
Co-Authored-By: Liamsi <Ismail.Khoffi@gmail.com>
2018-12-01 11:57:20 +01:00
Ismail Khoffi
417c30b9c1 PrivValidator.GetAddress() and PrivValidator.GetPublicKey() return an
error instead of panic
2018-11-29 18:52:19 +01:00
8 changed files with 70 additions and 62 deletions

View File

@@ -10,9 +10,13 @@ Special thanks to external contributors on this release:
- [cli] Removed `node` `--proxy_app=dummy` option. Use `kvstore` (`persistent_kvstore`) instead.
- [cli] Renamed `node` `--proxy_app=nilapp` to `--proxy_app=noop`.
- [privval] \#2926 split up `PubKeyMsg` into `PubKeyRequest` and `PubKeyResponse` to be consistent with other message types
* Apps
* Go API
* Go API
- [types] \#2926 memoize consensus public key on initialization of remote signer and return the memoized key on
`PrivValidator.GetPubKey()` instead of requesting it again
* Blockchain Protocol
@@ -23,4 +27,4 @@ Special thanks to external contributors on this release:
### IMPROVEMENTS:
### BUG FIXES:
- [types] \#2926 do not panic if retrieving the private validator's public key fails

View File

@@ -16,6 +16,8 @@ var ShowValidatorCmd = &cobra.Command{
}
func showValidator(cmd *cobra.Command, args []string) {
// TODO(ismail): add a flag and check if we actually want to see the pub key
// of the remote signer instead of the FilePV
privValidator := privval.LoadOrGenFilePV(config.PrivValidatorFile())
pubKeyJSONBytes, _ := cdc.MarshalJSON(privValidator.GetPubKey())
fmt.Println(string(pubKeyJSONBytes))

View File

@@ -659,12 +659,6 @@ func TestInitChainUpdateValidators(t *testing.T) {
assert.Equal(t, newValAddr, expectValAddr)
}
func newInitChainApp(vals []abci.ValidatorUpdate) *initChainApp {
return &initChainApp{
vals: vals,
}
}
// returns the vals on InitChain
type initChainApp struct {
abci.BaseApplication

View File

@@ -2,13 +2,14 @@ package consensus
import (
"bytes"
"errors"
"fmt"
"reflect"
"runtime/debug"
"sync"
"time"
"github.com/pkg/errors"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/fail"
"github.com/tendermint/tendermint/libs/log"

View File

@@ -67,7 +67,10 @@ func (sc *IPCVal) OnStart() error {
return err
}
sc.RemoteSignerClient = NewRemoteSignerClient(sc.conn)
sc.RemoteSignerClient, err = NewRemoteSignerClient(sc.conn)
if err != nil {
return err
}
// Start a routine to keep the connection alive
sc.cancelPing = make(chan struct{}, 1)

View File

@@ -6,6 +6,8 @@ import (
"net"
"sync"
"github.com/pkg/errors"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common"
@@ -15,8 +17,9 @@ import (
// RemoteSignerClient implements PrivValidator, it uses a socket to request signatures
// from an external process.
type RemoteSignerClient struct {
conn net.Conn
lock sync.Mutex
conn net.Conn
consensusPubKey crypto.PubKey
mtx sync.Mutex
}
// Check that RemoteSignerClient implements PrivValidator.
@@ -25,38 +28,34 @@ var _ types.PrivValidator = (*RemoteSignerClient)(nil)
// NewRemoteSignerClient returns an instance of RemoteSignerClient.
func NewRemoteSignerClient(
conn net.Conn,
) *RemoteSignerClient {
) (*RemoteSignerClient, error) {
sc := &RemoteSignerClient{
conn: conn,
}
return sc
}
// GetAddress implements PrivValidator.
func (sc *RemoteSignerClient) GetAddress() types.Address {
pubKey, err := sc.getPubKey()
if err != nil {
panic(err)
return nil, cmn.ErrorWrap(err, "error while retrieving public key for remote signer")
}
return pubKey.Address()
// retrieve and memoize the consensus public key once:
sc.consensusPubKey = pubKey
return sc, nil
}
// GetPubKey implements PrivValidator.
func (sc *RemoteSignerClient) GetPubKey() crypto.PubKey {
pubKey, err := sc.getPubKey()
if err != nil {
panic(err)
}
return sc.consensusPubKey
}
return pubKey
// GetAddress implements PrivValidator.
func (sc *RemoteSignerClient) GetAddress() types.Address {
return sc.consensusPubKey.Address()
}
func (sc *RemoteSignerClient) getPubKey() (crypto.PubKey, error) {
sc.lock.Lock()
defer sc.lock.Unlock()
sc.mtx.Lock()
defer sc.mtx.Unlock()
err := writeMsg(sc.conn, &PubKeyMsg{})
err := writeMsg(sc.conn, &PubKeyRequest{})
if err != nil {
return nil, err
}
@@ -65,14 +64,22 @@ func (sc *RemoteSignerClient) getPubKey() (crypto.PubKey, error) {
if err != nil {
return nil, err
}
pubKeyResp, ok := res.(*PubKeyResponse)
if !ok {
return nil, errors.Wrap(ErrUnexpectedResponse, "response is not PubKeyResponse")
}
return res.(*PubKeyMsg).PubKey, nil
if pubKeyResp.Error != nil {
return nil, errors.Wrap(pubKeyResp.Error, "failed to get private validator's public key")
}
return pubKeyResp.PubKey, nil
}
// SignVote implements PrivValidator.
func (sc *RemoteSignerClient) SignVote(chainID string, vote *types.Vote) error {
sc.lock.Lock()
defer sc.lock.Unlock()
sc.mtx.Lock()
defer sc.mtx.Unlock()
err := writeMsg(sc.conn, &SignVoteRequest{Vote: vote})
if err != nil {
@@ -101,8 +108,8 @@ func (sc *RemoteSignerClient) SignProposal(
chainID string,
proposal *types.Proposal,
) error {
sc.lock.Lock()
defer sc.lock.Unlock()
sc.mtx.Lock()
defer sc.mtx.Unlock()
err := writeMsg(sc.conn, &SignProposalRequest{Proposal: proposal})
if err != nil {
@@ -127,8 +134,8 @@ func (sc *RemoteSignerClient) SignProposal(
// Ping is used to check connection health.
func (sc *RemoteSignerClient) Ping() error {
sc.lock.Lock()
defer sc.lock.Unlock()
sc.mtx.Lock()
defer sc.mtx.Unlock()
err := writeMsg(sc.conn, &PingRequest{})
if err != nil {
@@ -152,7 +159,8 @@ type RemoteSignerMsg interface{}
func RegisterRemoteSignerMsg(cdc *amino.Codec) {
cdc.RegisterInterface((*RemoteSignerMsg)(nil), nil)
cdc.RegisterConcrete(&PubKeyMsg{}, "tendermint/remotesigner/PubKeyMsg", nil)
cdc.RegisterConcrete(&PubKeyRequest{}, "tendermint/remotesigner/PubKeyRequest", nil)
cdc.RegisterConcrete(&PubKeyResponse{}, "tendermint/remotesigner/PubKeyResponse", nil)
cdc.RegisterConcrete(&SignVoteRequest{}, "tendermint/remotesigner/SignVoteRequest", nil)
cdc.RegisterConcrete(&SignedVoteResponse{}, "tendermint/remotesigner/SignedVoteResponse", nil)
cdc.RegisterConcrete(&SignProposalRequest{}, "tendermint/remotesigner/SignProposalRequest", nil)
@@ -161,9 +169,13 @@ func RegisterRemoteSignerMsg(cdc *amino.Codec) {
cdc.RegisterConcrete(&PingResponse{}, "tendermint/remotesigner/PingResponse", nil)
}
// PubKeyMsg is a PrivValidatorSocket message containing the public key.
type PubKeyMsg struct {
// PubKeyRequest requests the consensus public key from the remote signer.
type PubKeyRequest struct{}
// PubKeyResponse is a PrivValidatorSocket message containing the public key.
type PubKeyResponse struct {
PubKey crypto.PubKey
Error *RemoteSignerError
}
// SignVoteRequest is a PrivValidatorSocket message containing a vote.
@@ -227,10 +239,10 @@ func handleRequest(req RemoteSignerMsg, chainID string, privVal types.PrivValida
var err error
switch r := req.(type) {
case *PubKeyMsg:
case *PubKeyRequest:
var p crypto.PubKey
p = privVal.GetPubKey()
res = &PubKeyMsg{p}
res = &PubKeyResponse{p, nil}
case *SignVoteRequest:
err = privVal.SignVote(chainID, r.Vote)
if err != nil {

View File

@@ -107,8 +107,10 @@ func (sc *TCPVal) OnStart() error {
}
sc.conn = conn
sc.RemoteSignerClient = NewRemoteSignerClient(sc.conn)
sc.RemoteSignerClient, err = NewRemoteSignerClient(sc.conn)
if err != nil {
return err
}
// Start a routine to keep the connection alive
sc.cancelPing = make(chan struct{}, 1)

View File

@@ -25,15 +25,10 @@ func TestSocketPVAddress(t *testing.T) {
defer sc.Stop()
defer rs.Stop()
serverAddr := rs.privVal.GetAddress()
clientAddr := sc.GetAddress()
serverAddr := rs.privVal.GetPubKey().Address()
clientAddr := sc.GetPubKey().Address()
assert.Equal(t, serverAddr, clientAddr)
// TODO(xla): Remove when PrivValidator2 replaced PrivValidator.
assert.Equal(t, serverAddr, sc.GetAddress())
}
func TestSocketPVPubKey(t *testing.T) {
@@ -47,12 +42,9 @@ func TestSocketPVPubKey(t *testing.T) {
clientKey, err := sc.getPubKey()
require.NoError(t, err)
privKey := rs.privVal.GetPubKey()
privvalPubKey := rs.privVal.GetPubKey()
assert.Equal(t, privKey, clientKey)
// TODO(xla): Remove when PrivValidator2 replaced PrivValidator.
assert.Equal(t, privKey, sc.GetPubKey())
assert.Equal(t, privvalPubKey, clientKey)
}
func TestSocketPVProposal(t *testing.T) {
@@ -153,9 +145,9 @@ func TestSocketPVDeadline(t *testing.T) {
go func(sc *TCPVal) {
defer close(listenc)
require.NoError(t, sc.Start())
assert.Equal(t, sc.Start().(cmn.Error).Data(), ErrConnTimeout)
assert.True(t, sc.IsRunning())
assert.False(t, sc.IsRunning())
}(sc)
for {
@@ -174,9 +166,6 @@ func TestSocketPVDeadline(t *testing.T) {
}
<-listenc
_, err := sc.getPubKey()
assert.Equal(t, err.(cmn.Error).Data(), ErrConnTimeout)
}
func TestRemoteSignerRetry(t *testing.T) {
@@ -310,14 +299,15 @@ func TestErrUnexpectedResponse(t *testing.T) {
testStartSocketPV(t, readyc, sc)
defer sc.Stop()
RemoteSignerConnDeadline(time.Millisecond)(rs)
RemoteSignerConnRetries(1e6)(rs)
RemoteSignerConnRetries(100)(rs)
// we do not want to Start() the remote signer here and instead use the connection to
// reply with intentionally wrong replies below:
rsConn, err := rs.connect()
defer rsConn.Close()
require.NoError(t, err)
require.NotNil(t, rsConn)
// send over public key to get the remote signer running:
go testReadWriteResponse(t, &PubKeyResponse{}, rsConn)
<-readyc
// Proposal: