Skip to content

Commit

Permalink
fix consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
pdxwebdev committed Oct 16, 2018
1 parent 9224916 commit 0b446a9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion node.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def node(nonces=None, config=None):
Config.from_dict(json.loads(config))
Peers.init()
latest_block_index = Value('i', 0)
my_peer = Config.peer_host + ":" + str(Config.peer_port)
with open('mypeer') as f:
my_peer = f.read()
Config.max_duration = 300000
Config.block_version = 1
#p = Process(target=new_block_checker, args=(latest_block_index,))
Expand Down
3 changes: 2 additions & 1 deletion p2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ def get_base_graph():
Config.serve_port = Config.serve_port
Config.peer_host = Config.peer_host
Config.peer_port = Config.peer_port

with open('mypeer', 'w') as f:
f.write(Config.peer_host + ":" + str(Config.peer_port))
try:
res = requests.post(
'https://yadacoin.io/peers',
Expand Down
2 changes: 1 addition & 1 deletion rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def changetime(block):

@app.route('/api-stats')
def api_stats():
max_target = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
max_target = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
blocks = BU.get_blocks()
total_nonce = 0
periods = []
Expand Down
4 changes: 2 additions & 2 deletions yadacoin/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def set_merkle_root(self, txn_hashes):
@classmethod
def get_target(cls, height, last_time, last_block, blockchain):
# change target
max_target = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
max_target = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
retarget_period = 2016 # blocks
two_weeks = 1209600 # seconds
half_week = 302400 # seconds
Expand Down Expand Up @@ -186,7 +186,7 @@ def mine(cls, transactions, public_key, private_key, max_duration, callback=None
latest_block = Block.from_dict(BU.get_latest_block())
last_time = latest_block.time

max_target = 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
max_target = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
target = cls.get_target(height, last_time, latest_block, Blockchain([x for x in BU.get_blocks()]))

block_factory = cls(
Expand Down
4 changes: 3 additions & 1 deletion yadacoin/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def find_error_block(self):
def get_difficulty(self):
difficulty = 0
for block in self.blocks:
if block.index == 18170:
pass
target = int(block.hash, 16)
difficulty += 0x0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - target
difficulty += (0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - target)
return difficulty

def get_highest_block_height(self):
Expand Down

0 comments on commit 0b446a9

Please sign in to comment.