Proposer->Proposal; sign heartbeats

This commit is contained in:
Ethan Buchman
2017-07-29 17:04:28 -04:00
parent 10f8101314
commit ab753abfa0
6 changed files with 74 additions and 32 deletions
+23
View File
@@ -31,6 +31,14 @@ type CanonicalJSONVote struct {
Type byte `json:"type"`
}
type CanonicalJSONHeartbeat struct {
Height int `json:"height"`
Round int `json:"round"`
Sequence int `json:"sequence"`
ValidatorAddress data.Bytes `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
}
//------------------------------------
// Messages including a "chain id" can only be applied to one chain, hence "Once"
@@ -44,6 +52,11 @@ type CanonicalJSONOnceVote struct {
Vote CanonicalJSONVote `json:"vote"`
}
type CanonicalJSONOnceHeartbeat struct {
ChainID string `json:"chain_id"`
Heartbeat CanonicalJSONHeartbeat `json:"heartbeat"`
}
//-----------------------------------
// Canonicalize the structs
@@ -79,3 +92,13 @@ func CanonicalVote(vote *Vote) CanonicalJSONVote {
vote.Type,
}
}
func CanonicalHeartbeat(heartbeat *Heartbeat) CanonicalJSONHeartbeat {
return CanonicalJSONHeartbeat{
heartbeat.Height,
heartbeat.Round,
heartbeat.Sequence,
heartbeat.ValidatorAddress,
heartbeat.ValidatorIndex,
}
}
+9 -12
View File
@@ -31,7 +31,7 @@ func EventStringRelock() string { return "Relock" }
func EventStringTimeoutWait() string { return "TimeoutWait" }
func EventStringVote() string { return "Vote" }
func EventStringProposerHeartbeat() string { return "ProposerHeartbeat" }
func EventStringProposalHeartbeat() string { return "ProposalHeartbeat" }
//----------------------------------------
@@ -42,7 +42,7 @@ var (
EventDataNameRoundState = "round_state"
EventDataNameVote = "vote"
EventDataNameProposerHeartbeat = "proposer_heartbeat"
EventDataNameProposalHeartbeat = "proposer_heartbeat"
)
//----------------------------------------
@@ -89,7 +89,7 @@ const (
EventDataTypeRoundState = byte(0x11)
EventDataTypeVote = byte(0x12)
EventDataTypeProposerHeartbeat = byte(0x20)
EventDataTypeProposalHeartbeat = byte(0x20)
)
var tmEventDataMapper = data.NewMapper(TMEventData{}).
@@ -98,7 +98,7 @@ var tmEventDataMapper = data.NewMapper(TMEventData{}).
RegisterImplementation(EventDataTx{}, EventDataNameTx, EventDataTypeTx).
RegisterImplementation(EventDataRoundState{}, EventDataNameRoundState, EventDataTypeRoundState).
RegisterImplementation(EventDataVote{}, EventDataNameVote, EventDataTypeVote).
RegisterImplementation(EventDataProposerHeartbeat{}, EventDataNameProposerHeartbeat, EventDataTypeProposerHeartbeat)
RegisterImplementation(EventDataProposalHeartbeat{}, EventDataNameProposalHeartbeat, EventDataTypeProposalHeartbeat)
// Most event messages are basic types (a block, a transaction)
// but some (an input to a call tx or a receive) are more exotic
@@ -122,11 +122,8 @@ type EventDataTx struct {
Error string `json:"error"` // this is redundant information for now
}
type EventDataProposerHeartbeat struct {
EventDataRoundState
Proposer []byte `json:"proposer"`
Sequence int `json:"sequence"`
type EventDataProposalHeartbeat struct {
Heartbeat *Heartbeat
}
// NOTE: This goes into the replay WAL
@@ -149,7 +146,7 @@ func (_ EventDataTx) AssertIsTMEventData() {}
func (_ EventDataRoundState) AssertIsTMEventData() {}
func (_ EventDataVote) AssertIsTMEventData() {}
func (_ EventDataProposerHeartbeat) AssertIsTMEventData() {}
func (_ EventDataProposalHeartbeat) AssertIsTMEventData() {}
//----------------------------------------
// Wrappers for type safety
@@ -249,6 +246,6 @@ func FireEventLock(fireable events.Fireable, rs EventDataRoundState) {
fireEvent(fireable, EventStringLock(), TMEventData{rs})
}
func FireEventProposerHeartbeat(fireable events.Fireable, rs EventDataProposerHeartbeat) {
fireEvent(fireable, EventStringProposerHeartbeat(), TMEventData{rs})
func FireEventProposalHeartbeat(fireable events.Fireable, rs EventDataProposalHeartbeat) {
fireEvent(fireable, EventStringProposalHeartbeat(), TMEventData{rs})
}
+7
View File
@@ -252,6 +252,13 @@ func (privVal *PrivValidator) signBytesHRS(height, round int, step int8, signByt
}
func (privVal *PrivValidator) SignHeartbeat(chainID string, heartbeat *Heartbeat) error {
privVal.mtx.Lock()
defer privVal.mtx.Unlock()
heartbeat.Signature = privVal.Sign(SignBytes(chainID, heartbeat))
return nil
}
func (privVal *PrivValidator) String() string {
return fmt.Sprintf("PrivValidator{%v LH:%v, LR:%v, LS:%v}", privVal.Address, privVal.LastHeight, privVal.LastRound, privVal.LastStep)
}