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.
40 lines
1.1 KiB
40 lines
1.1 KiB
package consensus
|
|
|
|
import (
|
|
msg_pb "github.com/harmony-one/harmony/api/proto/message"
|
|
"github.com/harmony-one/harmony/consensus"
|
|
"github.com/harmony-one/harmony/internal/utils"
|
|
)
|
|
|
|
// Service is the consensus service.
|
|
type Service struct {
|
|
consensus *consensus.Consensus
|
|
stopChan chan struct{}
|
|
stoppedChan chan struct{}
|
|
startChan chan struct{}
|
|
messageChan chan *msg_pb.Message
|
|
}
|
|
|
|
// New returns consensus service.
|
|
func New(consensus *consensus.Consensus, startChan chan struct{}) *Service {
|
|
return &Service{consensus: consensus, startChan: startChan}
|
|
}
|
|
|
|
// Start starts consensus service.
|
|
func (s *Service) Start() error {
|
|
utils.Logger().Info().Msg("[consensus/service] Starting consensus service.")
|
|
s.stopChan = make(chan struct{})
|
|
s.stoppedChan = make(chan struct{})
|
|
s.consensus.Start(s.stopChan, s.stoppedChan, s.startChan)
|
|
s.consensus.WaitForNewRandomness()
|
|
return nil
|
|
}
|
|
|
|
// Stop stops consensus service.
|
|
func (s *Service) Stop() error {
|
|
utils.Logger().Info().Msg("Stopping consensus service.")
|
|
s.stopChan <- struct{}{}
|
|
<-s.stoppedChan
|
|
utils.Logger().Info().Msg("Consensus service stopped.")
|
|
return s.consensus.Close()
|
|
}
|
|
|