Skip to content

Commit

Permalink
blockchain: error GetLastTimestamps() empty result if height > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
xiphon committed Feb 28, 2020
1 parent 8ba3313 commit 510f508
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions blockchain/blockchain.go
Expand Up @@ -192,9 +192,14 @@ func (b *Blockchain) addBlock(target common.TargetBase, block safebox.BlockBase)
return nil, nil, ErrParentNotFound
}

lastTimestamps := b.safebox.GetLastTimestamps(1)
if len(lastTimestamps) != 0 && block.GetTimestamp() < lastTimestamps[0] {
return nil, nil, errors.New("Invalid timestamp")
if block.GetIndex() > 0 {
lastTimestamps := b.safebox.GetLastTimestamps(1)
if len(lastTimestamps) == 0 {
return nil, nil, errors.New("Failed to get recent blocks timestamps")
}
if block.GetTimestamp() < lastTimestamps[0] {
return nil, nil, errors.New("Invalid timestamp")
}
}
if err := b.safebox.GetFork().CheckBlock(target, block); err != nil {
return nil, nil, errors.New("Invalid block: " + err.Error())
Expand Down

0 comments on commit 510f508

Please sign in to comment.