diff --git a/cmd/priv_val_server/main.go b/cmd/priv_val_server/main.go index c86bced81..37d67bcf6 100644 --- a/cmd/priv_val_server/main.go +++ b/cmd/priv_val_server/main.go @@ -48,7 +48,7 @@ func main() { os.Exit(1) } - rs := privval.NewSignerServiceEndpoint(logger, *chainID, pv, dialer) + rs := privval.NewSignerDialerEndpoint(logger, *chainID, pv, dialer) err := rs.Start() if err != nil { panic(err) diff --git a/node/node.go b/node/node.go index c0a4d736e..f2cce6367 100644 --- a/node/node.go +++ b/node/node.go @@ -16,12 +16,11 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/rs/cors" - amino "github.com/tendermint/go-amino" + "github.com/tendermint/go-amino" abci "github.com/tendermint/tendermint/abci/types" bc "github.com/tendermint/tendermint/blockchain" cfg "github.com/tendermint/tendermint/config" cs "github.com/tendermint/tendermint/consensus" - "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/evidence" cmn "github.com/tendermint/tendermint/libs/common" dbm "github.com/tendermint/tendermint/libs/db" @@ -926,33 +925,14 @@ func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) { db.SetSync(genesisDocKey, bytes) } -func createAndStartPrivValidatorSocketClient( - listenAddr string, - logger log.Logger, -) (types.PrivValidator, error) { - var listener net.Listener - - protocol, address := cmn.ProtocolAndAddress(listenAddr) - ln, err := net.Listen(protocol, address) +func createAndStartPrivValidatorSocketClient(listenAddr string, logger log.Logger) (types.PrivValidator, error) { + pve, err := privval.NewSignerListener(listenAddr, logger) if err != nil { - return nil, err - } - switch protocol { - case "unix": - listener = privval.NewUnixListener(ln) - case "tcp": - // TODO: persist this key so external signer - // can actually authenticate us - listener = privval.NewTCPListener(ln, ed25519.GenPrivKey()) - default: - return nil, fmt.Errorf( - "Wrong listen address: expected either 'tcp' or 'unix' protocols, got %s", - protocol, - ) + return nil, errors.Wrap(err, "failed to start private validator") } - pvsc := privval.NewSignerValidatorEndpoint(logger.With("module", "privval"), listener) - if err := pvsc.Start(); err != nil { + pvsc, err := privval.NewSignerRemote(pve) + if err != nil { return nil, errors.Wrap(err, "failed to start private validator") } diff --git a/node/node_test.go b/node/node_test.go index 915dddfdd..104fb413e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -132,7 +132,7 @@ func TestNodeSetPrivValTCP(t *testing.T) { config.BaseConfig.PrivValidatorListenAddr = addr dialer := privval.DialTCPFn(addr, 100*time.Millisecond, ed25519.GenPrivKey()) - pvsc := privval.NewSignerServiceEndpoint( + pvsc := privval.NewSignerDialerEndpoint( log.TestingLogger(), config.ChainID(), types.NewMockPV(), @@ -174,7 +174,7 @@ func TestNodeSetPrivValIPC(t *testing.T) { config.BaseConfig.PrivValidatorListenAddr = "unix://" + tmpfile dialer := privval.DialUnixFn(tmpfile) - pvsc := privval.NewSignerServiceEndpoint( + pvsc := privval.NewSignerDialerEndpoint( log.TestingLogger(), config.ChainID(), types.NewMockPV(), diff --git a/privval/doc.go b/privval/doc.go index 80869a6a7..ad60673b6 100644 --- a/privval/doc.go +++ b/privval/doc.go @@ -6,16 +6,16 @@ FilePV FilePV is the simplest implementation and developer default. It uses one file for the private key and another to store state. -SignerValidatorEndpoint +SignerListenerEndpoint -SignerValidatorEndpoint establishes a connection to an external process, like a Key Management Server (KMS), using a socket. -SignerValidatorEndpoint listens for the external KMS process to dial in. -SignerValidatorEndpoint takes a listener, which determines the type of connection +SignerListenerEndpoint establishes a connection to an external process, like a Key Management Server (KMS), using a socket. +SignerListenerEndpoint listens for the external KMS process to dial in. +SignerListenerEndpoint takes a listener, which determines the type of connection (ie. encrypted over tcp, or unencrypted over unix). -SignerServiceEndpoint +SignerDialerEndpoint -SignerServiceEndpoint is a simple wrapper around a net.Conn. It's used by both IPCVal and TCPVal. +SignerDialerEndpoint is a simple wrapper around a net.Conn. It's used by both IPCVal and TCPVal. */ package privval diff --git a/privval/messages.go b/privval/messages.go index 81eae5913..1140e2bb2 100644 --- a/privval/messages.go +++ b/privval/messages.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/types" ) -// RemoteSignerMsg is sent between SignerServiceEndpoint and the SignerServiceEndpoint client. +// RemoteSignerMsg is sent between SignerDialerEndpoint and the SignerDialerEndpoint client. type RemoteSignerMsg interface{} func RegisterRemoteSignerMsg(cdc *amino.Codec) { diff --git a/privval/signer_service_endpoint.go b/privval/signer_dialer_endpoint.go similarity index 76% rename from privval/signer_service_endpoint.go rename to privval/signer_dialer_endpoint.go index f11d9cbe0..e04f5258c 100644 --- a/privval/signer_service_endpoint.go +++ b/privval/signer_dialer_endpoint.go @@ -10,23 +10,25 @@ import ( "github.com/tendermint/tendermint/types" ) -// SignerServiceEndpointOption sets an optional parameter on the SignerServiceEndpoint. -type SignerServiceEndpointOption func(*SignerServiceEndpoint) +// SignerServiceEndpointOption sets an optional parameter on the SignerDialerEndpoint. +type SignerServiceEndpointOption func(*SignerDialerEndpoint) // SignerServiceEndpointTimeoutReadWrite sets the read and write timeout for connections // from external signing processes. func SignerServiceEndpointTimeoutReadWrite(timeout time.Duration) SignerServiceEndpointOption { - return func(ss *SignerServiceEndpoint) { ss.timeoutReadWrite = timeout } + return func(ss *SignerDialerEndpoint) { ss.timeoutReadWrite = timeout } } // SignerServiceEndpointConnRetries sets the amount of attempted retries to connect. func SignerServiceEndpointConnRetries(retries int) SignerServiceEndpointOption { - return func(ss *SignerServiceEndpoint) { ss.connRetries = retries } + return func(ss *SignerDialerEndpoint) { ss.connRetries = retries } } -// SignerServiceEndpoint dials using its dialer and responds to any +// TODO: Create a type for a signerEndpoint (common for both listener/dialer) + +// SignerDialerEndpoint dials using its dialer and responds to any // signature requests using its privVal. -type SignerServiceEndpoint struct { +type SignerDialerEndpoint struct { cmn.BaseService chainID string @@ -38,16 +40,16 @@ type SignerServiceEndpoint struct { conn net.Conn } -// NewSignerServiceEndpoint returns a SignerServiceEndpoint that will dial using the given +// NewSignerDialerEndpoint returns a SignerDialerEndpoint that will dial using the given // dialer and respond to any signature requests over the connection // using the given privVal. -func NewSignerServiceEndpoint( +func NewSignerDialerEndpoint( logger log.Logger, chainID string, privVal types.PrivValidator, dialer SocketDialer, -) *SignerServiceEndpoint { - se := &SignerServiceEndpoint{ +) *SignerDialerEndpoint { + se := &SignerDialerEndpoint{ chainID: chainID, timeoutReadWrite: time.Second * defaultTimeoutReadWriteSeconds, connRetries: defaultMaxDialRetries, @@ -55,12 +57,12 @@ func NewSignerServiceEndpoint( dialer: dialer, } - se.BaseService = *cmn.NewBaseService(logger, "SignerServiceEndpoint", se) + se.BaseService = *cmn.NewBaseService(logger, "SignerDialerEndpoint", se) return se } // OnStart implements cmn.Service. -func (ss *SignerServiceEndpoint) OnStart() error { +func (ss *SignerDialerEndpoint) OnStart() error { conn, err := ss.connect() if err != nil { ss.Logger.Error("OnStart", "err", err) @@ -74,7 +76,7 @@ func (ss *SignerServiceEndpoint) OnStart() error { } // OnStop implements cmn.Service. -func (ss *SignerServiceEndpoint) OnStop() { +func (ss *SignerDialerEndpoint) OnStop() { if ss.conn == nil { return } @@ -84,7 +86,7 @@ func (ss *SignerServiceEndpoint) OnStop() { } } -func (ss *SignerServiceEndpoint) connect() (net.Conn, error) { +func (ss *SignerDialerEndpoint) connect() (net.Conn, error) { for retries := 0; retries < ss.connRetries; retries++ { // Don't sleep if it is the first retry. if retries > 0 { @@ -102,7 +104,7 @@ func (ss *SignerServiceEndpoint) connect() (net.Conn, error) { return nil, ErrDialRetryMax } -func (ss *SignerServiceEndpoint) readMessage() (msg RemoteSignerMsg, err error) { +func (ss *SignerDialerEndpoint) readMessage() (msg RemoteSignerMsg, err error) { // TODO: Avoid duplication // TODO: Check connection status @@ -115,7 +117,7 @@ func (ss *SignerServiceEndpoint) readMessage() (msg RemoteSignerMsg, err error) return } -func (ss *SignerServiceEndpoint) writeMessage(msg RemoteSignerMsg) (err error) { +func (ss *SignerDialerEndpoint) writeMessage(msg RemoteSignerMsg) (err error) { // TODO: Avoid duplication // TODO: Check connection status @@ -130,7 +132,7 @@ func (ss *SignerServiceEndpoint) writeMessage(msg RemoteSignerMsg) (err error) { return } -func (ss *SignerServiceEndpoint) handleConnection(conn net.Conn) { +func (ss *SignerDialerEndpoint) handleConnection(conn net.Conn) { for { if !ss.IsRunning() { return // Ignore error from listener closing. diff --git a/privval/signer_validator_endpoint.go b/privval/signer_listener_endpoint.go similarity index 81% rename from privval/signer_validator_endpoint.go rename to privval/signer_listener_endpoint.go index 833ae7e98..b5962c928 100644 --- a/privval/signer_validator_endpoint.go +++ b/privval/signer_listener_endpoint.go @@ -20,15 +20,14 @@ var ( ) // SignerValidatorEndpointOption sets an optional parameter on the SocketVal. -type SignerValidatorEndpointOption func(*SignerValidatorEndpoint) +type SignerValidatorEndpointOption func(*SignerListenerEndpoint) // SignerValidatorEndpointSetHeartbeat sets the period on which to check the liveness of the // connected Signer connections. func SignerValidatorEndpointSetHeartbeat(period time.Duration) SignerValidatorEndpointOption { - return func(sc *SignerValidatorEndpoint) { sc.heartbeatPeriod = period } + return func(sc *SignerListenerEndpoint) { sc.heartbeatPeriod = period } } - // TODO: Add a type for SignerEndpoints // getConnection // connect @@ -40,12 +39,12 @@ func SignerValidatorEndpointSetHeartbeat(period time.Duration) SignerValidatorEn // SocketVal implements PrivValidator. // It listens for an external process to dial in and uses // the socket to request signatures. -type SignerValidatorEndpoint struct { +type SignerListenerEndpoint struct { cmn.BaseService - mtx sync.Mutex + mtx sync.Mutex listener net.Listener - conn net.Conn + conn net.Conn // ping cancelPingCh chan struct{} @@ -53,20 +52,20 @@ type SignerValidatorEndpoint struct { heartbeatPeriod time.Duration } -// NewSignerValidatorEndpoint returns an instance of SignerValidatorEndpoint. -func NewSignerValidatorEndpoint(logger log.Logger, listener net.Listener) *SignerValidatorEndpoint { - sc := &SignerValidatorEndpoint{ +// NewSignerListenerEndpoint returns an instance of SignerListenerEndpoint. +func NewSignerListenerEndpoint(logger log.Logger, listener net.Listener) *SignerListenerEndpoint { + sc := &SignerListenerEndpoint{ listener: listener, heartbeatPeriod: heartbeatPeriod, } - sc.BaseService = *cmn.NewBaseService(logger, "SignerValidatorEndpoint", sc) + sc.BaseService = *cmn.NewBaseService(logger, "SignerListenerEndpoint", sc) return sc } // OnStart implements cmn.Service. -func (ve *SignerValidatorEndpoint) OnStart() error { +func (ve *SignerListenerEndpoint) OnStart() error { closed, err := ve.connect() // TODO: Improve. Connection state should be kept in a variable @@ -118,7 +117,7 @@ func (ve *SignerValidatorEndpoint) OnStart() error { } // OnStop implements cmn.Service. -func (ve *SignerValidatorEndpoint) OnStop() { +func (ve *SignerListenerEndpoint) OnStop() { if ve.cancelPingCh != nil { close(ve.cancelPingCh) } @@ -126,7 +125,7 @@ func (ve *SignerValidatorEndpoint) OnStop() { } // Close closes the underlying net.Conn. -func (ve *SignerValidatorEndpoint) Close() error { +func (ve *SignerListenerEndpoint) Close() error { ve.mtx.Lock() defer ve.mtx.Unlock() @@ -148,7 +147,7 @@ func (ve *SignerValidatorEndpoint) Close() error { } // SendRequest sends a request and waits for a response -func (ve *SignerValidatorEndpoint) SendRequest(request RemoteSignerMsg) (RemoteSignerMsg, error) { +func (ve *SignerListenerEndpoint) SendRequest(request RemoteSignerMsg) (RemoteSignerMsg, error) { ve.mtx.Lock() defer ve.mtx.Unlock() @@ -166,7 +165,7 @@ func (ve *SignerValidatorEndpoint) SendRequest(request RemoteSignerMsg) (RemoteS } // Ping is used to check connection health. -func (ve *SignerValidatorEndpoint) ping() error { +func (ve *SignerListenerEndpoint) ping() error { response, err := ve.SendRequest(&PingRequest{}) if err != nil { @@ -181,7 +180,7 @@ func (ve *SignerValidatorEndpoint) ping() error { return nil } -func (ve *SignerValidatorEndpoint) readMessage() (msg RemoteSignerMsg, err error) { +func (ve *SignerListenerEndpoint) readMessage() (msg RemoteSignerMsg, err error) { // TODO: Check connection status const maxRemoteSignerMsgSize = 1024 * 10 @@ -193,7 +192,7 @@ func (ve *SignerValidatorEndpoint) readMessage() (msg RemoteSignerMsg, err error return } -func (ve *SignerValidatorEndpoint) writeMessage(msg RemoteSignerMsg) (err error) { +func (ve *SignerListenerEndpoint) writeMessage(msg RemoteSignerMsg) (err error) { // TODO: Check connection status if ve.conn == nil { return fmt.Errorf("endpoint is not connected") @@ -211,7 +210,7 @@ func (ve *SignerValidatorEndpoint) writeMessage(msg RemoteSignerMsg) (err error) // connection is closed in OnStop. // returns true if the listener is closed (ie. it returns a nil conn). // TODO: Improve this -func (ve *SignerValidatorEndpoint) connect() (closed bool, err error) { +func (ve *SignerListenerEndpoint) connect() (closed bool, err error) { ve.mtx.Lock() defer ve.mtx.Unlock() @@ -247,7 +246,7 @@ func (ve *SignerValidatorEndpoint) connect() (closed bool, err error) { // acceptConnection attempts to accept a connection // it will timeout after the listener's timeoutAccept // TODO: There is no reason for this separate accept -func (ve *SignerValidatorEndpoint) acceptConnection() (net.Conn, error) { +func (ve *SignerListenerEndpoint) acceptConnection() (net.Conn, error) { conn, err := ve.listener.Accept() if err != nil { if !ve.IsRunning() { diff --git a/privval/signer_validator_endpoint_test.go b/privval/signer_listener_endpoint_test.go similarity index 93% rename from privval/signer_validator_endpoint_test.go rename to privval/signer_listener_endpoint_test.go index a0e2d108d..1f1a292bb 100644 --- a/privval/signer_validator_endpoint_test.go +++ b/privval/signer_listener_endpoint_test.go @@ -31,7 +31,7 @@ type dialerTestCase struct { // TestSignerRemoteRetryTCPOnly will test connection retry attempts over TCP. We // don't need this for Unix sockets because the OS instantly knows the state of // both ends of the socket connection. This basically causes the -// SignerServiceEndpoint.dialer() call inside SignerServiceEndpoint.connect() to return +// SignerDialerEndpoint.dialer() call inside SignerDialerEndpoint.connect() to return // successfully immediately, putting an instant stop to any retry attempts. func TestSignerRemoteRetryTCPOnly(t *testing.T) { var ( @@ -61,7 +61,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { } }(ln, attemptCh) - serviceEndpoint := NewSignerServiceEndpoint( + serviceEndpoint := NewSignerDialerEndpoint( log.TestingLogger(), common.RandStr(12), types.NewMockPV(), @@ -91,7 +91,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { // validatorEndpoint = newSignerValidatorEndpoint(log.TestingLogger(), tc.addr, thisConnTimeout) // ) // -// go func(sc *SignerValidatorEndpoint) { +// go func(sc *SignerListenerEndpoint) { // defer close(listenc) // // // Note: the TCP connection times out at the accept() phase, @@ -123,7 +123,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { // readyCh = make(chan struct{}) // errCh = make(chan error, 1) // -// serviceEndpoint = NewSignerServiceEndpoint( +// serviceEndpoint = NewSignerDialerEndpoint( // logger, // chainID, // types.NewMockPV(), @@ -182,7 +182,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { // chainID = common.RandStr(12) // readyCh = make(chan struct{}) // -// serviceEndpoint = NewSignerServiceEndpoint( +// serviceEndpoint = NewSignerDialerEndpoint( // logger, // chainID, // types.NewMockPV(), @@ -206,7 +206,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { // time.Sleep(testTimeoutHeartbeat * 2) // // serviceEndpoint.Stop() -// rs2 := NewSignerServiceEndpoint( +// rs2 := NewSignerDialerEndpoint( // logger, // chainID, // types.NewMockPV(), @@ -230,7 +230,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { /////////////////////////////////// -func newSignerValidatorEndpoint(logger log.Logger, addr string, timeoutReadWrite time.Duration) *SignerValidatorEndpoint { +func newSignerValidatorEndpoint(logger log.Logger, addr string, timeoutReadWrite time.Duration) *SignerListenerEndpoint { proto, address := common.ProtocolAndAddress(addr) ln, err := net.Listen(proto, address) @@ -253,11 +253,11 @@ func newSignerValidatorEndpoint(logger log.Logger, addr string, timeoutReadWrite listener = tcpLn } - return NewSignerValidatorEndpoint(logger, listener) + return NewSignerListenerEndpoint(logger, listener) } -func getStartEndpoint(t *testing.T, readyCh chan struct{}, sv *SignerValidatorEndpoint) { - go func(sv *SignerValidatorEndpoint) { +func getStartEndpoint(t *testing.T, readyCh chan struct{}, sv *SignerListenerEndpoint) { + go func(sv *SignerListenerEndpoint) { require.NoError(t, sv.Start()) assert.True(t, sv.IsRunning()) readyCh <- struct{}{} @@ -270,13 +270,13 @@ func getMockEndpoints( privValidator types.PrivValidator, addr string, socketDialer SocketDialer, -) (*SignerValidatorEndpoint, *SignerServiceEndpoint) { +) (*SignerListenerEndpoint, *SignerDialerEndpoint) { var ( logger = log.TestingLogger() privVal = privValidator readyCh = make(chan struct{}) - serviceEndpoint = NewSignerServiceEndpoint( + serviceEndpoint = NewSignerDialerEndpoint( logger, chainID, privVal, diff --git a/privval/signer_remote.go b/privval/signer_remote.go index b0c898c5f..0dc8ea780 100644 --- a/privval/signer_remote.go +++ b/privval/signer_remote.go @@ -3,14 +3,15 @@ package privval import ( "fmt" + "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/types" ) // SignerRemote implements PrivValidator. -// It uses a net.Conn to request signatures from an external process. +// It uses a validator endpoint to request signatures from an external process. type SignerRemote struct { - endpoint *SignerValidatorEndpoint + endpoint *SignerListenerEndpoint // memoized consensusPubKey crypto.PubKey @@ -20,7 +21,12 @@ type SignerRemote struct { var _ types.PrivValidator = (*SignerRemote)(nil) // NewSignerRemote returns an instance of SignerRemote. -func NewSignerRemote(endpoint *SignerValidatorEndpoint) (*SignerRemote, error) { +func NewSignerRemote(endpoint *SignerListenerEndpoint) (*SignerRemote, error) { + if !endpoint.IsRunning() { + if err := endpoint.Start(); err != nil { + return nil, errors.Wrap(err, "failed to start private validator") + } + } // TODO: Fix this //// retrieve and memoize the consensus public key once. diff --git a/privval/signer_remote_test.go b/privval/signer_remote_test.go index 7026c241f..cec37a617 100644 --- a/privval/signer_remote_test.go +++ b/privval/signer_remote_test.go @@ -1,19 +1,20 @@ package privval import ( + "testing" + "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/types" - "testing" - "time" ) type signerTestCase struct { chainID string mockPV types.PrivValidator signer *SignerRemote - signerService *SignerServiceEndpoint // TODO: Replace once it is encapsulated + signerService *SignerDialerEndpoint // TODO: Replace once it is encapsulated } func getSignerTestCases(t *testing.T) []signerTestCase { @@ -51,8 +52,8 @@ func TestSignerClose(t *testing.T) { assert.NoError(t, err) //// FIXME: An error is logged but OnStop hides it - //err = tc.signerService.Stop() - //assert.NoError(t, err) + err = tc.signerService.Stop() + assert.NoError(t, err) }() } } diff --git a/privval/socket_dialers_test.go b/privval/socket_dialers_test.go index a908c7d27..0906dceee 100644 --- a/privval/socket_dialers_test.go +++ b/privval/socket_dialers_test.go @@ -2,11 +2,11 @@ package privval import ( "fmt" - "github.com/stretchr/testify/require" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" cmn "github.com/tendermint/tendermint/libs/common" ) diff --git a/privval/utils.go b/privval/utils.go index d8837bdf0..6212eb235 100644 --- a/privval/utils.go +++ b/privval/utils.go @@ -1,7 +1,12 @@ package privval import ( + "fmt" + "net" + + "github.com/tendermint/tendermint/crypto/ed25519" cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/log" ) // IsConnTimeout returns a boolean indicating whether the error is known to @@ -18,3 +23,29 @@ func IsConnTimeout(err error) bool { } return false } + +func NewSignerListener(listenAddr string, logger log.Logger) (*SignerListenerEndpoint, error) { + var listener net.Listener + + protocol, address := cmn.ProtocolAndAddress(listenAddr) + ln, err := net.Listen(protocol, address) + if err != nil { + return nil, err + } + switch protocol { + case "unix": + listener = NewUnixListener(ln) + case "tcp": + // TODO: persist this key so external signer can actually authenticate us + listener = NewTCPListener(ln, ed25519.GenPrivKey()) + default: + return nil, fmt.Errorf( + "wrong listen address: expected either 'tcp' or 'unix' protocols, got %s", + protocol, + ) + } + + pve := NewSignerListenerEndpoint(logger.With("module", "privval"), listener) + + return pve, nil +} diff --git a/privval/utils_test.go b/privval/utils_test.go index 357aee7b9..851c01ffc 100644 --- a/privval/utils_test.go +++ b/privval/utils_test.go @@ -2,11 +2,11 @@ package privval import ( "fmt" - "github.com/stretchr/testify/require" "net" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" cmn "github.com/tendermint/tendermint/libs/common" ) diff --git a/tools/tm-signer-harness/internal/test_harness.go b/tools/tm-signer-harness/internal/test_harness.go index 279455590..161fa0d90 100644 --- a/tools/tm-signer-harness/internal/test_harness.go +++ b/tools/tm-signer-harness/internal/test_harness.go @@ -313,7 +313,7 @@ func (th *TestHarness) Shutdown(err error) { } // newTestHarnessSignerRemote creates our client instance which we will use for testing. -func newTestHarnessSignerRemote(logger log.Logger, cfg TestHarnessConfig) (*privval.SignerValidatorEndpoint, error) { +func newTestHarnessSignerRemote(logger log.Logger, cfg TestHarnessConfig) (*privval.SignerListenerEndpoint, error) { proto, addr := cmn.ProtocolAndAddress(cfg.BindAddr) if proto == "unix" { // make sure the socket doesn't exist - if so, try to delete it @@ -346,7 +346,7 @@ func newTestHarnessSignerRemote(logger log.Logger, cfg TestHarnessConfig) (*priv logger.Error("Unsupported protocol (must be unix:// or tcp://)", "proto", proto) return nil, newTestHarnessError(ErrInvalidParameters, nil, fmt.Sprintf("Unsupported protocol: %s", proto)) } - return privval.NewSignerValidatorEndpoint(logger, svln), nil + return privval.NewSignerListenerEndpoint(logger, svln), nil } func newTestHarnessError(code int, err error, info string) *TestHarnessError { diff --git a/tools/tm-signer-harness/internal/test_harness_test.go b/tools/tm-signer-harness/internal/test_harness_test.go index c249bd2b6..296b6d9c4 100644 --- a/tools/tm-signer-harness/internal/test_harness_test.go +++ b/tools/tm-signer-harness/internal/test_harness_test.go @@ -85,7 +85,7 @@ func TestRemoteSignerTestHarnessMaxAcceptRetriesReached(t *testing.T) { func TestRemoteSignerTestHarnessSuccessfulRun(t *testing.T) { harnessTest( t, - func(th *TestHarness) *privval.SignerServiceEndpoint { + func(th *TestHarness) *privval.SignerDialerEndpoint { return newMockRemoteSigner(t, th, th.fpv.Key.PrivKey, false, false) }, NoError, @@ -95,7 +95,7 @@ func TestRemoteSignerTestHarnessSuccessfulRun(t *testing.T) { func TestRemoteSignerPublicKeyCheckFailed(t *testing.T) { harnessTest( t, - func(th *TestHarness) *privval.SignerServiceEndpoint { + func(th *TestHarness) *privval.SignerDialerEndpoint { return newMockRemoteSigner(t, th, ed25519.GenPrivKey(), false, false) }, ErrTestPublicKeyFailed, @@ -105,7 +105,7 @@ func TestRemoteSignerPublicKeyCheckFailed(t *testing.T) { func TestRemoteSignerProposalSigningFailed(t *testing.T) { harnessTest( t, - func(th *TestHarness) *privval.SignerServiceEndpoint { + func(th *TestHarness) *privval.SignerDialerEndpoint { return newMockRemoteSigner(t, th, th.fpv.Key.PrivKey, true, false) }, ErrTestSignProposalFailed, @@ -115,15 +115,15 @@ func TestRemoteSignerProposalSigningFailed(t *testing.T) { func TestRemoteSignerVoteSigningFailed(t *testing.T) { harnessTest( t, - func(th *TestHarness) *privval.SignerServiceEndpoint { + func(th *TestHarness) *privval.SignerDialerEndpoint { return newMockRemoteSigner(t, th, th.fpv.Key.PrivKey, false, true) }, ErrTestSignVoteFailed, ) } -func newMockRemoteSigner(t *testing.T, th *TestHarness, privKey crypto.PrivKey, breakProposalSigning bool, breakVoteSigning bool) *privval.SignerServiceEndpoint { - return privval.NewSignerServiceEndpoint( +func newMockRemoteSigner(t *testing.T, th *TestHarness, privKey crypto.PrivKey, breakProposalSigning bool, breakVoteSigning bool) *privval.SignerDialerEndpoint { + return privval.NewSignerDialerEndpoint( th.logger, th.chainID, types.NewMockPVWithParams(privKey, breakProposalSigning, breakVoteSigning), @@ -136,7 +136,7 @@ func newMockRemoteSigner(t *testing.T, th *TestHarness, privKey crypto.PrivKey, } // For running relatively standard tests. -func harnessTest(t *testing.T, rsMaker func(th *TestHarness) *privval.SignerServiceEndpoint, expectedExitCode int) { +func harnessTest(t *testing.T, rsMaker func(th *TestHarness) *privval.SignerDialerEndpoint, expectedExitCode int) { cfg := makeConfig(t, 100, 3) defer cleanup(cfg)