diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/lattice-data.go | 1 | ||||
-rw-r--r-- | core/lattice.go | 9 | ||||
-rw-r--r-- | core/lattice_test.go | 11 |
3 files changed, 21 insertions, 0 deletions
diff --git a/core/lattice-data.go b/core/lattice-data.go index e5d173d..7eec7f2 100644 --- a/core/lattice-data.go +++ b/core/lattice-data.go @@ -40,6 +40,7 @@ var ( ErrForkBlock = fmt.Errorf("fork block") ErrNotAckParent = fmt.Errorf("not ack parent") ErrDoubleAck = fmt.Errorf("double ack") + ErrAcksNotSorted = fmt.Errorf("acks not sorted") ErrInvalidBlockHeight = fmt.Errorf("invalid block height") ErrAlreadyInLattice = fmt.Errorf("block already in lattice") ErrIncorrectBlockTime = fmt.Errorf("block timestampe is incorrect") diff --git a/core/lattice.go b/core/lattice.go index 530fbab..27d38d8 100644 --- a/core/lattice.go +++ b/core/lattice.go @@ -102,6 +102,15 @@ func (s *Lattice) SanityCheck(b *types.Block) (err error) { err = ErrIncorrectHash return } + for i := range b.Acks { + if i == 0 { + continue + } + if !b.Acks[i-1].Less(b.Acks[i]) { + err = ErrAcksNotSorted + return + } + } // Check the signer. pubKey, err := crypto.SigToPub(b.Hash, b.Signature) if err != nil { diff --git a/core/lattice_test.go b/core/lattice_test.go index 2115d1a..bf65684 100644 --- a/core/lattice_test.go +++ b/core/lattice_test.go @@ -220,6 +220,17 @@ func (s *LatticeTestSuite) TestSanityCheck() { b.Signature, err = auth.prvKey.Sign(common.NewRandomHash()) req.NoError(err) req.Equal(lattice.SanityCheck(b), ErrIncorrectSignature) + // A block with un-sorted acks should not pass sanity check. + b.Acks = common.NewSortedHashes(common.Hashes{ + common.NewRandomHash(), + common.NewRandomHash(), + common.NewRandomHash(), + common.NewRandomHash(), + common.NewRandomHash(), + }) + b.Acks[0], b.Acks[1] = b.Acks[1], b.Acks[0] + req.NoError(auth.SignBlock(b)) + req.Equal(lattice.SanityCheck(b), ErrAcksNotSorted) // A block with incorrect hash should not pass sanity check. b.Hash = common.NewRandomHash() req.Equal(lattice.SanityCheck(b), ErrIncorrectHash) |