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.

52 lines
1.5 KiB

  1. package types
  2. import (
  3. "fmt"
  4. "github.com/tendermint/tendermint/crypto"
  5. cmn "github.com/tendermint/tendermint/libs/common"
  6. )
  7. // Heartbeat is a simple vote-like structure so validators can
  8. // alert others that they are alive and waiting for transactions.
  9. // Note: We aren't adding ",omitempty" to Heartbeat's
  10. // json field tags because we always want the JSON
  11. // representation to be in its canonical form.
  12. type Heartbeat struct {
  13. ValidatorAddress Address `json:"validator_address"`
  14. ValidatorIndex int `json:"validator_index"`
  15. Height int64 `json:"height"`
  16. Round int `json:"round"`
  17. Sequence int `json:"sequence"`
  18. Signature crypto.Signature `json:"signature"`
  19. }
  20. // SignBytes returns the Heartbeat bytes for signing.
  21. // It panics if the Heartbeat is nil.
  22. func (heartbeat *Heartbeat) SignBytes(chainID string) []byte {
  23. bz, err := cdc.MarshalJSON(CanonicalHeartbeat(chainID, heartbeat))
  24. if err != nil {
  25. panic(err)
  26. }
  27. return bz
  28. }
  29. // Copy makes a copy of the Heartbeat.
  30. func (heartbeat *Heartbeat) Copy() *Heartbeat {
  31. if heartbeat == nil {
  32. return nil
  33. }
  34. heartbeatCopy := *heartbeat
  35. return &heartbeatCopy
  36. }
  37. // String returns a string representation of the Heartbeat.
  38. func (heartbeat *Heartbeat) String() string {
  39. if heartbeat == nil {
  40. return "nil-heartbeat"
  41. }
  42. return fmt.Sprintf("Heartbeat{%v:%X %v/%02d (%v) %v}",
  43. heartbeat.ValidatorIndex, cmn.Fingerprint(heartbeat.ValidatorAddress),
  44. heartbeat.Height, heartbeat.Round, heartbeat.Sequence, heartbeat.Signature)
  45. }