forked from DNAProject/DNA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dbft_service.go
717 lines (603 loc) · 20.1 KB
/
dbft_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*
* Copyright (C) 2018 The DNA Authors
* This file is part of The DNA library.
*
* The DNA is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The DNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with The DNA. If not, see <http://www.gnu.org/licenses/>.
*/
package dbft
import (
"bytes"
"fmt"
"reflect"
"time"
"github.com/dnaproject2/DNA/account"
"github.com/dnaproject2/DNA/common"
"github.com/dnaproject2/DNA/common/config"
"github.com/dnaproject2/DNA/common/log"
actorTypes "github.com/dnaproject2/DNA/consensus/actor"
"github.com/dnaproject2/DNA/core/genesis"
"github.com/dnaproject2/DNA/core/ledger"
"github.com/dnaproject2/DNA/core/signature"
"github.com/dnaproject2/DNA/core/types"
"github.com/dnaproject2/DNA/core/vote"
"github.com/dnaproject2/DNA/events"
"github.com/dnaproject2/DNA/events/message"
p2pmsg "github.com/dnaproject2/DNA/p2pserver/message/types"
"github.com/dnaproject2/DNA/validator/increment"
"github.com/ontio/ontology-eventbus/actor"
)
type DbftService struct {
context ConsensusContext
Account *account.Account
timer *time.Timer
timerHeight uint32
timeView byte
blockReceivedTime time.Time
started bool
ledger *ledger.Ledger
incrValidator *increment.IncrementValidator
poolActor *actorTypes.TxPoolActor
p2p *actorTypes.P2PActor
pid *actor.PID
sub *events.ActorSubscriber
}
func NewDbftService(bkAccount *account.Account, txpool, p2p *actor.PID) (*DbftService, error) {
service := &DbftService{
Account: bkAccount,
timer: time.NewTimer(time.Second * 15),
started: false,
ledger: ledger.DefLedger,
incrValidator: increment.NewIncrementValidator(20),
poolActor: &actorTypes.TxPoolActor{Pool: txpool},
p2p: &actorTypes.P2PActor{P2P: p2p},
}
if !service.timer.Stop() {
<-service.timer.C
}
go func() {
for {
select {
case <-service.timer.C:
log.Debug("******Get a timeout notice")
service.pid.Tell(&actorTypes.TimeOut{})
}
}
}()
props := actor.FromProducer(func() actor.Actor {
return service
})
pid, err := actor.SpawnNamed(props, "consensus_dbft")
service.pid = pid
service.sub = events.NewActorSubscriber(pid)
return service, err
}
func (this *DbftService) Receive(context actor.Context) {
if _, ok := context.Message().(*actorTypes.StartConsensus); this.started == false && ok == false {
return
}
switch msg := context.Message().(type) {
case *actor.Restarting:
log.Warn("dbft actor restarting")
case *actor.Stopping:
log.Warn("dbft actor stopping")
case *actor.Stopped:
log.Warn("dbft actor stopped")
case *actor.Started:
log.Warn("dbft actor started")
case *actor.Restart:
log.Warn("dbft actor restart")
case *actorTypes.StartConsensus:
this.start()
case *actorTypes.StopConsensus:
this.incrValidator.Clean()
this.halt()
case *actorTypes.TimeOut:
log.Info("dbft receive timeout")
this.Timeout()
case *message.SaveBlockCompleteMsg:
log.Infof("dbft actor receives block complete event. block height=%d, numtx=%d",
msg.Block.Header.Height, len(msg.Block.Transactions))
this.incrValidator.AddBlock(msg.Block)
this.handleBlockPersistCompleted(msg.Block)
case *p2pmsg.ConsensusPayload:
this.NewConsensusPayload(msg)
default:
log.Info("dbft actor: Unknown msg ", msg, "type", reflect.TypeOf(msg))
}
}
func (this *DbftService) GetPID() *actor.PID {
return this.pid
}
func (this *DbftService) Start() error {
this.pid.Tell(&actorTypes.StartConsensus{})
return nil
}
func (this *DbftService) Halt() error {
this.pid.Tell(&actorTypes.StopConsensus{})
return nil
}
func (self *DbftService) handleBlockPersistCompleted(block *types.Block) {
log.Infof("persist block: %x", block.Hash())
self.p2p.Broadcast(block.Hash())
self.InitializeConsensus(0)
}
func (ds *DbftService) BlockPersistCompleted(v interface{}) {
if block, ok := v.(*types.Block); ok {
log.Infof("persist block: %x", block.Hash())
ds.p2p.Broadcast(block.Hash())
}
}
func (ds *DbftService) CheckExpectedView(viewNumber byte) {
log.Debug()
if ds.context.State.HasFlag(BlockGenerated) {
return
}
if ds.context.ViewNumber == viewNumber {
return
}
//check the count for same view number
count := 0
for _, expectedViewNumber := range ds.context.ExpectedView {
if expectedViewNumber == viewNumber {
count++
}
}
M := ds.context.M()
if count >= M {
log.Debug("[CheckExpectedView] Begin InitializeConsensus.")
ds.InitializeConsensus(viewNumber)
}
}
func (ds *DbftService) CheckPolicy(transaction *types.Transaction) error {
//TODO: CheckPolicy
return nil
}
func (ds *DbftService) CheckSignatures() error {
log.Debug()
//check if get enough signatures
if ds.context.GetSignaturesCount() >= ds.context.M() {
//build block
block := ds.context.MakeHeader()
sigs := make([]SignaturesData, ds.context.M())
for i, j := 0, 0; i < len(ds.context.Bookkeepers) && j < ds.context.M(); i++ {
if ds.context.Signatures[i] != nil {
sig := ds.context.Signatures[i]
sigs[j].Index = uint16(i)
sigs[j].Signature = sig
block.Header.SigData = append(block.Header.SigData, sig)
j++
}
}
block.Header.Bookkeepers = ds.context.Bookkeepers
//fill transactions
block.Transactions = ds.context.Transactions
hash := block.Hash()
isExist, err := ds.ledger.IsContainBlock(hash)
if err != nil {
log.Errorf("DefLedger.IsContainBlock Hash:%x error:%s", hash, err)
return err
}
if !isExist {
// save block
result, err := ds.ledger.ExecuteBlock(block)
if err != nil {
return fmt.Errorf("CheckSignatures DefLedgerPid.RequestFuture Height:%d error:%s", block.Header.Height, err)
}
err = ds.ledger.SubmitBlock(block, result)
if err != nil {
return fmt.Errorf("CheckSignatures DefLedgerPid.RequestFuture Height:%d error:%s", block.Header.Height, err)
}
ds.context.State |= BlockGenerated
payload := ds.context.MakeBlockSignatures(sigs)
ds.SignAndRelay(payload)
}
}
return nil
}
func (ds *DbftService) ChangeViewReceived(payload *p2pmsg.ConsensusPayload, message *ChangeView) {
log.Debug()
log.Info(fmt.Sprintf("Change View Received: height=%d View=%d index=%d nv=%d", payload.Height, message.ViewNumber(), payload.BookkeeperIndex, message.NewViewNumber))
if message.NewViewNumber <= ds.context.ExpectedView[payload.BookkeeperIndex] {
return
}
ds.context.ExpectedView[payload.BookkeeperIndex] = message.NewViewNumber
ds.CheckExpectedView(message.NewViewNumber)
}
func (ds *DbftService) halt() error {
log.Info("DBFT Stop")
if ds.timer != nil {
ds.timer.Stop()
}
if ds.started {
ds.sub.Unsubscribe(message.TOPIC_SAVE_BLOCK_COMPLETE)
}
return nil
}
func (ds *DbftService) InitializeConsensus(viewNum byte) error {
log.Debug("[InitializeConsensus] Start InitializeConsensus.")
log.Debug("[InitializeConsensus] viewNum: ", viewNum)
if viewNum == 0 {
ds.context.Reset(ds.Account)
} else {
if ds.context.State.HasFlag(BlockGenerated) {
return nil
}
ds.context.ChangeView(viewNum)
}
if ds.context.BookkeeperIndex < 0 {
log.Info("You aren't bookkeeper")
return nil
}
if ds.context.BookkeeperIndex == int(ds.context.PrimaryIndex) {
//primary peer
ds.context.State |= Primary
ds.timerHeight = ds.context.Height
ds.timeView = viewNum
span := time.Now().Sub(ds.blockReceivedTime)
if span > genesis.GenBlockTime {
//TODO: double check the is the stop necessary
ds.timer.Stop()
ds.timer.Reset(0)
//go ds.Timeout()
} else {
ds.timer.Stop()
ds.timer.Reset(genesis.GenBlockTime - span)
}
} else {
//backup peer
ds.context.State = Backup
ds.timerHeight = ds.context.Height
ds.timeView = viewNum
ds.timer.Stop()
ds.timer.Reset(genesis.GenBlockTime << (viewNum + 1))
}
return nil
}
func (ds *DbftService) LocalNodeNewInventory(v interface{}) {
log.Debug()
if inventory, ok := v.(common.Inventory); ok {
if inventory.Type() == common.CONSENSUS {
payload, ret := inventory.(*p2pmsg.ConsensusPayload)
if ret == true {
ds.NewConsensusPayload(payload)
}
}
}
}
func (ds *DbftService) NewConsensusPayload(payload *p2pmsg.ConsensusPayload) {
//if payload from current peer, ignore it
if int(payload.BookkeeperIndex) == ds.context.BookkeeperIndex {
return
}
//if payload is not same height with current contex, ignore it
if payload.Version != ContextVersion || payload.PrevHash != ds.context.PrevHash || payload.Height != ds.context.Height {
log.Debug("unmatched height")
return
}
if ds.context.State.HasFlag(BlockGenerated) {
log.Debug("has flag 'BlockGenerated'")
return
}
if int(payload.BookkeeperIndex) >= len(ds.context.Bookkeepers) {
log.Debug("bookkeeper index out of range")
return
}
message, err := DeserializeMessage(payload.Data)
if err != nil {
log.Error(fmt.Sprintf("DeserializeMessage failed: %s\n", err))
return
}
if message.ViewNumber() != ds.context.ViewNumber && message.Type() != ChangeViewMsg {
return
}
err = payload.Verify()
if err != nil {
log.Warn(err.Error())
return
}
switch message.Type() {
case ChangeViewMsg:
if cv, ok := message.(*ChangeView); ok {
ds.ChangeViewReceived(payload, cv)
}
break
case PrepareRequestMsg:
if pr, ok := message.(*PrepareRequest); ok {
ds.PrepareRequestReceived(payload, pr)
}
break
case PrepareResponseMsg:
if pres, ok := message.(*PrepareResponse); ok {
ds.PrepareResponseReceived(payload, pres)
}
break
case BlockSignaturesMsg:
if blockSigs, ok := message.(*BlockSignatures); ok {
ds.BlockSignaturesReceived(payload, blockSigs)
}
break
default:
log.Warn("unknown consensus message type")
}
}
func (ds *DbftService) PrepareRequestReceived(payload *p2pmsg.ConsensusPayload, message *PrepareRequest) {
log.Info(fmt.Sprintf("Prepare Request Received: height=%d View=%d index=%d tx=%d", payload.Height, message.ViewNumber(), payload.BookkeeperIndex, len(message.Transactions)))
if !ds.context.State.HasFlag(Backup) || ds.context.State.HasFlag(RequestReceived) {
return
}
if uint32(payload.BookkeeperIndex) != ds.context.PrimaryIndex {
return
}
header, err := ds.ledger.GetHeaderByHash(ds.context.PrevHash)
if err != nil {
log.Errorf("PrepareRequestReceived GetHeader failed with ds.context.PrevHash:%x", ds.context.PrevHash)
return
}
if header == nil {
log.Errorf("PrepareRequestReceived cannot GetHeaderByHash by PrevHash:%x", ds.context.PrevHash)
return
}
//TODO Add Error Catch
prevBlockTimestamp := header.Timestamp
if payload.Timestamp <= prevBlockTimestamp || payload.Timestamp > uint32(time.Now().Add(time.Minute*10).Unix()) {
log.Info(fmt.Sprintf("Prepare Reques tReceived: Timestamp incorrect: %d", payload.Timestamp))
return
}
backupContext := ds.context
ds.context.State |= RequestReceived
ds.context.Timestamp = payload.Timestamp
ds.context.Nonce = message.Nonce
ds.context.NextBookkeeper = message.NextBookkeeper
ds.context.Transactions = message.Transactions
ds.context.header = nil
blockHash := ds.context.MakeHeader().Hash()
err = signature.Verify(ds.context.Bookkeepers[payload.BookkeeperIndex], blockHash[:], message.Signature)
if err != nil {
log.Warn("PrepareRequestReceived VerifySignature failed.", err)
ds.context = backupContext
ds.RequestChangeView()
return
}
ds.context.Signatures = make([][]byte, len(ds.context.Bookkeepers))
ds.context.Signatures[payload.BookkeeperIndex] = message.Signature
if len(ds.context.Transactions) > 0 {
height := ds.context.Height - 1
start, end := ds.incrValidator.BlockRange()
validHeight := height
if height+1 == end {
validHeight = start
} else {
ds.incrValidator.Clean()
log.Infof("incr validator block height %v != ledger block height %v", int(end)-1, height)
}
if err := ds.poolActor.VerifyBlock(ds.context.Transactions, validHeight); err != nil {
log.Error("PrepareRequestReceived new transaction verification failed, will not sent Prepare Response", err)
ds.context = backupContext
ds.RequestChangeView()
return
}
for _, tx := range ds.context.Transactions {
if err := ds.incrValidator.Verify(tx, validHeight); err != nil {
log.Error("PrepareRequestReceived new transaction increment verification failed, will not sent Prepare Response", err)
ds.context = backupContext
ds.RequestChangeView()
return
}
}
}
ds.context.NextBookkeepers, err = vote.GetValidators(ds.context.Transactions)
if err != nil {
ds.context = backupContext
log.Error("[PrepareRequestReceived] GetValidators failed")
return
}
ds.context.NextBookkeeper, err = types.AddressFromBookkeepers(ds.context.NextBookkeepers)
if err != nil {
ds.context = backupContext
log.Error("[PrepareRequestReceived] GetBookkeeperAddress failed")
return
}
if ds.context.NextBookkeeper != message.NextBookkeeper {
ds.context = backupContext
ds.RequestChangeView()
log.Error("[PrepareRequestReceived] Unmatched NextBookkeeper")
return
}
log.Info("send prepare response")
ds.context.State |= SignatureSent
if ds.context.BookkeeperIndex == -1 {
log.Error("[DbftService] GetAccount failed")
return
}
sig, err := signature.Sign(ds.Account, blockHash[:])
if err != nil {
log.Error("[DbftService] signing failed")
return
}
ds.context.Signatures[ds.context.BookkeeperIndex] = sig
payload = ds.context.MakePrepareResponse(ds.context.Signatures[ds.context.BookkeeperIndex])
ds.SignAndRelay(payload)
ds.blockReceivedTime = time.Now()
log.Info("Prepare Request finished")
}
func (ds *DbftService) PrepareResponseReceived(payload *p2pmsg.ConsensusPayload, message *PrepareResponse) {
log.Info(fmt.Sprintf("Prepare Response Received: height=%d View=%d index=%d", payload.Height, message.ViewNumber(), payload.BookkeeperIndex))
if ds.context.State.HasFlag(BlockGenerated) {
return
}
//if the signature already exist, needn't handle again
if ds.context.Signatures[payload.BookkeeperIndex] != nil {
return
}
header := ds.context.MakeHeader()
if header == nil {
return
}
blockHash := header.Hash()
err := signature.Verify(ds.context.Bookkeepers[payload.BookkeeperIndex], blockHash[:], message.Signature)
if err != nil {
return
}
ds.context.Signatures[payload.BookkeeperIndex] = message.Signature
err = ds.CheckSignatures()
if err != nil {
log.Error("CheckSignatures failed", err)
return
}
log.Info("Prepare Response finished")
}
func (ds *DbftService) BlockSignaturesReceived(payload *p2pmsg.ConsensusPayload, message *BlockSignatures) {
log.Info(fmt.Sprintf("BlockSignatures Received: height=%d View=%d index=%d", payload.Height, message.ViewNumber(), payload.BookkeeperIndex))
if ds.context.State.HasFlag(BlockGenerated) {
return
}
//if the signature already exist, needn't handle again
if ds.context.Signatures[payload.BookkeeperIndex] != nil {
return
}
header := ds.context.MakeHeader()
if header == nil {
return
}
blockHash := header.Hash()
for i := 0; i < len(message.Signatures); i++ {
sigdata := message.Signatures[i]
if ds.context.Signatures[sigdata.Index] != nil {
continue
}
err := signature.Verify(ds.context.Bookkeepers[sigdata.Index], blockHash[:], sigdata.Signature)
if err != nil {
continue
}
ds.context.Signatures[sigdata.Index] = sigdata.Signature
if ds.context.GetSignaturesCount() >= ds.context.M() {
log.Info("BlockSignatures got enough signatures")
break
}
}
err := ds.CheckSignatures()
if err != nil {
log.Error("CheckSignatures failed")
return
}
log.Info("BlockSignatures finished")
}
func (ds *DbftService) RefreshPolicy() {
}
func (ds *DbftService) RequestChangeView() {
if ds.context.State.HasFlag(BlockGenerated) {
return
}
// FIXME if there is no save block notifcation, when the timeout call this function it will crash
if ds.context.ViewNumber > ds.context.ExpectedView[ds.context.BookkeeperIndex] {
ds.context.ExpectedView[ds.context.BookkeeperIndex] = ds.context.ViewNumber + 1
} else {
ds.context.ExpectedView[ds.context.BookkeeperIndex] += 1
}
log.Info(fmt.Sprintf("Request change view: height=%d View=%d nv=%d state=%s", ds.context.Height,
ds.context.ViewNumber, ds.context.ExpectedView[ds.context.BookkeeperIndex], ds.context.GetStateDetail()))
ds.timer.Stop()
ds.timer.Reset(genesis.GenBlockTime << (ds.context.ExpectedView[ds.context.BookkeeperIndex] + 1))
ds.SignAndRelay(ds.context.MakeChangeView())
ds.CheckExpectedView(ds.context.ExpectedView[ds.context.BookkeeperIndex])
}
func (ds *DbftService) SignAndRelay(payload *p2pmsg.ConsensusPayload) {
buf := new(bytes.Buffer)
payload.SerializeUnsigned(buf)
payload.Signature, _ = signature.Sign(ds.Account, buf.Bytes())
ds.p2p.Broadcast(payload)
}
func (ds *DbftService) start() {
log.Debug()
ds.started = true
if config.DefConfig.Genesis.DBFT.GenBlockTime > config.MIN_GEN_BLOCK_TIME {
genesis.GenBlockTime = time.Duration(config.DefConfig.Genesis.DBFT.GenBlockTime) * time.Second
} else {
log.Warn("The Generate block time should be longer than 2 seconds, so set it to be default 6 seconds.")
}
ds.sub.Subscribe(message.TOPIC_SAVE_BLOCK_COMPLETE)
ds.InitializeConsensus(0)
}
func (ds *DbftService) Timeout() {
if ds.timerHeight != ds.context.Height || ds.timeView != ds.context.ViewNumber {
return
}
log.Info("Timeout: height: ", ds.timerHeight, " View: ", ds.timeView, " State: ", ds.context.GetStateDetail())
if ds.context.State.HasFlag(Primary) && !ds.context.State.HasFlag(RequestSent) {
//primary node send the prepare request
log.Info("Send prepare request: height: ", ds.timerHeight, " View: ", ds.timeView, " State: ", ds.context.GetStateDetail())
ds.context.State |= RequestSent
if !ds.context.State.HasFlag(SignatureSent) {
now := uint32(time.Now().Unix())
header, err := ds.ledger.GetHeaderByHash(ds.context.PrevHash)
if err != nil {
log.Errorf("[Timeout] GetHeader PrevHash:%x error:%s", ds.context.PrevHash, err)
return
}
if header == nil {
log.Errorf("[Timeout] cannot GetHeaderByHash by PrevHash:%x", ds.context.PrevHash)
return
}
//set context Timestamp
blockTime := header.Timestamp + 1
if blockTime > now {
ds.context.Timestamp = blockTime
} else {
ds.context.Timestamp = now
}
ds.context.Nonce = common.GetNonce()
height := ds.context.Height - 1
validHeight := height
start, end := ds.incrValidator.BlockRange()
if height+1 == end {
validHeight = start
} else {
ds.incrValidator.Clean()
log.Infof("incr validator block height %v != ledger block height %v", int(end)-1, height)
}
log.Infof("current block height %v, increment validator block cache range: [%d, %d)", height, start, end)
txs := ds.poolActor.GetTxnPool(true, validHeight)
transactions := make([]*types.Transaction, 0, len(txs))
for _, txEntry := range txs {
// TODO optimize to use height in txentry
if err := ds.incrValidator.Verify(txEntry.Tx, validHeight); err == nil {
transactions = append(transactions, txEntry.Tx)
}
}
ds.context.Transactions = transactions
ds.context.NextBookkeepers, err = vote.GetValidators(ds.context.Transactions)
if err != nil {
log.Error("[Timeout] GetValidators failed", err.Error())
return
}
ds.context.NextBookkeeper, err = types.AddressFromBookkeepers(ds.context.NextBookkeepers)
if err != nil {
log.Error("[Timeout] GetBookkeeperAddress failed")
return
}
ds.context.header = nil
//build block and sign
block := ds.context.MakeHeader()
blockHash := block.Hash()
ds.context.Signatures[ds.context.BookkeeperIndex], _ = signature.Sign(ds.Account, blockHash[:])
}
payload := ds.context.MakePrepareRequest()
ds.SignAndRelay(payload)
ds.blockReceivedTime = time.Now()
ds.timer.Stop()
ds.timer.Reset(genesis.GenBlockTime << (ds.timeView + 1))
} else if (ds.context.State.HasFlag(Primary) && ds.context.State.HasFlag(RequestSent)) || ds.context.State.HasFlag(Backup) {
ds.RequestChangeView()
}
}