Make ElectionPostChallengeCount math overflow safe

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2019-12-09 17:41:38 +01:00
parent 9e363f9266
commit 887a34135b
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA

View File

@ -214,8 +214,11 @@ func IsTicketWinner(partialTicket []byte, ssizeI uint64, snum uint64, totpow Big
}
func ElectionPostChallengeCount(sectors uint64) uint64 {
if sectors == 0 {
return 0
}
// ceil(sectors / build.SectorChallengeRatioDiv)
return (sectors + build.SectorChallengeRatioDiv - 1) / build.SectorChallengeRatioDiv
return (sectors-1)/build.SectorChallengeRatioDiv + 1
}
func (t *Ticket) Equals(ot *Ticket) bool {