Skip to content

Commit

Permalink
Fix a bug in State reversion. Closes #315.
Browse files Browse the repository at this point in the history
Also has the Blockchain Test generate packets once again, as well as 
changes the Element setup to something fuzzier.
  • Loading branch information
kayabaNerve committed May 30, 2021
1 parent cece8c2 commit e5ca442
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Database/Merit/State.nim
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ proc revert*(
#Don't add Merit back if the miner has a MeritRemoval.
var removed: bool = false
try:
removed = state.db.loadRemovalHeight(nick) < height
removed = state.db.loadRemovalHeight(nick) <= height
except DBReadError:
discard
if not removed:
Expand Down
49 changes: 24 additions & 25 deletions tests/Database/Merit/BlockchainTest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,35 @@ suite "Blockchain":
if state.holders.len != removed.card:
#Randomize the Packets.
packets = @[]
for _ in 0 ..< rand(0):#300):
for _ in 0 ..< rand(300):
packets.add(newValidVerificationPacket(state.holders, removed))

#Randomize the Elements/removals.
elements = @[]
toRemove = {}
if rand(1) == 0:
for _ in 0 ..< 3:
var
holder: uint16 = getNonMaliciousHolder()
elementNonce: int
try:
elementNonce = elementNonces[holder]
except KeyError:
elementNonce = 0
elementNonces[holder] = elementNonce + 1

case rand(2):
of 0:
var sd: SignedSendDifficulty = newSignedSendDifficultyObj(elementNonce, uint16(rand(high(int16))))
miners[holder].sign(sd)
elements.add(sd)
of 1:
var dd: SignedDataDifficulty = newSignedDataDifficultyObj(elementNonce, uint16(rand(high(int16))))
miners[holder].sign(dd)
elements.add(dd)
of 2:
toRemove.incl(holder)
else:
panic("Generated a number outside of the provided range.")
for _ in 0 ..< rand(3):
var
holder: uint16 = getNonMaliciousHolder()
elementNonce: int
try:
elementNonce = elementNonces[holder]
except KeyError:
elementNonce = 0
elementNonces[holder] = elementNonce + 1

case rand(2):
of 0:
var sd: SignedSendDifficulty = newSignedSendDifficultyObj(elementNonce, uint16(rand(high(int16))))
miners[holder].sign(sd)
elements.add(sd)
of 1:
var dd: SignedDataDifficulty = newSignedDataDifficultyObj(elementNonce, uint16(rand(high(int16))))
miners[holder].sign(dd)
elements.add(dd)
of 2:
toRemove.incl(holder)
else:
panic("Generated a number outside of the provided range.")

#Decide if this is a nickname or new miner Block.
if (miners.len == removed.card) or (rand(2) == 0):
Expand Down

0 comments on commit e5ca442

Please sign in to comment.