MCPcopy Create free account
hub / github.com/DNAProject/DNA / actionLoop

Method actionLoop

consensus/vbft/service.go:1379–1631  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1377}
1378
1379func (self *Server) actionLoop() {
1380 self.quitWg.Add(1)
1381 defer self.quitWg.Done()
1382
1383 for {
1384 select {
1385 case action := <-self.bftActionC:
1386 switch action.Type {
1387 case MakeProposal:
1388 // this may triggered when block sealed or random backoff of 2nd proposer
1389 blkNum := self.GetCurrentBlockNo()
1390 if blkNum > action.BlockNum {
1391 continue
1392 }
1393
1394 var proposal *blockProposalMsg
1395 msgs := self.msgPool.GetProposalMsgs(blkNum)
1396 for _, m := range msgs {
1397 if p, ok := m.(*blockProposalMsg); ok && p.Block.getProposer() == self.Index {
1398 proposal = p
1399 break
1400 }
1401 }
1402 if proposal == nil {
1403 if err := self.makeProposal(blkNum, action.forEmpty); err != nil {
1404 log.Errorf("server %d failed to making proposal (%d): %s",
1405 self.Index, blkNum, err)
1406 }
1407 }
1408
1409 case EndorseBlock:
1410 // endorse the proposal
1411 blkNum := action.Proposal.GetBlockNum()
1412 if err := self.endorseBlock(action.Proposal, action.forEmpty); err != nil {
1413 log.Errorf("server %d failed to endorse block proposal (%d): %s",
1414 self.Index, blkNum, err)
1415 continue
1416 }
1417
1418 case CommitBlock:
1419 blkNum := action.Proposal.GetBlockNum()
1420 if err := self.commitBlock(action.Proposal, action.forEmpty); err != nil {
1421 log.Errorf("server %d failed to commit block proposal (%d): %s",
1422 self.Index, blkNum, err)
1423 continue
1424 }
1425 case SealBlock:
1426 if action.Proposal.GetBlockNum() < self.GetCurrentBlockNo() {
1427 continue
1428 }
1429 if err := self.sealProposal(action.Proposal, action.forEmpty); err != nil {
1430 log.Errorf("server %d failed to seal block (%d): %s",
1431 self.Index, action.Proposal.GetBlockNum(), err)
1432 }
1433 case FastForward:
1434 // 1. from current block num, check commit msgs in msg pool
1435 // 2. if commit consensused, seal the proposal
1436 for {

Callers 1

initializeMethod · 0.95

Calls 15

GetCurrentBlockNoMethod · 0.95
makeProposalMethod · 0.95
endorseBlockMethod · 0.95
commitBlockMethod · 0.95
sealProposalMethod · 0.95
startNewRoundMethod · 0.95
catchConsensusMethod · 0.95
fetchProposalMethod · 0.95
sealBlockMethod · 0.95
broadcastMethod · 0.95
isEndorserMethod · 0.95

Tested by

no test coverage detected