ADR 034: PrivValidator file structure

Changelog

03-11-2018: Initial Draft

Context

For now, the PrivValidator file priv_validator.json contains mutable and immutable parts. Even in an insecure mode which does not encrypt private key on disk, it is reasonable to separate the mutable part and immutable part.

References: #1181 #2657 #2313

Proposed Solution

We can split mutable and immutable parts with two structs:

  1. // FilePVKey stores the immutable part of PrivValidator
  2. type FilePVKey struct {
  3. Address types.Address `json:"address"`
  4. PubKey crypto.PubKey `json:"pub_key"`
  5. PrivKey crypto.PrivKey `json:"priv_key"`
  6. filePath string
  7. }
  8. // FilePVState stores the mutable part of PrivValidator
  9. type FilePVLastSignState struct {
  10. Height int64 `json:"height"`
  11. Round int `json:"round"`
  12. Step int8 `json:"step"`
  13. Signature []byte `json:"signature,omitempty"`
  14. SignBytes cmn.HexBytes `json:"signbytes,omitempty"`
  15. filePath string
  16. mtx sync.Mutex
  17. }

Then we can combine FilePVKey with FilePVLastSignState and will get the original FilePV.

  1. type FilePV struct {
  2. Key FilePVKey
  3. LastSignState FilePVLastSignState
  4. }

As discussed, FilePV should be located in config, and FilePVLastSignState should be stored in data. The store path of each file should be specified in config.yml.

What we need to do next is changing the methods of FilePV.

Status

Draft.

Consequences

Positive

  • separate the mutable and immutable of PrivValidator

Negative

  • need to add more config for file path

Neutral