diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-09-20 14:37:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-20 14:37:53 +0800 |
commit | 2f1e71d9d298d1f6ade8d17a1db7a657b0223872 (patch) | |
tree | 7bcd6bedb41dda8daa2d8b102d961323bc7f45a6 /core/types/block.go | |
parent | 682de6408544b8d4073333e6659340b304f4399e (diff) | |
download | tangerine-consensus-2f1e71d9d298d1f6ade8d17a1db7a657b0223872.tar tangerine-consensus-2f1e71d9d298d1f6ade8d17a1db7a657b0223872.tar.gz tangerine-consensus-2f1e71d9d298d1f6ade8d17a1db7a657b0223872.tar.bz2 tangerine-consensus-2f1e71d9d298d1f6ade8d17a1db7a657b0223872.tar.lz tangerine-consensus-2f1e71d9d298d1f6ade8d17a1db7a657b0223872.tar.xz tangerine-consensus-2f1e71d9d298d1f6ade8d17a1db7a657b0223872.tar.zst tangerine-consensus-2f1e71d9d298d1f6ade8d17a1db7a657b0223872.zip |
core: add blockpool (#121)
core.blockPool is used to cache blocks arrived
out-of-order. Our consensus should retry
those blocks after their acking blocks added
to lattice.
Diffstat (limited to 'core/types/block.go')
-rw-r--r-- | core/types/block.go | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/core/types/block.go b/core/types/block.go index 949876f..ddd0abd 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -125,14 +125,29 @@ func (b ByHash) Swap(i int, j int) { // ByHeight is the helper type for sorting slice of blocks by height. type ByHeight []*Block -func (b ByHeight) Len() int { - return len(b) +// Len implements Len method in sort.Sort interface. +func (bs ByHeight) Len() int { + return len(bs) } -func (b ByHeight) Less(i int, j int) bool { - return b[i].Position.Height < b[j].Position.Height +// 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 (b ByHeight) Swap(i int, j int) { - b[i], b[j] = b[j], b[i] +// Swap implements Swap method in sort.Sort interface. +func (bs ByHeight) 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{}) { + *bs = append(*bs, x.(*Block)) +} + +// Pop implements Pop method in heap interface. +func (bs *ByHeight) Pop() (ret interface{}) { + n := len(*bs) + *bs, ret = (*bs)[0:n-1], (*bs)[n-1] + return } |