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.
50 lines
1.7 KiB
50 lines
1.7 KiB
package blockproposal
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
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 a block proposal service.
|
|
type Service struct {
|
|
stopChan chan struct{}
|
|
stoppedChan chan struct{}
|
|
readySignal chan consensus.ProposalType
|
|
commitSigsChan chan []byte
|
|
messageChan chan *msg_pb.Message
|
|
waitForConsensusReady func(readySignal chan consensus.ProposalType, commitSigsChan chan []byte, stopChan chan struct{}, stoppedChan chan struct{})
|
|
}
|
|
|
|
// New returns a block proposal service.
|
|
func New(readySignal chan consensus.ProposalType, commitSigsChan chan []byte, waitForConsensusReady func(readySignal chan consensus.ProposalType, commitSigsChan chan []byte, stopChan chan struct{}, stoppedChan chan struct{})) *Service {
|
|
return &Service{readySignal: readySignal, commitSigsChan: commitSigsChan, waitForConsensusReady: waitForConsensusReady}
|
|
}
|
|
|
|
// Start starts block proposal service.
|
|
func (s *Service) Start() error {
|
|
s.stopChan = make(chan struct{})
|
|
s.stoppedChan = make(chan struct{})
|
|
|
|
s.run(s.stopChan, s.stoppedChan)
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) run(stopChan chan struct{}, stoppedChan chan struct{}) {
|
|
s.waitForConsensusReady(s.readySignal, s.commitSigsChan, s.stopChan, s.stoppedChan)
|
|
}
|
|
|
|
// Stop stops block proposal service.
|
|
func (s *Service) Stop() error {
|
|
utils.Logger().Info().Msg("Stopping block proposal service.")
|
|
s.stopChan <- struct{}{}
|
|
<-s.stoppedChan
|
|
utils.Logger().Info().Msg("Role conversion stopped.")
|
|
return nil
|
|
}
|
|
|
|
// APIs for the services.
|
|
func (s *Service) APIs() []rpc.API {
|
|
return nil
|
|
}
|
|
|