(bkAccount *account.Account, txpool, p2p *actor.PID)
| 61 | } |
| 62 | |
| 63 | func NewDbftService(bkAccount *account.Account, txpool, p2p *actor.PID) (*DbftService, error) { |
| 64 | service := &DbftService{ |
| 65 | Account: bkAccount, |
| 66 | timer: time.NewTimer(time.Second * 15), |
| 67 | started: false, |
| 68 | ledger: ledger.DefLedger, |
| 69 | incrValidator: increment.NewIncrementValidator(20), |
| 70 | poolActor: &actorTypes.TxPoolActor{Pool: txpool}, |
| 71 | p2p: &actorTypes.P2PActor{P2P: p2p}, |
| 72 | } |
| 73 | |
| 74 | if !service.timer.Stop() { |
| 75 | <-service.timer.C |
| 76 | } |
| 77 | |
| 78 | go func() { |
| 79 | for { |
| 80 | select { |
| 81 | case <-service.timer.C: |
| 82 | log.Debug("******Get a timeout notice") |
| 83 | service.pid.Tell(&actorTypes.TimeOut{}) |
| 84 | } |
| 85 | } |
| 86 | }() |
| 87 | |
| 88 | props := actor.FromProducer(func() actor.Actor { |
| 89 | return service |
| 90 | }) |
| 91 | |
| 92 | pid, err := actor.SpawnNamed(props, "consensus_dbft") |
| 93 | service.pid = pid |
| 94 | |
| 95 | service.sub = events.NewActorSubscriber(pid) |
| 96 | return service, err |
| 97 | } |
| 98 | |
| 99 | func (this *DbftService) Receive(context actor.Context) { |
| 100 | if _, ok := context.Message().(*actorTypes.StartConsensus); this.started == false && ok == false { |
no test coverage detected