mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-04 11:02:13 +00:00
* Close and recreate a RemoteSigner on err * Update changelog * Address Anton's comments / suggestions: - update changelog - restart TCPVal - shut down on `ErrUnexpectedResponse` * re-init remote signer client with fresh connection if Ping fails - add/update TODOs in secret connection - rename tcp.go -> tcp_client.go, same with ipc to clarify their purpose * account for `conn returned by waitConnection can be `nil` - also add TODO about RemoteSigner conn field * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn * Tests for retrying: IPC / TCP - shorter info log on success - set conn and use it in tests to close conn - add rwmutex for conn field in IPC * comments and doc.go * fix ipc tests. fixes #2677 * use constants for tests * cleanup some error statements * fixes #2784, race in tests * remove print statement * minor fixes from review * update comment on sts spec * cosmetics * p2p/conn: add failing tests * p2p/conn: make SecretConnection thread safe * changelog * IPCVal signer refactor - use a .reset() method - don't use embedded RemoteSignerClient - guard RemoteSignerClient with mutex - drop the .conn - expose Close() on RemoteSignerClient * apply IPCVal refactor to TCPVal * remove mtx from RemoteSignerClient * consolidate IPCVal and TCPVal, fixes #3104 - done in tcp_client.go - now called SocketVal - takes a listener in the constructor - make tcpListener and unixListener contain all the differences * delete ipc files * introduce unix and tcp dialer for RemoteSigner * rename files - drop tcp_ prefix - rename priv_validator.go to file.go * bring back listener options * fix node * fix priv_val_server * fix node test * minor cleanup and comments
81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
package privval
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
// OldFilePV is the old version of the FilePV, pre v0.28.0.
|
|
type OldFilePV struct {
|
|
Address types.Address `json:"address"`
|
|
PubKey crypto.PubKey `json:"pub_key"`
|
|
LastHeight int64 `json:"last_height"`
|
|
LastRound int `json:"last_round"`
|
|
LastStep int8 `json:"last_step"`
|
|
LastSignature []byte `json:"last_signature,omitempty"`
|
|
LastSignBytes cmn.HexBytes `json:"last_signbytes,omitempty"`
|
|
PrivKey crypto.PrivKey `json:"priv_key"`
|
|
|
|
filePath string
|
|
}
|
|
|
|
// LoadOldFilePV loads an OldFilePV from the filePath.
|
|
func LoadOldFilePV(filePath string) (*OldFilePV, error) {
|
|
pvJSONBytes, err := ioutil.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
pv := &OldFilePV{}
|
|
err = cdc.UnmarshalJSON(pvJSONBytes, &pv)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// overwrite pubkey and address for convenience
|
|
pv.PubKey = pv.PrivKey.PubKey()
|
|
pv.Address = pv.PubKey.Address()
|
|
|
|
pv.filePath = filePath
|
|
return pv, nil
|
|
}
|
|
|
|
// Upgrade convets the OldFilePV to the new FilePV, separating the immutable and mutable components,
|
|
// and persisting them to the keyFilePath and stateFilePath, respectively.
|
|
// It renames the original file by adding ".bak".
|
|
func (oldFilePV *OldFilePV) Upgrade(keyFilePath, stateFilePath string) *FilePV {
|
|
privKey := oldFilePV.PrivKey
|
|
pvKey := FilePVKey{
|
|
PrivKey: privKey,
|
|
PubKey: privKey.PubKey(),
|
|
Address: privKey.PubKey().Address(),
|
|
filePath: keyFilePath,
|
|
}
|
|
|
|
pvState := FilePVLastSignState{
|
|
Height: oldFilePV.LastHeight,
|
|
Round: oldFilePV.LastRound,
|
|
Step: oldFilePV.LastStep,
|
|
Signature: oldFilePV.LastSignature,
|
|
SignBytes: oldFilePV.LastSignBytes,
|
|
filePath: stateFilePath,
|
|
}
|
|
|
|
// Save the new PV files
|
|
pv := &FilePV{
|
|
Key: pvKey,
|
|
LastSignState: pvState,
|
|
}
|
|
pv.Save()
|
|
|
|
// Rename the old PV file
|
|
err := os.Rename(oldFilePV.filePath, oldFilePV.filePath+".bak")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return pv
|
|
}
|