diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-10-18 15:00:27 +0800 |
---|---|---|
committer | haoping-ku <37325897+haoping-ku@users.noreply.github.com> | 2018-10-18 15:00:27 +0800 |
commit | 43299221c586bfb55e225799aedc6d133ba97c3f (patch) | |
tree | e607424430237698c4eb8f33e186643fc5849ca6 /core/types | |
parent | 8303e9d054957195717f41804a456e2720b0c4bb (diff) | |
download | dexon-consensus-43299221c586bfb55e225799aedc6d133ba97c3f.tar dexon-consensus-43299221c586bfb55e225799aedc6d133ba97c3f.tar.gz dexon-consensus-43299221c586bfb55e225799aedc6d133ba97c3f.tar.bz2 dexon-consensus-43299221c586bfb55e225799aedc6d133ba97c3f.tar.lz dexon-consensus-43299221c586bfb55e225799aedc6d133ba97c3f.tar.xz dexon-consensus-43299221c586bfb55e225799aedc6d133ba97c3f.tar.zst dexon-consensus-43299221c586bfb55e225799aedc6d133ba97c3f.zip |
core: total ordering flush (#212)
* Implement flush
* Panic for all errors from total-ordering
* Fix test failure
All DAGs generated by blocks-generator would trigger round switching.
* Add NewBlocksGeneratorConfig
* Add test caes for numChains changes
* Resize internal structures
* Perform total ordering based on current numChains
* Fix not a valid DAG checking
* Comparing blocks by height is not correct
* Fix blocks from future round are delivered first by revealer
* Make sure only picking one candidate in one chain.
Blocks on the same chain in different rounds would not
have acking relation.
* Fix stuffs
* Fix the issue that two candidates from the same chain are picked.
* Rework candidateChainMapping
* Add test case for phi, k changed
* Refine testing code for round change
* Add breakpoints in global vector
* Remove not a valid dag checking.
* Adding comments
* Add check to forward acking
* Fix vet failure
* Prepareing height record with breakpoint
* Fixup: add check to make sure delivered round IDs are increasing.
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 16 | ||||
-rw-r--r-- | core/types/block_test.go | 28 |
2 files changed, 24 insertions, 20 deletions
diff --git a/core/types/block.go b/core/types/block.go index e384f95..63bcec4 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -146,31 +146,31 @@ func (b ByHash) Swap(i int, j int) { b[i], b[j] = b[j], b[i] } -// ByHeight is the helper type for sorting slice of blocks by height. -type ByHeight []*Block +// ByPosition is the helper type for sorting slice of blocks by position. +type ByPosition []*Block // Len implements Len method in sort.Sort interface. -func (bs ByHeight) Len() int { +func (bs ByPosition) Len() int { return len(bs) } // Less implements Less method in sort.Sort interface. -func (bs ByHeight) Less(i int, j int) bool { - return bs[i].Position.Height < bs[j].Position.Height +func (bs ByPosition) Less(i int, j int) bool { + return bs[j].Position.Newer(&bs[i].Position) } // Swap implements Swap method in sort.Sort interface. -func (bs ByHeight) Swap(i int, j int) { +func (bs ByPosition) Swap(i int, j int) { bs[i], bs[j] = bs[j], bs[i] } // Push implements Push method in heap interface. -func (bs *ByHeight) Push(x interface{}) { +func (bs *ByPosition) Push(x interface{}) { *bs = append(*bs, x.(*Block)) } // Pop implements Pop method in heap interface. -func (bs *ByHeight) Pop() (ret interface{}) { +func (bs *ByPosition) Pop() (ret interface{}) { n := len(*bs) *bs, ret = (*bs)[0:n-1], (*bs)[n-1] return diff --git a/core/types/block_test.go b/core/types/block_test.go index b03b785..49eaa86 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -104,18 +104,22 @@ func (s *BlockTestSuite) TestSortByHash() { s.Equal(blocks[3].Hash, b3.Hash) } -func (s *BlockTestSuite) TestSortByHeight() { - b0 := &Block{Position: Position{Height: 0}} - b1 := &Block{Position: Position{Height: 1}} - b2 := &Block{Position: Position{Height: 2}} - b3 := &Block{Position: Position{Height: 3}} - - blocks := []*Block{b3, b2, b1, b0} - sort.Sort(ByHeight(blocks)) - s.Equal(blocks[0].Hash, b0.Hash) - s.Equal(blocks[1].Hash, b1.Hash) - s.Equal(blocks[2].Hash, b2.Hash) - s.Equal(blocks[3].Hash, b3.Hash) +func (s *BlockTestSuite) TestSortByPosition() { + b00 := &Block{Position: Position{Height: 0}} + b01 := &Block{Position: Position{Height: 1}} + b02 := &Block{Position: Position{Height: 2}} + b10 := &Block{Position: Position{Round: 1, Height: 0}} + b11 := &Block{Position: Position{Round: 1, Height: 1}} + b12 := &Block{Position: Position{Round: 1, Height: 2}} + + blocks := []*Block{b12, b11, b10, b02, b01, b00} + sort.Sort(ByPosition(blocks)) + s.Equal(blocks[0].Hash, b00.Hash) + s.Equal(blocks[1].Hash, b01.Hash) + s.Equal(blocks[2].Hash, b02.Hash) + s.Equal(blocks[3].Hash, b10.Hash) + s.Equal(blocks[4].Hash, b11.Hash) + s.Equal(blocks[5].Hash, b12.Hash) } func (s *BlockTestSuite) TestGenesisBlock() { |