Skip to content

Commit

Permalink
fixup! blockchain: implement third fork
Browse files Browse the repository at this point in the history
The `//` operator in Python was used for integer division
while it actually performs a floor division. This is only
an issue for negative numbers, e.g.

>>>  3.2 // 2
1.0
>>> -3.2 // 2
-2.0  # should be -1.0
  • Loading branch information
toxeus committed May 3, 2018
1 parent bd5e939 commit d41d6ba
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,13 @@ def __fork_three_target(self, height, headers):
bits = last.get('bits')
target = Blockchain.bits2target(bits)
first = self.get_header(last_height - 15, height, headers)
nActualTimespanShort = (last.get('timestamp') - first.get('timestamp')) // 15
nActualTimespanShort = int((last.get('timestamp') - first.get('timestamp')) / 15)
first = self.get_header(last_height - 120, height, headers)
nActualTimespanMedium = (last.get('timestamp') - first.get('timestamp')) // 120
nActualTimespanMedium = int((last.get('timestamp') - first.get('timestamp')) / 120)
first = self.get_header(last_height - 480, height, headers)
nActualTimespanLong = (last.get('timestamp') - first.get('timestamp')) // 480
nActualTimespanLong = int((last.get('timestamp') - first.get('timestamp')) / 480)
nActualTimespan = (nActualTimespanShort + nActualTimespanMedium + nActualTimespanLong) // 3
assert nActualTimespan >= 0
nTargetTimespan = 60
nActualTimespan = Blockchain.__damp(nActualTimespan, nTargetTimespan)
return Blockchain.__get_target(target, nActualTimespan, nTargetTimespan, 453, 494)
Expand Down

0 comments on commit d41d6ba

Please sign in to comment.