Stricter checks in sidechain GetDifficulty via 645de31fe3

This commit is contained in:
DataHoarder 2023-03-27 14:37:50 +02:00
parent 0382deccba
commit 50d2f56d06
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -317,8 +317,15 @@ func GetDifficulty(tip *PoolBlock, consensus *Consensus, getByTemplateId GetByTe
timestamp1 := oldestTimestamp + uint64(tmpTimestamps[index1])
timestamp2 := oldestTimestamp + uint64(tmpTimestamps[index2])
deltaT := uint64(1)
if timestamp2 > timestamp1 {
// Make a reasonable assumption that each block has higher timestamp, so deltaT can't be less than deltaIndex
// Because if it is, someone is trying to mess with timestamps
// In reality, deltaT ~ deltaIndex*10 (sidechain block time)
deltaIndex := uint64(1)
if index2 > index2 {
deltaIndex = uint64(index2 - index1)
}
deltaT := deltaIndex
if timestamp2 > (timestamp1 + deltaIndex) {
deltaT = timestamp2 - timestamp1
}