Prevent handle consensus messages before the module is started
@@ -108,6 +108,7 @@ func (ew *endorsementWrapper) Topic() endorsement.ConsensusVoteTopic {
type RollDPoS struct {
cfsm *consensusfsm.ConsensusFSM
ctx *rollDPoSCtx
+ ready chan interface{}
}
// Start starts RollDPoS consensus
@@ -117,6 +118,7 @@ func (r *RollDPoS) Start(ctx context.Context) error {
}
r.ctx.round = &roundCtx{height: 0}
r.cfsm.ProducePrepareEvent(r.ctx.cfg.Delay)
+ close(r.ready)
return nil
}
@@ -127,6 +129,7 @@ func (r *RollDPoS) Stop(ctx context.Context) error {
// HandleConsensusMsg handles incoming consensus message
func (r *RollDPoS) HandleConsensusMsg(msg *iotexrpc.Consensus) error {
+ <-r.ready
consensusHeight := r.ctx.Height()
if consensusHeight != 0 && msg.Height < consensusHeight {
log.L().Debug(
@@ -377,5 +380,6 @@ func (b *Builder) Build() (*RollDPoS, error) {
return &RollDPoS{
cfsm: cfsm,
ctx: &ctx,
+ ready: make(chan interface{}),
}, nil
}
