delinting!

This commit is contained in:
Jude Nelson
2018-07-06 13:48:24 -04:00
parent 803f2cd9ef
commit 733e3ce9ef
13 changed files with 38 additions and 35 deletions

View File

@@ -1648,7 +1648,7 @@ def atlas_peer_getinfo( peer_hostport, timeout=None, peer_table=None ):
res = {'error': 'Remote peer {} did not rely last_block_processed'.format(peer_hostport)}
if 'stale' in res and res['stale']:
log.error("Remote host is well behind the chain tip".format(peer_hostport))
log.error("Remote host {} is well behind the chain tip".format(peer_hostport))
res = {'error': 'Remote peer {} is well behind the chain tip'.format(peer_hostport)}
if 'testnet' in res:
@@ -3532,7 +3532,7 @@ class AtlasZonefilePusher(threading.Thread):
# it's a valid zonefile. store it.
rc = add_atlas_zonefile_data( str(zfdata_txt), self.zonefile_dir )
if not rc:
log.error("Failed to replicate zonefile %s to external storage" % zonefile_hash)
log.error("Failed to replicate zonefile %s to external storage" % zfhash)
peers = None

View File

@@ -24,6 +24,7 @@
import re
import string
from binascii import hexlify, unhexlify
import virtualchain
B16_CHARS = string.hexdigits[0:16]
B40_CHARS = string.digits + string.lowercase + '-_.+'

View File

@@ -24,6 +24,7 @@
import sys
import os
import xmlrpclib
from xmlrpclib import ServerProxy, Transport
from defusedxml import xmlrpc
import httplib
@@ -943,6 +944,8 @@ def get_zonefiles_by_block(from_block, to_block, hostport=None, proxy=None):
output_zonefiles = []
last_server_block = 0
resp = {'zonefile_info': []}
while offset == 0 or len(resp['zonefile_info']) > 0:
resp = proxy.get_zonefiles_by_block(from_block, to_block, offset, 100)
@@ -1885,7 +1888,7 @@ def get_all_subdomains(offset=0, count=100, proxy=None, hostport=None):
for name in resp['names']:
if not is_subdomain(str(name)):
raise ValidationError()
raise ValidationError('Not a valid subdomain: {}'.format(str(name)))
except ValidationError as ve:
if BLOCKSTACK_DEBUG:

View File

@@ -187,7 +187,7 @@ RPC_DEFAULT_TIMEOUT = 30 # in secs
RPC_MAX_ZONEFILE_LEN = 40960 # 40KB
RPC_MAX_INDEXING_DELAY = 2 * 3600 # 2 hours; maximum amount of time before the absence of new blocks causes the node to stop responding
MAX_RPC_LEN = RPC_MAX_ZONEFILE_LEN * 10 # maximum blockstackd RPC length
MAX_RPC_LEN = RPC_MAX_ZONEFILE_LEN * 150 # maximum blockstackd RPC length (100 40K zone files, plus base64 encoding overhead and XMLRPC padding)
if os.environ.get("BLOCKSTACK_TEST_MAX_RPC_LEN"):
MAX_RPC_LEN = int(os.environ.get("BLOCKSTACK_TEST_MAX_RPC_LEN"))
print("Overriding MAX_RPC_LEN to {}".format(MAX_RPC_LEN))
@@ -1272,7 +1272,7 @@ def store_announcement( working_dir, announcement_hash, announcement_text, force
failed_path = announce_filename_tmp + (".%s" % i)
while os.path.exists( failed_path ):
log.debug("Merge announcement list %s" % failed_paht )
log.debug("Merge announcement list %s" % failed_path )
with open(failed_path, "r") as f:
announce_text += f.read()
@@ -1302,9 +1302,9 @@ def store_announcement( working_dir, announcement_hash, announcement_text, force
f.flush()
# NOTE: rename doesn't remove the old file on Windows
if sys.platform == 'win32' and os.path.exists( announcement_filename_tmp ):
if sys.platform == 'win32' and os.path.exists( announce_filename_tmp ):
try:
os.unlink( announcement_filename_tmp )
os.unlink( announce_filename_tmp )
except:
pass

View File

@@ -499,7 +499,7 @@ def fast_sync_inspect_snapshot( snapshot_path ):
with open(snapshot_path, 'r') as f:
info = fast_sync_inspect( f )
if 'error' in info:
log.error("Failed to inspect snapshot {}: {}".format(import_path, info['error']))
log.error("Failed to inspect snapshot {}: {}".format(snapshot_path, info['error']))
return {'error': 'Failed to inspect snapshot'}
# get the hash of the file

View File

@@ -326,7 +326,7 @@ def namedb_create_token_genesis(con, initial_account_balances, genesis_block_his
if 'vesting' in account_info:
assert 'vesting_total' in account_info, 'BUG: vesting is present but vesting_total is not'
vesting_sum = sum([ac[h] for h in account_info['vesting']])
vesting_sum = sum([account_info['vesting'][h] for h in account_info['vesting']])
assert vesting_sum == account_info['vesting_total'], 'BUG: vesting mismatch on {}: {} != {}'.format(address, vesting_sum, account_info['vesting'])
for block_height in account_info['vesting']:
@@ -2200,7 +2200,7 @@ def namedb_get_preorder(cur, preorder_hash, current_block_number, include_expire
args = (preorder_hash, expiry_time + current_block_number)
preorder_rows = namedb_query_execute( cur, select_query, (preorder_hash,))
preorder_row = preorder_row.fetchone()
preorder_row = preorder_rows.fetchone()
if preorder_row is None:
# no such preorder
return None
@@ -2816,7 +2816,7 @@ if __name__ == "__main__":
path = "/tmp/namedb.sqlite"
if not os.path.exists( path ):
db = namedb_create( path )
db = namedb_create( path, {'rows': [], 'history': []})
else:
db = namedb_open( path )

View File

@@ -50,7 +50,7 @@ blockstack_db_lastblock = None
blockstack_db_lock = threading.Lock()
def autofill( *autofill_fields ):
def autofill(*autofill_fields):
"""
Decorator to automatically fill in extra useful fields
that aren't stored in the db.
@@ -71,7 +71,7 @@ def autofill( *autofill_fields ):
return wrap
class BlockstackDB( virtualchain.StateEngine ):
class BlockstackDB(virtualchain.StateEngine):
"""
State engine implementation for blockstack.
"""
@@ -858,7 +858,8 @@ class BlockstackDB( virtualchain.StateEngine ):
"""
Get two consecutive account states---the one at (block_id, vtxindex), and the one prior.
"""
return namedb_get_account_delta(address, token_type, block_id, vtxindex)
cur = self.db.cursor()
return namedb_get_account_delta(cur, address, token_type, block_id, vtxindex)
def get_account_diff(self, current, prior):
@@ -1391,7 +1392,7 @@ class BlockstackDB( virtualchain.StateEngine ):
Given a namespace preorder hash, determine if it is preordered
at the current block.
"""
namespace_preorder = self.get_namespace_preorder( self.db, namespace_id_hash, self.lastblock )
namespace_preorder = self.get_namespace_preorder(namespace_id_hash)
if namespace_preorder is None:
return False
else:
@@ -1646,7 +1647,7 @@ class BlockstackDB( virtualchain.StateEngine ):
except Exception as e:
log.exception(e)
log.fatal("Sanity check failed")
os.abort
os.abort()
# have to debit this account
cur = self.db.cursor()
@@ -1683,7 +1684,7 @@ class BlockstackDB( virtualchain.StateEngine ):
except Exception as e:
log.exception(e)
log.fatal("Sanity check failed")
os.abort
os.abort()
# have to debit this account
cur = self.db.cursor()
@@ -1728,7 +1729,7 @@ class BlockstackDB( virtualchain.StateEngine ):
# cannot have collided
if BlockstackDB.nameop_is_collided( nameop ):
log.debug("Not commiting '%s', since it collided" % nameop)
self.log_reject( block_id, nameop['vtxindex'], nameop['op'], nameop )
self.log_reject(current_block_number, nameop['vtxindex'], nameop['op'], nameop)
return []
self.log_accept( current_block_number, nameop['vtxindex'], nameop['op'], nameop )
@@ -1983,16 +1984,6 @@ class BlockstackDB( virtualchain.StateEngine ):
return True
@classmethod
def restore_from_history( cls, rec, block_id ):
"""
Given a record with a history and a block number,
calculate the sequence of states it went through
in that block number.
"""
return namedb_restore_from_history( rec, block_id )
def get_block_ops_hash( self, block_id ):
"""
Get the block's operations hash

View File

@@ -247,7 +247,7 @@ def check( state_engine, nameop, block_id, checked_ops ):
# must have paid enough
if namespace_fee < price_namespace(namespace_id, block_id, units):
# not enough money
log.warning("Namespace '%s' costs %s, but sender paid %s" % (namespace_id, price_namespace(namespace_id, block_id), namespace_fee ))
log.warning("Namespace '%s' costs %s, but sender paid %s" % (namespace_id, price_namespace(namespace_id, block_id, units), namespace_fee))
return False
else:

View File

@@ -217,4 +217,4 @@ def queuedb_peek(path, queue_id, name):
"""
Find the oldest instance of a named record in a queue.
"""
return queuedb_find( queue_id, name, limit=1, path=path )
return queuedb_find(path, queue_id, name, limit=1)

View File

@@ -57,7 +57,7 @@ from virtualchain import AuthServiceProxy, JSONRPCException
import blockstack_zones
from schemas import OP_BASE64_EMPTY_PATTERN
from schemas import OP_BASE64_EMPTY_PATTERN, OP_ZONEFILE_HASH_PATTERN
log = virtualchain.get_logger()
@@ -415,7 +415,7 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
if end_block is None:
log.error('endblock= required')
return self_reply_json({'error': 'endblock= argument required'}, status_code=400)
return self._reply_json({'error': 'endblock= argument required'}, status_code=400)
if page is None:
log.error("page= required")
@@ -785,14 +785,18 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
blockstackd_url = get_blockstackd_url()
zonefile_json = self._read_json(schema=request_schema)
if zonefile_json is None:
return self.reply_json({'error': 'Invalid request'}, status_code=400)
return self._reply_json({'error': 'Invalid request'}, status_code=400)
elif 'error' in zonefile_json:
log.error("Failed to parse JSON")
return self._reply_json({'error': 'Invalid request'}, status_code=400)
zonefile_str = zonefile_json.get('zonefile', False)
zonefile_hash = None
if zonefile_str:
# base64-encode
zonefile_hash = storage.get_zonefile_data_hash(zonefile_str)
zonefile_str = base64.b64encode(zonefile_str)
else:
@@ -802,6 +806,8 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
# neither given
return self._reply_json({'error': 'Invalid request'}, status_code=400)
zonefile_hash = storage.get_zonefile_data_hash(base64.b64decode(zonefile_json['zonefile_b64']))
zonefiles_b64 = [zonefile_str]
resp = blockstackd_client.put_zonefiles(blockstackd_url, zonefiles_b64)
if json_is_error(resp):

View File

@@ -25,6 +25,7 @@ import virtualchain
import keylib
log = virtualchain.get_logger("blockstack-server")
import re
import traceback
from .config import *
from .b40 import *

View File

@@ -31,7 +31,7 @@ import virtualchain
import blockstack_zones
import threading
from virtualchain import bitcoin_blockchain
import virtualchain.lib.blockchain.bitcoin_blockchain as bitcoin_blockchain
from .config import BLOCKSTACK_TESTNET, BLOCKSTACK_TEST, BLOCKSTACK_DEBUG, SUBDOMAINS_FIRST_BLOCK, get_blockstack_opts, is_atlas_enabled, is_subdomains_enabled, \
SUBDOMAIN_ADDRESS_VERSION_BYTE, SUBDOMAIN_ADDRESS_MULTISIG_VERSION_BYTE, SUBDOMAIN_ADDRESS_VERSION_BYTES
@@ -332,7 +332,7 @@ class Subdomain(object):
if BLOCKSTACK_DEBUG:
log.exception(ae)
raise ParserError("Invalid names: {}".format(ae))
raise ParseError("Invalid names: {}".format(ae))
else:
# already fully-qualified

View File

@@ -35,6 +35,7 @@ import jsonschema
import random
import sqlite3
import re
import signal
import keylib
import virtualchain