Browse Source

limit squatted blocks quantity to 1 per step; add info comments.

main
D4708 3 years ago
parent
commit
19b816a73d
  1. 15
      follower.py

15
follower.py

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# #
# Auto-following/reading bot written in Python 2 that has a mission to safe distributed data shared in the twister network # Auto-following/reading bot written in Python 2 has a mission to safe distributed data shared in the twister network
# (https://github.com/twisterarmy/twister-data-guard) # (https://github.com/twisterarmy/twister-data-guard)
# This script based on the official usernameCrawler # This script based on the official usernameCrawler
# (https://github.com/miguelfreitas/twister-core/blob/master/contrib/usernameCrawler.py) # (https://github.com/miguelfreitas/twister-core/blob/master/contrib/usernameCrawler.py)
@ -11,9 +11,10 @@
import sys, cPickle import sys, cPickle
dbFileName = "twisterDataGuard.pickle" dbFileName = "twisterDataGuard.pickle" # service database file
nodeUserName = "twisterdataguard" nodeUserName = "twisterdataguard" # twister wallet (user)
blocksInStep = 100 blocksInStep = 100 # mlocks processing by the one step
squattersStop = 20 # max users per block. Reset the blocksInStep on this quantity to prevent CPU overload
class MyDb: class MyDb:
lastBlockHash = 0 lastBlockHash = 0
@ -52,7 +53,12 @@ if not dataLock:
block = twister.getblock(nextHash) block = twister.getblock(nextHash)
db.lastBlockHash = block["hash"] db.lastBlockHash = block["hash"]
if squattersStop < 0:
db.dataLock = False
break
blocksInStep = blocksInStep - 1 blocksInStep = blocksInStep - 1
if blocksInStep < 0: if blocksInStep < 0:
db.dataLock = False db.dataLock = False
break break
@ -62,6 +68,7 @@ if not dataLock:
for u in block["usernames"]: for u in block["usernames"]:
print "follow", u print "follow", u
twister.follow(nodeUserName, [u]) twister.follow(nodeUserName, [u])
squattersStop = squattersStop - 1
if block.has_key("nextblockhash"): if block.has_key("nextblockhash"):
nextHash = block["nextblockhash"] nextHash = block["nextblockhash"]
else: else:

Loading…
Cancel
Save