More PEP8 stuff
This commit is contained in:
parent
33cdfa4fc8
commit
3f35bc0298
@ -71,8 +71,8 @@ class Coin(object):
|
|||||||
req_attrs = ('TX_COUNT', 'TX_COUNT_HEIGHT', 'TX_PER_BLOCK',
|
req_attrs = ('TX_COUNT', 'TX_COUNT_HEIGHT', 'TX_PER_BLOCK',
|
||||||
'IRC_CHANNEL')
|
'IRC_CHANNEL')
|
||||||
for coin in util.subclasses(Coin):
|
for coin in util.subclasses(Coin):
|
||||||
if (coin.NAME.lower() == name.lower()
|
if (coin.NAME.lower() == name.lower() and
|
||||||
and coin.NET.lower() == net.lower()):
|
coin.NET.lower() == net.lower()):
|
||||||
missing = [attr for attr in req_attrs
|
missing = [attr for attr in req_attrs
|
||||||
if not hasattr(coin, attr)]
|
if not hasattr(coin, attr)]
|
||||||
if missing:
|
if missing:
|
||||||
|
|||||||
@ -88,7 +88,7 @@ class Peer(object):
|
|||||||
minor_version) pair.
|
minor_version) pair.
|
||||||
'''
|
'''
|
||||||
if isinstance(vstr, str) and VERSION_REGEX.match(vstr):
|
if isinstance(vstr, str) and VERSION_REGEX.match(vstr):
|
||||||
if not '.' in vstr:
|
if '.' not in vstr:
|
||||||
vstr += '.0'
|
vstr += '.0'
|
||||||
else:
|
else:
|
||||||
vstr = '1.0'
|
vstr = '1.0'
|
||||||
|
|||||||
@ -52,8 +52,8 @@ class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")):
|
|||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def is_coinbase(self):
|
def is_coinbase(self):
|
||||||
return (self.prev_hash == TxInput.ZERO
|
return (self.prev_hash == TxInput.ZERO and
|
||||||
and self.prev_idx == TxInput.MINUS_1)
|
self.prev_idx == TxInput.MINUS_1)
|
||||||
|
|
||||||
@cachedproperty
|
@cachedproperty
|
||||||
def script_sig_info(self):
|
def script_sig_info(self):
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
from collections import Container, Mapping
|
from collections import Container, Mapping
|
||||||
|
|
||||||
|
|
||||||
class LoggedClass(object):
|
class LoggedClass(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -131,8 +132,8 @@ def deep_getsizeof(obj):
|
|||||||
def subclasses(base_class, strict=True):
|
def subclasses(base_class, strict=True):
|
||||||
'''Return a list of subclasses of base_class in its module.'''
|
'''Return a list of subclasses of base_class in its module.'''
|
||||||
def select(obj):
|
def select(obj):
|
||||||
return (inspect.isclass(obj) and issubclass(obj, base_class)
|
return (inspect.isclass(obj) and issubclass(obj, base_class) and
|
||||||
and (not strict or obj != base_class))
|
(not strict or obj != base_class))
|
||||||
|
|
||||||
pairs = inspect.getmembers(sys.modules[base_class.__module__], select)
|
pairs = inspect.getmembers(sys.modules[base_class.__module__], select)
|
||||||
return [pair[1] for pair in pairs]
|
return [pair[1] for pair in pairs]
|
||||||
@ -222,6 +223,7 @@ def open_file(filename, create=False):
|
|||||||
return open(filename, 'wb+')
|
return open(filename, 'wb+')
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def open_truncate(filename):
|
def open_truncate(filename):
|
||||||
'''Open the file name. Return its handle.'''
|
'''Open the file name. Return its handle.'''
|
||||||
return open(filename, 'wb+')
|
return open(filename, 'wb+')
|
||||||
|
|||||||
@ -568,7 +568,7 @@ class BlockProcessor(server.db.DB):
|
|||||||
header = coin.block_header(block, self.height)
|
header = coin.block_header(block, self.height)
|
||||||
header_hash = coin.header_hash(header)
|
header_hash = coin.header_hash(header)
|
||||||
if header_hash != self.tip:
|
if header_hash != self.tip:
|
||||||
raise ChainError('backup block {} is not tip {} at height {:,d}'
|
raise ChainError('backup block {} not tip {} at height {:,d}'
|
||||||
.format(hash_to_str(header_hash),
|
.format(hash_to_str(header_hash),
|
||||||
hash_to_str(self.tip), self.height))
|
hash_to_str(self.tip), self.height))
|
||||||
self.tip = coin.header_prevhash(header)
|
self.tip = coin.header_prevhash(header)
|
||||||
|
|||||||
@ -394,7 +394,7 @@ class Controller(util.LoggedClass):
|
|||||||
.format(session.kind, session.peername(),
|
.format(session.kind, session.peername(),
|
||||||
len(self.sessions)))
|
len(self.sessions)))
|
||||||
if (len(self.sessions) >= self.max_sessions
|
if (len(self.sessions) >= self.max_sessions
|
||||||
and self.state == self.LISTENING):
|
and self.state == self.LISTENING):
|
||||||
self.state = self.PAUSED
|
self.state = self.PAUSED
|
||||||
session.log_info('maximum sessions {:,d} reached, stopping new '
|
session.log_info('maximum sessions {:,d} reached, stopping new '
|
||||||
'connections until count drops to {:,d}'
|
'connections until count drops to {:,d}'
|
||||||
|
|||||||
@ -105,7 +105,7 @@ class IRC(LoggedClass):
|
|||||||
nick = event.arguments[4]
|
nick = event.arguments[4]
|
||||||
if nick.startswith(self.prefix):
|
if nick.startswith(self.prefix):
|
||||||
line = event.arguments[6].split()
|
line = event.arguments[6].split()
|
||||||
hp_string = ' '.join(line[1:]) # hostname, ports, version etc.
|
hp_string = ' '.join(line[1:]) # hostname, ports, version etc.
|
||||||
self.peer_mgr.add_irc_peer(nick, hp_string)
|
self.peer_mgr.add_irc_peer(nick, hp_string)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -162,8 +162,8 @@ class MemPool(util.LoggedClass):
|
|||||||
deferred = pending
|
deferred = pending
|
||||||
pending = []
|
pending = []
|
||||||
|
|
||||||
result, deferred = await self.controller.run_in_executor \
|
result, deferred = await self.controller.run_in_executor(
|
||||||
(self.process_raw_txs, raw_txs, deferred)
|
self.process_raw_txs, raw_txs, deferred)
|
||||||
|
|
||||||
pending.extend(deferred)
|
pending.extend(deferred)
|
||||||
hashXs = self.hashXs
|
hashXs = self.hashXs
|
||||||
@ -279,8 +279,8 @@ class MemPool(util.LoggedClass):
|
|||||||
if not item or not raw_tx:
|
if not item or not raw_tx:
|
||||||
continue
|
continue
|
||||||
txin_pairs, txout_pairs = item
|
txin_pairs, txout_pairs = item
|
||||||
tx_fee = (sum(v for hashX, v in txin_pairs)
|
tx_fee = (sum(v for hashX, v in txin_pairs) -
|
||||||
- sum(v for hashX, v in txout_pairs))
|
sum(v for hashX, v in txout_pairs))
|
||||||
tx, tx_hash = deserializer(raw_tx).read_tx()
|
tx, tx_hash = deserializer(raw_tx).read_tx()
|
||||||
unconfirmed = any(txin.prev_hash in self.txs for txin in tx.inputs)
|
unconfirmed = any(txin.prev_hash in self.txs for txin in tx.inputs)
|
||||||
result.append((hex_hash, tx_fee, unconfirmed))
|
result.append((hex_hash, tx_fee, unconfirmed))
|
||||||
|
|||||||
@ -32,8 +32,8 @@ WAKEUP_SECS = 300
|
|||||||
def peer_from_env(env):
|
def peer_from_env(env):
|
||||||
'''Return ourself as a peer from the environment settings.'''
|
'''Return ourself as a peer from the environment settings.'''
|
||||||
main_identity = env.identities[0]
|
main_identity = env.identities[0]
|
||||||
hosts = {identity.host : {'tcp_port': identity.tcp_port,
|
hosts = {identity.host: {'tcp_port': identity.tcp_port,
|
||||||
'ssl_port': identity.ssl_port}
|
'ssl_port': identity.ssl_port}
|
||||||
for identity in env.identities}
|
for identity in env.identities}
|
||||||
features = {
|
features = {
|
||||||
'hosts': hosts,
|
'hosts': hosts,
|
||||||
@ -156,7 +156,7 @@ class PeerSession(JSONSession):
|
|||||||
our_height = self.peer_mgr.controller.bp.db_height
|
our_height = self.peer_mgr.controller.bp.db_height
|
||||||
their_height = result.get('block_height')
|
their_height = result.get('block_height')
|
||||||
if (not isinstance(their_height, int) or
|
if (not isinstance(their_height, int) or
|
||||||
abs(our_height - their_height) > 5):
|
abs(our_height - their_height) > 5):
|
||||||
self.failed = True
|
self.failed = True
|
||||||
self.peer.mark_bad()
|
self.peer.mark_bad()
|
||||||
self.log_warning('bad height {}'.format(their_height))
|
self.log_warning('bad height {}'.format(their_height))
|
||||||
@ -244,9 +244,9 @@ class PeerManager(util.LoggedClass):
|
|||||||
def rpc_data(self):
|
def rpc_data(self):
|
||||||
'''Peer data for the peers RPC method.'''
|
'''Peer data for the peers RPC method.'''
|
||||||
self.set_peer_statuses()
|
self.set_peer_statuses()
|
||||||
|
|
||||||
descs = ['good', 'stale', 'never', 'bad']
|
descs = ['good', 'stale', 'never', 'bad']
|
||||||
def peer_data( peer):
|
|
||||||
|
def peer_data(peer):
|
||||||
data = peer.serialize()
|
data = peer.serialize()
|
||||||
data['status'] = descs[peer.status]
|
data['status'] = descs[peer.status]
|
||||||
return data
|
return data
|
||||||
@ -304,8 +304,8 @@ class PeerManager(util.LoggedClass):
|
|||||||
'''
|
'''
|
||||||
cutoff = time.time() - STALE_SECS
|
cutoff = time.time() - STALE_SECS
|
||||||
recent = [peer for peer in self.peers
|
recent = [peer for peer in self.peers
|
||||||
if peer.last_connect > cutoff
|
if peer.last_connect > cutoff and
|
||||||
and not peer.bad and peer.is_public]
|
not peer.bad and peer.is_public]
|
||||||
onion_peers = []
|
onion_peers = []
|
||||||
|
|
||||||
# Always report ourselves if valid (even if not public)
|
# Always report ourselves if valid (even if not public)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user