mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
* switch to amino for SignBytes and add Reply with error message - currently only Vote is done * switch Reply type in socket for other messages - add error description on error * add TODOs regarding error handling * address comments from peer review session (thx @xla) - contains all changes besides the test-coverage / error'ing branches * increase test coverage: - add tests for each newly introduced error'ing code path * return error if received wrong response * add test for wrong response branches (ErrUnexpectedResponse) * update CHANGELOG_PENDING and related documentation (spec) * fix typo: s/CanonicallockID/CanonicalBlockID * fixes from review
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package types
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
cmn "github.com/tendermint/tendermint/libs/common"
|
|
)
|
|
|
|
// Heartbeat is a simple vote-like structure so validators can
|
|
// alert others that they are alive and waiting for transactions.
|
|
// Note: We aren't adding ",omitempty" to Heartbeat's
|
|
// json field tags because we always want the JSON
|
|
// representation to be in its canonical form.
|
|
type Heartbeat struct {
|
|
ValidatorAddress Address `json:"validator_address"`
|
|
ValidatorIndex int `json:"validator_index"`
|
|
Height int64 `json:"height"`
|
|
Round int `json:"round"`
|
|
Sequence int `json:"sequence"`
|
|
Signature []byte `json:"signature"`
|
|
}
|
|
|
|
// SignBytes returns the Heartbeat bytes for signing.
|
|
// It panics if the Heartbeat is nil.
|
|
func (heartbeat *Heartbeat) SignBytes(chainID string) []byte {
|
|
bz, err := cdc.MarshalBinary(CanonicalizeHeartbeat(chainID, heartbeat))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bz
|
|
}
|
|
|
|
// Copy makes a copy of the Heartbeat.
|
|
func (heartbeat *Heartbeat) Copy() *Heartbeat {
|
|
if heartbeat == nil {
|
|
return nil
|
|
}
|
|
heartbeatCopy := *heartbeat
|
|
return &heartbeatCopy
|
|
}
|
|
|
|
// String returns a string representation of the Heartbeat.
|
|
func (heartbeat *Heartbeat) String() string {
|
|
if heartbeat == nil {
|
|
return "nil-heartbeat"
|
|
}
|
|
|
|
return fmt.Sprintf("Heartbeat{%v:%X %v/%02d (%v) %v}",
|
|
heartbeat.ValidatorIndex, cmn.Fingerprint(heartbeat.ValidatorAddress),
|
|
heartbeat.Height, heartbeat.Round, heartbeat.Sequence,
|
|
fmt.Sprintf("/%X.../", cmn.Fingerprint(heartbeat.Signature[:])))
|
|
}
|