privval

package
v0.28.0-dev0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2019 License: Apache-2.0 Imports: 19 Imported by: 1,070

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDialRetryMax       = errors.New("dialed maximum retries")
	ErrConnTimeout        = errors.New("remote signer timed out")
	ErrUnexpectedResponse = errors.New("received unexpected response")
)

Socket errors.

Functions

func RegisterRemoteSignerMsg

func RegisterRemoteSignerMsg(cdc *amino.Codec)

Types

type FilePV

type FilePV struct {
	Key           FilePVKey
	LastSignState FilePVLastSignState
}

FilePV implements PrivValidator using data persisted to disk to prevent double signing. NOTE: the directories containing pv.Key.filePath and pv.LastSignState.filePath must already exist. It includes the LastSignature and LastSignBytes so we don't lose the signature if the process crashes after signing but before the resulting consensus message is processed.

func GenFilePV

func GenFilePV(keyFilePath, stateFilePath string) *FilePV

GenFilePV generates a new validator with randomly generated private key and sets the filePaths, but does not call Save().

func LoadFilePV

func LoadFilePV(keyFilePath, stateFilePath string) *FilePV

LoadFilePV loads a FilePV from the filePaths. The FilePV handles double signing prevention by persisting data to the stateFilePath. If either file path does not exist, the program will exit.

func LoadFilePVEmptyState

func LoadFilePVEmptyState(keyFilePath, stateFilePath string) *FilePV

LoadFilePVEmptyState loads a FilePV from the given keyFilePath, with an empty LastSignState. If the keyFilePath does not exist, the program will exit.

func LoadOrGenFilePV

func LoadOrGenFilePV(keyFilePath, stateFilePath string) *FilePV

LoadOrGenFilePV loads a FilePV from the given filePaths or else generates a new one and saves it to the filePaths.

func (*FilePV) GetAddress

func (pv *FilePV) GetAddress() types.Address

GetAddress returns the address of the validator. Implements PrivValidator.

func (*FilePV) GetPubKey

func (pv *FilePV) GetPubKey() crypto.PubKey

GetPubKey returns the public key of the validator. Implements PrivValidator.

func (*FilePV) Reset

func (pv *FilePV) Reset()

Reset resets all fields in the FilePV. NOTE: Unsafe!

func (*FilePV) Save

func (pv *FilePV) Save()

Save persists the FilePV to disk.

func (*FilePV) SignProposal

func (pv *FilePV) SignProposal(chainID string, proposal *types.Proposal) error

SignProposal signs a canonical representation of the proposal, along with the chainID. Implements PrivValidator.

func (*FilePV) SignVote

func (pv *FilePV) SignVote(chainID string, vote *types.Vote) error

SignVote signs a canonical representation of the vote, along with the chainID. Implements PrivValidator.

func (*FilePV) String

func (pv *FilePV) String() string

String returns a string representation of the FilePV.

type FilePVKey

type FilePVKey struct {
	Address types.Address  `json:"address"`
	PubKey  crypto.PubKey  `json:"pub_key"`
	PrivKey crypto.PrivKey `json:"priv_key"`
	// contains filtered or unexported fields
}

FilePVKey stores the immutable part of PrivValidator.

func (FilePVKey) Save

func (pvKey FilePVKey) Save()

Save persists the FilePVKey to its filePath.

type FilePVLastSignState

type FilePVLastSignState struct {
	Height    int64        `json:"height"`
	Round     int          `json:"round"`
	Step      int8         `json:"step"`
	Signature []byte       `json:"signature,omitempty"`
	SignBytes cmn.HexBytes `json:"signbytes,omitempty"`
	// contains filtered or unexported fields
}

FilePVLastSignState stores the mutable part of PrivValidator.

func (*FilePVLastSignState) CheckHRS

func (lss *FilePVLastSignState) CheckHRS(height int64, round int, step int8) (bool, error)

CheckHRS checks the given height, round, step (HRS) against that of the FilePVLastSignState. It returns an error if the arguments constitute a regression, or if they match but the SignBytes are empty. The returned boolean indicates whether the last Signature should be reused - it returns true if the HRS matches the arguments and the SignBytes are not empty (indicating we have already signed for this HRS, and can reuse the existing signature). It panics if the HRS matches the arguments, there's a SignBytes, but no Signature.

func (*FilePVLastSignState) Save

func (lss *FilePVLastSignState) Save()

Save persists the FilePvLastSignState to its filePath.

type IPCRemoteSigner added in v0.26.0

type IPCRemoteSigner struct {
	cmn.BaseService
	// contains filtered or unexported fields
}

IPCRemoteSigner is a RPC implementation of PrivValidator that listens on a unix socket.

func NewIPCRemoteSigner added in v0.26.0

func NewIPCRemoteSigner(
	logger log.Logger,
	chainID, socketAddr string,
	privVal types.PrivValidator,
) *IPCRemoteSigner

NewIPCRemoteSigner returns an instance of IPCRemoteSigner.

func (*IPCRemoteSigner) OnStart added in v0.26.0

func (rs *IPCRemoteSigner) OnStart() error

OnStart implements cmn.Service.

func (*IPCRemoteSigner) OnStop added in v0.26.0

func (rs *IPCRemoteSigner) OnStop()

OnStop implements cmn.Service.

type IPCRemoteSignerOption added in v0.26.0

type IPCRemoteSignerOption func(*IPCRemoteSigner)

IPCRemoteSignerOption sets an optional parameter on the IPCRemoteSigner.

func IPCRemoteSignerConnDeadline added in v0.26.0

func IPCRemoteSignerConnDeadline(deadline time.Duration) IPCRemoteSignerOption

IPCRemoteSignerConnDeadline sets the read and write deadline for connections from external signing processes.

func IPCRemoteSignerConnRetries added in v0.26.0

func IPCRemoteSignerConnRetries(retries int) IPCRemoteSignerOption

IPCRemoteSignerConnRetries sets the amount of attempted retries to connect.

type IPCVal added in v0.26.0

type IPCVal struct {
	cmn.BaseService
	*RemoteSignerClient
	// contains filtered or unexported fields
}

IPCVal implements PrivValidator, it uses a unix socket to request signatures from an external process.

func NewIPCVal added in v0.26.0

func NewIPCVal(
	logger log.Logger,
	socketAddr string,
) *IPCVal

NewIPCVal returns an instance of IPCVal.

func (*IPCVal) OnStart added in v0.26.0

func (sc *IPCVal) OnStart() error

OnStart implements cmn.Service.

func (*IPCVal) OnStop added in v0.26.0

func (sc *IPCVal) OnStop()

OnStop implements cmn.Service.

type IPCValOption added in v0.26.0

type IPCValOption func(*IPCVal)

IPCValOption sets an optional parameter on the SocketPV.

func IPCValConnTimeout added in v0.26.0

func IPCValConnTimeout(timeout time.Duration) IPCValOption

IPCValConnTimeout sets the read and write timeout for connections from external signing processes.

func IPCValHeartbeat added in v0.26.0

func IPCValHeartbeat(period time.Duration) IPCValOption

IPCValHeartbeat sets the period on which to check the liveness of the connected Signer connections.

type OldFilePV

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"`
	// contains filtered or unexported fields
}

OldFilePV is the old version of the FilePV, pre v0.28.0.

func LoadOldFilePV

func LoadOldFilePV(filePath string) (*OldFilePV, error)

LoadOldFilePV loads an OldFilePV from the filePath.

func (*OldFilePV) Upgrade

func (oldFilePV *OldFilePV) Upgrade(keyFilePath, stateFilePath string) *FilePV

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".

type PingRequest

type PingRequest struct {
}

PingRequest is a PrivValidatorSocket message to keep the connection alive.

type PingResponse

type PingResponse struct {
}

type PubKeyRequest

type PubKeyRequest struct{}

PubKeyRequest requests the consensus public key from the remote signer.

type PubKeyResponse

type PubKeyResponse struct {
	PubKey crypto.PubKey
	Error  *RemoteSignerError
}

PubKeyResponse is a PrivValidatorSocket message containing the public key.

type RemoteSigner added in v0.19.9

type RemoteSigner struct {
	cmn.BaseService
	// contains filtered or unexported fields
}

RemoteSigner implements PrivValidator by dialing to a socket.

func NewRemoteSigner added in v0.19.9

func NewRemoteSigner(
	logger log.Logger,
	chainID, socketAddr string,
	privVal types.PrivValidator,
	privKey ed25519.PrivKeyEd25519,
) *RemoteSigner

NewRemoteSigner returns an instance of RemoteSigner.

func (*RemoteSigner) OnStart added in v0.19.9

func (rs *RemoteSigner) OnStart() error

OnStart implements cmn.Service.

func (*RemoteSigner) OnStop added in v0.19.9

func (rs *RemoteSigner) OnStop()

OnStop implements cmn.Service.

type RemoteSignerClient added in v0.26.0

type RemoteSignerClient struct {
	// contains filtered or unexported fields
}

RemoteSignerClient implements PrivValidator, it uses a socket to request signatures from an external process.

func NewRemoteSignerClient added in v0.26.0

func NewRemoteSignerClient(
	conn net.Conn,
) (*RemoteSignerClient, error)

NewRemoteSignerClient returns an instance of RemoteSignerClient.

func (*RemoteSignerClient) GetPubKey added in v0.26.0

func (sc *RemoteSignerClient) GetPubKey() crypto.PubKey

GetPubKey implements PrivValidator.

func (*RemoteSignerClient) Ping added in v0.26.0

func (sc *RemoteSignerClient) Ping() error

Ping is used to check connection health.

func (*RemoteSignerClient) SignProposal added in v0.26.0

func (sc *RemoteSignerClient) SignProposal(
	chainID string,
	proposal *types.Proposal,
) error

SignProposal implements PrivValidator.

func (*RemoteSignerClient) SignVote added in v0.26.0

func (sc *RemoteSignerClient) SignVote(chainID string, vote *types.Vote) error

SignVote implements PrivValidator.

type RemoteSignerError

type RemoteSignerError struct {
	// TODO(ismail): create an enum of known errors
	Code        int
	Description string
}

RemoteSignerError allows (remote) validators to include meaningful error descriptions in their reply.

func (*RemoteSignerError) Error

func (e *RemoteSignerError) Error() string

type RemoteSignerMsg

type RemoteSignerMsg interface{}

RemoteSignerMsg is sent between RemoteSigner and the RemoteSigner client.

type RemoteSignerOption added in v0.19.9

type RemoteSignerOption func(*RemoteSigner)

RemoteSignerOption sets an optional parameter on the RemoteSigner.

func RemoteSignerConnDeadline added in v0.19.9

func RemoteSignerConnDeadline(deadline time.Duration) RemoteSignerOption

RemoteSignerConnDeadline sets the read and write deadline for connections from external signing processes.

func RemoteSignerConnRetries added in v0.19.9

func RemoteSignerConnRetries(retries int) RemoteSignerOption

RemoteSignerConnRetries sets the amount of attempted retries to connect.

type SignProposalRequest

type SignProposalRequest struct {
	Proposal *types.Proposal
}

SignProposalRequest is a PrivValidatorSocket message containing a Proposal.

type SignVoteRequest

type SignVoteRequest struct {
	Vote *types.Vote
}

SignVoteRequest is a PrivValidatorSocket message containing a vote.

type SignedProposalResponse

type SignedProposalResponse struct {
	Proposal *types.Proposal
	Error    *RemoteSignerError
}

type SignedVoteResponse

type SignedVoteResponse struct {
	Vote  *types.Vote
	Error *RemoteSignerError
}

SignedVoteResponse is a PrivValidatorSocket message containing a signed vote along with a potenial error message.

type TCPVal added in v0.26.0

type TCPVal struct {
	cmn.BaseService
	*RemoteSignerClient
	// contains filtered or unexported fields
}

TCPVal implements PrivValidator, it uses a socket to request signatures from an external process.

func NewTCPVal added in v0.26.0

func NewTCPVal(
	logger log.Logger,
	socketAddr string,
	privKey ed25519.PrivKeyEd25519,
) *TCPVal

NewTCPVal returns an instance of TCPVal.

func (*TCPVal) OnStart added in v0.26.0

func (sc *TCPVal) OnStart() error

OnStart implements cmn.Service.

func (*TCPVal) OnStop added in v0.26.0

func (sc *TCPVal) OnStop()

OnStop implements cmn.Service.

type TCPValOption added in v0.26.0

type TCPValOption func(*TCPVal)

TCPValOption sets an optional parameter on the SocketPV.

func TCPValAcceptDeadline added in v0.26.0

func TCPValAcceptDeadline(deadline time.Duration) TCPValOption

TCPValAcceptDeadline sets the deadline for the TCPVal listener. A zero time value disables the deadline.

func TCPValConnTimeout added in v0.26.0

func TCPValConnTimeout(timeout time.Duration) TCPValOption

TCPValConnTimeout sets the read and write timeout for connections from external signing processes.

func TCPValHeartbeat added in v0.26.0

func TCPValHeartbeat(period time.Duration) TCPValOption

TCPValHeartbeat sets the period on which to check the liveness of the connected Signer connections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL