From 04eeac10e6c690e62ae57ef0e2bdf4618b8782d1 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Thu, 25 Oct 2018 16:59:30 +0800 Subject: core: lattice sync (#257) --- core/types/position.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'core/types/position.go') diff --git a/core/types/position.go b/core/types/position.go index f41be32..d821d16 100644 --- a/core/types/position.go +++ b/core/types/position.go @@ -57,6 +57,16 @@ func (pos *Position) Newer(other *Position) bool { (pos.Round == other.Round && pos.Height > other.Height) } +// Older checks if one block is older than another one on the same chain. +// If two blocks on different chain compared by this function, it would panic. +func (pos *Position) Older(other *Position) bool { + if pos.ChainID != other.ChainID { + panic(ErrComparePositionOnDifferentChains) + } + return pos.Round < other.Round || + (pos.Round == other.Round && pos.Height < other.Height) +} + // Clone a position instance. func (pos *Position) Clone() *Position { return &Position{ -- cgit v1.2.3