Skip to content

Commit

Permalink
Prevent potential overflow in timestamp check
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Jan 18, 2019
1 parent 03a9f44 commit b3c7999
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions core/ledger/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,12 @@ func GetNextBlockSigner(height uint32, timestamp int64) ([]byte, []byte, WinnerT
return publicKey, chordID, GenesisSigner, nil
}

// calculate time difference
timeSinceLastBlock := timestamp - header.Timestamp

if timeSinceLastBlock <= 0 {
if timestamp <= header.Timestamp {
return nil, nil, 0, fmt.Errorf("timestamp %d is earlier than previous block timestamp %d", timestamp, header.Timestamp)
}

// calculate time difference
timeSinceLastBlock := timestamp - header.Timestamp
timeSlot := int64(config.ProposerChangeTime / time.Second)

if timeSinceLastBlock >= timeSlot {
Expand Down

0 comments on commit b3c7999

Please sign in to comment.