check if has reached consensus on block-commit return @ consensused proposer @ for empty commit @ consensused Note: Attentions on lock contention. Only shared-lock for this function, because this function will also acquires shared-lock on peer-pool.
(blkNum uint32, C uint32, N uint32)
| 500 | // Only shared-lock for this function, because this function will also acquires shared-lock on peer-pool. |
| 501 | // |
| 502 | func (pool *BlockPool) commitDone(blkNum uint32, C uint32, N uint32) (uint32, bool, bool) { |
| 503 | pool.lock.RLock() |
| 504 | defer pool.lock.RUnlock() |
| 505 | candidate := pool.candidateBlocks[blkNum] |
| 506 | if candidate == nil { |
| 507 | return math.MaxUint32, false, false |
| 508 | } |
| 509 | |
| 510 | // check consensus with commit msgs |
| 511 | proposer, forEmpty := getCommitConsensus(candidate.CommitMsgs, int(C), int(N)) |
| 512 | |
| 513 | // enforce signature quorum if checking commit-consensus base on signature count |
| 514 | // if C <= (N-1)/3, N-1-C >= 2*C |
| 515 | C = N - 1 - C |
| 516 | if proposer == math.MaxUint32 { |
| 517 | // check consensus with endorse sigs |
| 518 | var emptyCnt uint32 |
| 519 | endorseCnt := make(map[uint32]uint32) // proposer -> endorsed-cnt |
| 520 | for endorser, eSigs := range candidate.EndorseSigs { |
| 521 | // check if from endorser |
| 522 | if !pool.server.isEndorser(blkNum, endorser) { |
| 523 | for _, sig := range eSigs { |
| 524 | if sig.ForEmpty { |
| 525 | emptyCnt++ |
| 526 | } |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | for _, sig := range eSigs { |
| 531 | if sig.ForEmpty { |
| 532 | emptyCnt++ |
| 533 | } else { |
| 534 | endorseCnt[sig.EndorsedProposer] += 1 |
| 535 | if endorseCnt[sig.EndorsedProposer] > C { |
| 536 | proposer = sig.EndorsedProposer |
| 537 | if !forEmpty { |
| 538 | forEmpty = emptyCnt > C |
| 539 | } |
| 540 | break |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if proposer != math.MaxUint32 { |
| 546 | break |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | if proposer != math.MaxUint32 { |
| 552 | return proposer, forEmpty, true |
| 553 | } |
| 554 | |
| 555 | return math.MaxUint32, false, false |
| 556 | } |
| 557 | |
| 558 | // |
| 559 | // @ set BlockPool as committed for given BlockNum |
no test coverage detected