Ethan Buchman 6 years ago
committed by Anton Kaliaev
parent
commit
d1afa0ed6c
3 changed files with 7 additions and 32 deletions
  1. +1
    -1
      cmd/priv_val_server/main.go
  2. +1
    -1
      node/node.go
  3. +5
    -30
      privval/client.go

+ 1
- 1
cmd/priv_val_server/main.go View File

@ -45,7 +45,7 @@ func main() {
dialer = privval.DialTCPFn(address, connTimeout, ed25519.GenPrivKey())
default:
logger.Error("Unknown protocol", "protocol", protocol)
return
os.Exit(1)
}
rs := privval.NewRemoteSigner(logger, *chainID, pv, dialer)


+ 1
- 1
node/node.go View File

@ -901,7 +901,7 @@ func createAndStartPrivValidatorSocketClient(
pvsc := privval.NewSocketVal(logger.With("module", "privval"), listener)
if err := pvsc.Start(); err != nil {
return nil, errors.Wrap(err, "failed to start")
return nil, errors.Wrap(err, "failed to start private validator")
}
return pvsc, nil


+ 5
- 30
privval/client.go View File

@ -191,19 +191,19 @@ func (sc *SocketVal) OnStop() {
// connection is closed in OnStop.
// returns true if the listener is closed
// (ie. it returns a nil conn).
func (sc *SocketVal) reset() (bool, error) {
func (sc *SocketVal) reset() (closed bool, err error) {
sc.mtx.Lock()
defer sc.mtx.Unlock()
// first check if the conn already exists and close it.
if sc.signer != nil {
if err := sc.signer.Close(); err != nil {
sc.Logger.Error("error closing connection", "err", err)
sc.Logger.Error("error closing socket val connection during reset", "err", err)
}
}
// wait for a new conn
conn, err := sc.waitConnection()
conn, err := sc.acceptConnection()
if err != nil {
return false, err
}
@ -224,6 +224,8 @@ func (sc *SocketVal) reset() (bool, error) {
return false, nil
}
// Attempt to accept a connection.
// Times out after the listener's acceptDeadline
func (sc *SocketVal) acceptConnection() (net.Conn, error) {
conn, err := sc.listener.Accept()
if err != nil {
@ -231,33 +233,6 @@ func (sc *SocketVal) acceptConnection() (net.Conn, error) {
return nil, nil // Ignore error from listener closing.
}
return nil, err
}
return conn, nil
}
// waitConnection uses the configured wait timeout to error if no external
// process connects in the time period.
func (sc *SocketVal) waitConnection() (net.Conn, error) {
var (
connc = make(chan net.Conn, 1)
errc = make(chan error, 1)
)
go func(connc chan<- net.Conn, errc chan<- error) {
conn, err := sc.acceptConnection()
if err != nil {
errc <- err
return
}
connc <- conn
}(connc, errc)
select {
case conn := <-connc:
return conn, nil
case err := <-errc:
return nil, err
}
}

Loading…
Cancel
Save