Skip to content

Commit

Permalink
Fixes bug with minimum difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Apr 7, 2024
1 parent f427347 commit e0cdbc2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Binary file modified builds/node/node_linux-arm64
Binary file not shown.
6 changes: 0 additions & 6 deletions create_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ func CreateBlock() (Block, error) {
TimeVerifierSignatures: []Signature{},
TimeVerifiers: []dsa.PublicKey{},
}
if block.Difficulty < minimumBlockDifficulty {
block.Difficulty = minimumBlockDifficulty
}
if len(blockchain) > 0 {
block.PreviousBlockHash = HashBlock(blockchain[len(blockchain)-1])
} else {
Expand Down Expand Up @@ -79,9 +76,6 @@ func CreateBlock() (Block, error) {
block.PreviousBlockHash = [32]byte{}
}
block.Difficulty = GetDifficulty(previousBlock.MiningTime, previousBlock.Difficulty)
if block.Difficulty < minimumBlockDifficulty {
block.Difficulty = minimumBlockDifficulty
}
block.Nonce++
hashBytes = HashBlock(block)
hash = binary.BigEndian.Uint64(hashBytes[:])
Expand Down
6 changes: 5 additions & 1 deletion difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ func GetDifficulty(lastTime time.Duration, lastDifficulty uint64) uint64 {
x := lastTime.Minutes() * float64(lastDifficulty)
adjustment := (1 / (1 + math.Pow(math.E, -(1/mdpm)*(x-mdpm)))) + 0.5
difficultyAfterAdjustment := float64(difficultyBeforeAdjustment) / adjustment
return uint64(difficultyAfterAdjustment)
difficultyUint64 := uint64(difficultyAfterAdjustment)
if difficultyUint64 > minimumBlockDifficulty {
return difficultyUint64
}
return minimumBlockDifficulty
}

0 comments on commit e0cdbc2

Please sign in to comment.