diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-08-08 19:32:20 +0800 |
---|---|---|
committer | Wei-Ning Huang <aitjcize@gmail.com> | 2018-08-08 19:32:20 +0800 |
commit | 295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785 (patch) | |
tree | bdb93aaa638ec890596a18490505a45204dc2cc7 /core/total-ordering.go | |
parent | a418ea95c0f5afb50cbb78aedecc68373353d06e (diff) | |
download | dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.gz dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.bz2 dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.lz dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.xz dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.tar.zst dexon-consensus-295c7b5efbc36f59e3ae8d10bc3abc3a5d17e785.zip |
core: Add Consensus to replace core.Blocklattice (#35)
* Make Sequencer return slice of blocks.
* Fix naming issue
The function 'getHeightVecto' would return ackingStatusVector.
* Fix comment error.
* Add methods to collect info when proposing blocks.
* Add test.App
* Add test.Gov
* Move this type to core.types to avoid cyclic import.
* Add core.Consensus
* Move getMedianTime, interpoTime to util
These functions are not depending on members of core.consensusTimestamp and
is required when testing core.Consensus.
* Make sure types.Block.Clone would copy critical fields.
* Remove core.blocklattice
* Define 'infinity' in core/total-ordering
This definition is defined in core/blocklattice originally.
* Fix a bug when processing the same block twice.
* Integrate simulation with core.Consensus
core.Consensus is a replacement of core.Blocklattice
* Fix the comment to use sigular form.
* Move lock mechanism to sub modules.
* phi should be 2*fmax+1
* Fixup: should aborting when the validator is added
* Fix for new block fields
* Fix the bug that the total ordering sequence is wrong.
Diffstat (limited to 'core/total-ordering.go')
-rw-r--r-- | core/total-ordering.go | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/core/total-ordering.go b/core/total-ordering.go index 63d3416..9f85813 100644 --- a/core/total-ordering.go +++ b/core/total-ordering.go @@ -19,12 +19,17 @@ package core import ( "fmt" + "math" "sort" "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) +const ( + infinity uint64 = math.MaxUint64 +) + // ErrNotValidDAG would be reported when block subbmitted to totalOrdering // didn't form a DAG. var ErrNotValidDAG = fmt.Errorf("not a valid dag") @@ -139,9 +144,9 @@ func (v blockVector) addBlock(b *types.Block) (err error) { return } -// getHeightVector would convert a blockVector to +// getAckingStatusVector would convert a blockVector to // ackingStatusVectorAckingStatus. -func (v blockVector) getHeightVector() ackingStatusVector { +func (v blockVector) getAckingStatusVector() ackingStatusVector { ret := ackingStatusVector{} for vID, vec := range v { if len(vec) == 0 { @@ -344,19 +349,17 @@ func (to *totalOrdering) isAckOnlyPrecedings(b *types.Block) bool { // output is a helper function to finish the delivery of // deliverable preceding set. -func (to *totalOrdering) output(precedings map[common.Hash]struct{}) common.Hashes { - ret := common.Hashes{} +func (to *totalOrdering) output(precedings map[common.Hash]struct{}) (ret []*types.Block) { for p := range precedings { - ret = append(ret, p) - // Remove the first element from corresponding blockVector. b := to.pendings[p] to.globalVector[b.ProposerID] = to.globalVector[b.ProposerID][1:] + ret = append(ret, b) // Remove block relations. to.clean(p) } - sort.Sort(ret) + sort.Sort(types.ByHash(ret)) // Find new candidates from tip of globalVector of each validator. // The complexity here is O(N^2logN). @@ -388,13 +391,14 @@ func (to *totalOrdering) output(precedings map[common.Hash]struct{}) common.Hash func (to *totalOrdering) generateDeliverSet() ( delivered map[common.Hash]struct{}, early bool) { - globalHeightVector := to.globalVector.getHeightVector() + globalAckingStatusVector := to.globalVector.getAckingStatusVector() ahvs := map[common.Hash]map[types.ValidatorID]uint64{} for candidate, v := range to.candidateAckingStatusVectors { - ahvs[candidate] = v.getAckingHeightVector(globalHeightVector, to.k) + ahvs[candidate] = v.getAckingHeightVector(globalAckingStatusVector, to.k) } - globalAns := globalHeightVector.getAckingNodeSet(globalHeightVector, to.k) + globalAns := globalAckingStatusVector.getAckingNodeSet( + globalAckingStatusVector, to.k) precedings := make(map[common.Hash]struct{}) CheckNextCandidateLoop: @@ -460,7 +464,7 @@ CheckNextCandidateLoop: checkANS := func() bool { for p := range precedings { validatorAns := to.candidateAckingStatusVectors[p].getAckingNodeSet( - globalHeightVector, to.k) + globalAckingStatusVector, to.k) if uint64(len(validatorAns)) < to.validatorCount-to.phi { return false } @@ -492,8 +496,7 @@ CheckNextCandidateLoop: // processBlock is the entry point of totalOrdering. func (to *totalOrdering) processBlock(b *types.Block) ( - delivered common.Hashes, early bool, err error) { - + delivered []*types.Block, early bool, err error) { // NOTE: I assume the block 'b' is already safe for total ordering. // That means, all its acking blocks are during/after // total ordering stage. |