mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 06:54:41 +00:00
Proposer->Proposal; sign heartbeats
This commit is contained in:
@@ -293,6 +293,15 @@ func (privVal *ByzantinePrivValidator) SignProposal(chainID string, proposal *ty
|
||||
return nil
|
||||
}
|
||||
|
||||
func (privVal *ByzantinePrivValidator) SignHeartbeat(chainID string, heartbeat *types.Heartbeat) error {
|
||||
privVal.mtx.Lock()
|
||||
defer privVal.mtx.Unlock()
|
||||
|
||||
// Sign
|
||||
heartbeat.Signature = privVal.Sign(types.SignBytes(chainID, heartbeat))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (privVal *ByzantinePrivValidator) String() string {
|
||||
return Fmt("PrivValidator{%X}", privVal.Address)
|
||||
}
|
||||
|
||||
+10
-18
@@ -312,19 +312,14 @@ func (conR *ConsensusReactor) registerEventCallbacks() {
|
||||
conR.broadcastHasVoteMessage(edv.Vote)
|
||||
})
|
||||
|
||||
types.AddListenerForEvent(conR.evsw, "conR", types.EventStringProposerHeartbeat(), func(data types.TMEventData) {
|
||||
heartbeat := data.Unwrap().(types.EventDataProposerHeartbeat)
|
||||
conR.broadcastProposerHeartbeatMessage(heartbeat)
|
||||
types.AddListenerForEvent(conR.evsw, "conR", types.EventStringProposalHeartbeat(), func(data types.TMEventData) {
|
||||
heartbeat := data.Unwrap().(types.EventDataProposalHeartbeat)
|
||||
conR.broadcastProposalHeartbeatMessage(heartbeat)
|
||||
})
|
||||
}
|
||||
|
||||
func (conR *ConsensusReactor) broadcastProposerHeartbeatMessage(heartbeat types.EventDataProposerHeartbeat) {
|
||||
msg := &ProposerHeartbeatMessage{
|
||||
Height: heartbeat.Height,
|
||||
Round: heartbeat.Round,
|
||||
Proposer: heartbeat.Proposer,
|
||||
Sequence: heartbeat.Sequence,
|
||||
}
|
||||
func (conR *ConsensusReactor) broadcastProposalHeartbeatMessage(heartbeat types.EventDataProposalHeartbeat) {
|
||||
msg := &ProposalHeartbeatMessage{heartbeat.Heartbeat}
|
||||
conR.Switch.Broadcast(StateChannel, struct{ ConsensusMessage }{msg})
|
||||
}
|
||||
|
||||
@@ -1323,15 +1318,12 @@ func (m *VoteSetBitsMessage) String() string {
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
// ProposerHeartbeatMessage is sent to signal that the proposer is alive and waiting for transactions
|
||||
type ProposerHeartbeatMessage struct {
|
||||
Height int
|
||||
Round int
|
||||
Proposer []byte
|
||||
Sequence int
|
||||
// ProposalHeartbeatMessage is sent to signal that the proposer is alive and waiting for transactions
|
||||
type ProposalHeartbeatMessage struct {
|
||||
Heartbeat *types.Heartbeat
|
||||
}
|
||||
|
||||
// String returns a string representation.
|
||||
func (m *ProposerHeartbeatMessage) String() string {
|
||||
return fmt.Sprintf("[HEARTBEAT %v/%02d %X %d]", m.Height, m.Round, m.Proposer, m.Sequence)
|
||||
func (m *ProposalHeartbeatMessage) String() string {
|
||||
return fmt.Sprintf("[HEARTBEAT %v]", m.Heartbeat)
|
||||
}
|
||||
|
||||
+16
-2
@@ -181,6 +181,7 @@ type PrivValidator interface {
|
||||
GetAddress() []byte
|
||||
SignVote(chainID string, vote *types.Vote) error
|
||||
SignProposal(chainID string, proposal *types.Proposal) error
|
||||
SignHeartbeat(chainID string, heartbeat *types.Heartbeat) error
|
||||
}
|
||||
|
||||
// ConsensusState handles execution of the consensus algorithm.
|
||||
@@ -810,13 +811,26 @@ func (cs *ConsensusState) needProofBlock(height int) bool {
|
||||
func (cs *ConsensusState) proposalHeartbeat() {
|
||||
counter := 0
|
||||
addr := cs.privValidator.GetAddress()
|
||||
valIndex, v := cs.Validators.GetByAddress(addr)
|
||||
if v == nil {
|
||||
// not a validator
|
||||
valIndex = -1
|
||||
}
|
||||
for {
|
||||
select {
|
||||
default:
|
||||
if cs.evsw != nil {
|
||||
rs := cs.GetRoundState().RoundStateEvent()
|
||||
heartbeat := types.EventDataProposerHeartbeat{rs, addr, counter}
|
||||
types.FireEventProposerHeartbeat(cs.evsw, heartbeat)
|
||||
heartbeat := &types.Heartbeat{
|
||||
Height: rs.Height,
|
||||
Round: rs.Round,
|
||||
Sequence: counter,
|
||||
ValidatorAddress: addr,
|
||||
ValidatorIndex: valIndex,
|
||||
}
|
||||
cs.privValidator.SignHeartbeat(cs.state.ChainID, heartbeat)
|
||||
heartbeatEvent := types.EventDataProposalHeartbeat{heartbeat}
|
||||
types.FireEventProposalHeartbeat(cs.evsw, heartbeatEvent)
|
||||
counter += 1
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
|
||||
Reference in New Issue
Block a user