Browse Source

Merge pull request #45 from thelazier/header_hash

fs_block_hashes need correct header_hash from coin
master
Neil 8 years ago
committed by GitHub
parent
commit
ffd9c65e7d
  1. 17
      lib/coins.py
  2. 9
      server/block_processor.py
  3. 4
      server/db.py

17
lib/coins.py

@ -215,9 +215,14 @@ class Coin(object):
return Base58.encode_check(payload)
@classmethod
def header_hashes(cls, header):
'''Given a header return the previous and current block hashes.'''
return header[4:36], double_sha256(header)
def header_hash(cls, header):
'''Given a header return hash'''
return double_sha256(header)
@classmethod
def header_prevhash(cls, header):
'''Given a header return previous hash'''
return header[4:36]
@classmethod
def read_block(cls, block):
@ -368,10 +373,10 @@ class Dash(Coin):
IRC_CHANNEL = "#electrum-dash"
@classmethod
def header_hashes(cls, header):
'''Given a header return the previous and current block hashes.'''
def header_hash(cls, header):
'''Given a header return the hash.'''
import x11_hash
return header[4:36], x11_hash.getPoWHash(header)
return x11_hash.getPoWHash(header)
class DashTestnet(Dash):
NAME = "Dash"

9
server/block_processor.py

@ -568,13 +568,12 @@ class BlockProcessor(server.db.DB):
# the UTXO cache uses the FS cache via get_tx_hash() to
# resolve compressed key collisions
header, tx_hashes, txs = self.coin.read_block(block)
prev_hash, header_hash = self.coin.header_hashes(header)
if prev_hash != self.tip:
if self.tip != self.coin.header_prevhash(header):
raise ChainReorg
touched = set()
self.fs_advance_block(header, tx_hashes, txs)
self.tip = header_hash
self.tip = self.coin.header_hash(header)
self.height += 1
undo_info = self.advance_txs(tx_hashes, txs, touched)
if self.daemon.cached_height() - self.height <= self.reorg_limit:
@ -636,14 +635,14 @@ class BlockProcessor(server.db.DB):
touched = set()
for block in blocks:
header, tx_hashes, txs = self.coin.read_block(block)
prev_hash, header_hash = self.coin.header_hashes(header)
header_hash = self.coin.header_hash(header)
if header_hash != self.tip:
raise ChainError('backup block {} is not tip {} at height {:,d}'
.format(hash_to_str(header_hash),
hash_to_str(self.tip), self.height))
self.backup_txs(tx_hashes, txs, touched)
self.tip = prev_hash
self.tip = self.coin.header_prevhash(header)
assert self.height >= 0
self.height -= 1
self.tx_counts.pop()

4
server/db.py

@ -16,7 +16,7 @@ from bisect import bisect_right
from collections import namedtuple
from lib.util import chunks, formatted_time, LoggedClass
from lib.hash import double_sha256, hash_to_str
from lib.hash import hash_to_str
from server.storage import open_db
from server.version import VERSION
@ -175,7 +175,7 @@ class DB(LoggedClass):
headers = self.fs_read_headers(height, count)
# FIXME: move to coins.py
hlen = self.coin.HEADER_LEN
return [double_sha256(header) for header in chunks(headers, hlen)]
return [self.coin.header_hash(header) for header in chunks(headers, hlen)]
@staticmethod
def _resolve_limit(limit):

Loading…
Cancel
Save