Skip to content
Snippets Groups Projects
Commit 0b4b9dfb authored by MESSIE Vincent's avatar MESSIE Vincent
Browse files

added comments

parent 146d8240
No related branches found
No related tags found
No related merge requests found
Pipeline #3942 canceled
...@@ -75,21 +75,26 @@ func DoPOW(msg []byte) (uint64, error) { ...@@ -75,21 +75,26 @@ func DoPOW(msg []byte) (uint64, error) {
return nonce, err return nonce, err
} }
// Function to adjust the PoW difficulty, called on the reception of a mesasage.
// Takes a *tangle.Message as parameter, and returns the next difficulty to account.
func adjustDifficulty(message *tangle.Message) int { func adjustDifficulty(message *tangle.Message) int {
//TODO dire que c'est fait // We use a global variable to track the transaction solidication time
prevSolidificationTime := currentSolidificationTime prevSolidificationTime := currentSolidificationTime
currentSolidificationTime = time.Now().UnixNano() - message.IssuingTime().UnixNano()
deltat := currentSolidificationTime - prevSolidificationTime currentSolidificationTime = time.Now().UnixNano() - message.IssuingTime().UnixNano() //We calculate the message solidication time?
powIncrement := int(deltat / 600000) deltat := currentSolidificationTime - prevSolidificationTime // deltat tracks the evolution of solidification time (if it increases, deltat is positive, negative if decrease). Unit is nanoseconds
powIncrement := int(deltat / 600000) //We use this time difference to directly calculate the PoW (if it increases, POW difficulty increases)
// If/else block to cap the PoW difficulty between 1 & 10.
if difficulty+powIncrement > 10 { if difficulty+powIncrement > 10 {
return 10 return 10
} else if difficulty+powIncrement < 1 { } else if difficulty+powIncrement < 1 {
return 1 return 1
} }
// We return current difficulty (global variable) plus the increment calculated previously (positive if solidication time increases, negative otherwise).
return difficulty + powIncrement return difficulty + powIncrement
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment