@@ -34,6 +34,8 @@ MAX_TARGET = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
|||||||
class MissingHeader(Exception):
|
class MissingHeader(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class InvalidHeader(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def serialize_header(res):
|
def serialize_header(res):
|
||||||
s = int_to_hex(res.get('version'), 4) \
|
s = int_to_hex(res.get('version'), 4) \
|
||||||
@@ -46,9 +48,9 @@ def serialize_header(res):
|
|||||||
|
|
||||||
def deserialize_header(s, height):
|
def deserialize_header(s, height):
|
||||||
if not s:
|
if not s:
|
||||||
raise Exception('Invalid header: {}'.format(s))
|
raise InvalidHeader('Invalid header: {}'.format(s))
|
||||||
if len(s) != 80:
|
if len(s) != 80:
|
||||||
raise Exception('Invalid header length: {}'.format(len(s)))
|
raise InvalidHeader('Invalid header length: {}'.format(len(s)))
|
||||||
hex_to_int = lambda s: int('0x' + bh2u(s[::-1]), 16)
|
hex_to_int = lambda s: int('0x' + bh2u(s[::-1]), 16)
|
||||||
h = {}
|
h = {}
|
||||||
h['version'] = hex_to_int(s[0:4])
|
h['version'] = hex_to_int(s[0:4])
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ from .interface import Connection, Interface
|
|||||||
from . import blockchain
|
from . import blockchain
|
||||||
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
from .blockchain import InvalidHeader
|
||||||
|
|
||||||
|
|
||||||
NODES_RETRY_INTERVAL = 60
|
NODES_RETRY_INTERVAL = 60
|
||||||
@@ -1075,7 +1076,11 @@ class Network(util.DaemonThread):
|
|||||||
# no point in keeping this connection without headers sub
|
# no point in keeping this connection without headers sub
|
||||||
self.connection_down(interface.server)
|
self.connection_down(interface.server)
|
||||||
return
|
return
|
||||||
header = blockchain.deserialize_header(util.bfh(header_hex), height)
|
try:
|
||||||
|
header = blockchain.deserialize_header(util.bfh(header_hex), height)
|
||||||
|
except InvalidHeader:
|
||||||
|
self.connection_down(interface.server)
|
||||||
|
return
|
||||||
if height < self.max_checkpoint():
|
if height < self.max_checkpoint():
|
||||||
self.connection_down(interface.server)
|
self.connection_down(interface.server)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user