diff --git a/lib/coins.py b/lib/coins.py index 71129b6..334299e 100644 --- a/lib/coins.py +++ b/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" diff --git a/server/block_processor.py b/server/block_processor.py index 144fb6a..583dad4 100644 --- a/server/block_processor.py +++ b/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() diff --git a/server/db.py b/server/db.py index 58c7d9e..08a08e6 100644 --- a/server/db.py +++ b/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):