You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.8 KiB

  1. # ADR 008: PrivValidator
  2. ## Context
  3. The current PrivValidator is monolithic and isn't easily reuseable by alternative signers.
  4. For instance, see https://github.com/tendermint/tendermint/issues/673
  5. The goal is to have a clean PrivValidator interface like:
  6. ```
  7. type PrivValidator interface {
  8. Address() data.Bytes
  9. PubKey() crypto.PubKey
  10. SignVote(chainID string, vote *types.Vote) error
  11. SignProposal(chainID string, proposal *types.Proposal) error
  12. SignHeartbeat(chainID string, heartbeat *types.Heartbeat) error
  13. }
  14. ```
  15. It should also be easy to re-use the LastSignedInfo logic to avoid double signing.
  16. ## Decision
  17. Tendermint node's should support only two in-process PrivValidator implementations:
  18. - PrivValidatorUnencrypted uses an unencrypted private key in a "priv_validator.json" file - no configuration required (just `tendermint init`).
  19. - PrivValidatorSocket uses a socket to send signing requests to another process - user is responsible for starting that process themselves.
  20. The PrivValidatorSocket address can be provided via flags at the command line -
  21. doing so will cause Tendermint to ignore any "priv_validator.json" file and to listen
  22. on the given address for incoming connections from an external priv_validator process.
  23. It will halt any operation until at least one external process succesfully
  24. connected.
  25. The external priv_validator process will dial the address to connect to Tendermint,
  26. and then Tendermint will send requests on the ensuing connection to sign votes and proposals.
  27. Thus the external process initiates the connection, but the Tendermint process makes all requests.
  28. In a later stage we're going to support multiple validators for fault
  29. tolerance. To prevent double signing they need to be synced, which is deferred
  30. to an external solution (see #1185).
  31. In addition, Tendermint will provide implementations that can be run in that external process.
  32. These include:
  33. - PrivValidatorEncrypted uses an encrypted private key persisted to disk - user must enter password to decrypt key when process is started.
  34. - PrivValidatorLedger uses a Ledger Nano S to handle all signing.
  35. What follows are descriptions of useful types
  36. ### Signer
  37. ```
  38. type Signer interface {
  39. Sign(msg []byte) (crypto.Signature, error)
  40. }
  41. ```
  42. Signer signs a message. It can also return an error.
  43. ### ValidatorID
  44. ValidatorID is just the Address and PubKey
  45. ```
  46. type ValidatorID struct {
  47. Address data.Bytes `json:"address"`
  48. PubKey crypto.PubKey `json:"pub_key"`
  49. }
  50. ```
  51. ### LastSignedInfo
  52. LastSignedInfo tracks the last thing we signed:
  53. ```
  54. type LastSignedInfo struct {
  55. Height int64 `json:"height"`
  56. Round int `json:"round"`
  57. Step int8 `json:"step"`
  58. Signature crypto.Signature `json:"signature,omitempty"` // so we dont lose signatures
  59. SignBytes data.Bytes `json:"signbytes,omitempty"` // so we dont lose signatures
  60. }
  61. ```
  62. It exposes methods for signing votes and proposals using a `Signer`.
  63. This allows it to easily be reused by developers implemented their own PrivValidator.
  64. ### PrivValidatorUnencrypted
  65. ```
  66. type PrivValidatorUnencrypted struct {
  67. ID types.ValidatorID `json:"id"`
  68. PrivKey PrivKey `json:"priv_key"`
  69. LastSignedInfo *LastSignedInfo `json:"last_signed_info"`
  70. }
  71. ```
  72. Has the same structure as currently, but broken up into sub structs.
  73. Note the LastSignedInfo is mutated in place every time we sign.
  74. ### PrivValidatorJSON
  75. The "priv_validator.json" file supports only the PrivValidatorUnencrypted type.
  76. It unmarshals into PrivValidatorJSON, which is used as the default PrivValidator type.
  77. It wraps the PrivValidatorUnencrypted and persists it to disk after every signature.
  78. ## Status
  79. Accepted.
  80. ## Consequences
  81. ### Positive
  82. - Cleaner separation of components enabling re-use.
  83. ### Negative
  84. - More files - led to creation of new directory.
  85. ### Neutral