The core protocol of WoopChain
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.
woop/api/service/consensus/service.go

61 lines
1.8 KiB

6 years ago
package consensus
import (
"github.com/ethereum/go-ethereum/rpc"
msg_pb "github.com/harmony-one/harmony/api/proto/message"
6 years ago
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
)
// Service is the consensus service.
type Service struct {
blockChannel chan *types.Block // The channel to receive new blocks from Node
consensus *consensus.Consensus
stopChan chan struct{}
stoppedChan chan struct{}
startChan chan struct{}
messageChan chan *msg_pb.Message
6 years ago
}
// New returns consensus service.
func New(blockChannel chan *types.Block, consensus *consensus.Consensus, startChan chan struct{}) *Service {
return &Service{blockChannel: blockChannel, consensus: consensus, startChan: startChan}
6 years ago
}
6 years ago
// StartService starts consensus service.
6 years ago
func (s *Service) StartService() {
utils.GetLogInstance().Info("Starting consensus service.")
6 years ago
s.stopChan = make(chan struct{})
s.stoppedChan = make(chan struct{})
if s.consensus.ConsensusVersion == "v1" {
s.consensus.WaitForNewBlock(s.blockChannel, s.stopChan, s.stoppedChan, s.startChan)
} else {
s.consensus.Start(s.stopChan, s.stoppedChan)
}
s.consensus.WaitForNewRandomness()
6 years ago
}
6 years ago
// StopService stops consensus service.
6 years ago
func (s *Service) StopService() {
utils.GetLogInstance().Info("Stopping consensus service.")
s.stopChan <- struct{}{}
<-s.stoppedChan
utils.GetLogInstance().Info("Consensus service stopped.")
}
// NotifyService notify service
func (s *Service) NotifyService(params map[string]interface{}) {
return
}
// SetMessageChan sets up message channel to service.
func (s *Service) SetMessageChan(messageChan chan *msg_pb.Message) {
s.messageChan = messageChan
}
// APIs for the services.
func (s *Service) APIs() []rpc.API {
return nil
}