registrations in 6 confirmations => 4 confs for preorder, 1 for register, 1 for update... now to test it with a local bsk node and see if utxo.blockstack.org shouts at me

This commit is contained in:
Aaron Blankstein
2017-07-03 19:18:09 -04:00
parent be48e1d227
commit f5863ccef2
8 changed files with 339 additions and 18 deletions

View File

@@ -29,7 +29,7 @@ import json
current_dir = os.path.abspath(os.path.dirname(__file__))
parent_dir = os.path.abspath(current_dir + "/../")
from ..constants import TX_EXPIRED_INTERVAL, TX_CONFIRMATIONS_NEEDED, TX_MIN_CONFIRMATIONS
from ..constants import TX_EXPIRED_INTERVAL, DEFAULT_TX_CONFIRMATIONS_NEEDED, TX_MIN_CONFIRMATIONS
from ..constants import MAXIMUM_NAMES_PER_ADDRESS
from ..constants import BLOCKSTACK_TEST, BLOCKSTACK_DRY_RUN
from ..constants import CONFIG_PATH, BLOCKSTACK_DEBUG
@@ -154,12 +154,12 @@ def get_tx_fee( tx_hex, config_path=CONFIG_PATH ):
return fee_per_byte * len(tx_hex)/2
def is_tx_accepted( tx_hash, num_needed=TX_CONFIRMATIONS_NEEDED, config_path=CONFIG_PATH ):
def is_tx_accepted( tx_hash, num_needed=DEFAULT_TX_CONFIRMATIONS_NEEDED, config_path=CONFIG_PATH ):
"""
Determine whether or not a transaction was accepted.
"""
tx_confirmations = get_tx_confirmations(tx_hash, config_path=config_path)
if tx_confirmations > num_needed:
if tx_confirmations >= num_needed:
return True
return False

View File

@@ -30,7 +30,7 @@ import keylib
current_dir = os.path.abspath(os.path.dirname(__file__))
parent_dir = os.path.abspath(current_dir + "/../")
from .queue import in_queue, queue_append, queue_findone
from .queue import in_queue, queue_append, queue_findone, extract_entry
from .blockchain import get_tx_confirmations
from .blockchain import get_utxos, get_tx_fee_per_byte
@@ -2102,6 +2102,11 @@ def async_preorder(fqu, payment_privkey_info, owner_privkey_info, cost, name_dat
log.exception(e)
return {'error': 'Failed to sign and broadcast preorder transaction'}
additionals = {}
if 'aggressive_registration' in name_data:
log.debug("Adding an *aggressive* preorder for {}".format(fqu))
additionals['aggressive_registration'] = name_data['aggressive_registration']
additionals['confirmations_needed'] = 4
if 'transaction_hash' in resp:
if not BLOCKSTACK_DRY_RUN:
# watch this preorder, and register it when it gets queued
@@ -2112,7 +2117,7 @@ def async_preorder(fqu, payment_privkey_info, owner_privkey_info, cost, name_dat
zonefile_data=name_data.get('zonefile'),
profile=name_data.get('profile'),
config_path=config_path,
path=queue_path)
path=queue_path, **additionals)
else:
assert 'error' in resp
log.error("Error preordering: %s with %s for %s" % (fqu, payment_address, owner_address))
@@ -2177,6 +2182,13 @@ def async_register(fqu, payment_privkey_info, owner_privkey_info, name_data={},
log.exception(e)
return {'error': 'Failed to sign and broadcast registration transaction'}
entry_data = extract_entry( preorder_entry[0] )
additionals = {}
if 'aggressive_registration' in entry_data:
log.debug("Adding an *aggressive* register for {}".format(fqu))
additionals['aggressive_registration'] = entry_data['aggressive_registration']
additionals['confirmations_needed'] = 1
if 'transaction_hash' in resp:
if not BLOCKSTACK_DRY_RUN:
queue_append("register", fqu, resp['transaction_hash'],
@@ -2186,7 +2198,7 @@ def async_register(fqu, payment_privkey_info, owner_privkey_info, name_data={},
zonefile_data=name_data.get('zonefile'),
profile=name_data.get('profile'),
config_path=config_path,
path=queue_path)
path=queue_path, **additionals)
return resp
@@ -2256,6 +2268,18 @@ def async_update(fqu, zonefile_data, profile, owner_privkey_info, payment_privke
log.exception(e)
return {'error': 'Failed to sign and broadcast update transaction'}
register_entry = queue_findone( "register", fqu, path=queue_path )
if len(register_entry) == 0:
log.error("No register for '%s'" % fqu)
return {'error': 'No register found'}
entry_data = extract_entry( register_entry[0] )
additionals = {}
if 'aggressive_registration' in entry_data:
log.debug("Adding an *aggressive* update for {}".format(fqu))
additionals['aggressive_registration'] = entry_data['aggressive_registration']
additionals['confirmations_needed'] = 1
if 'transaction_hash' in resp:
if not BLOCKSTACK_DRY_RUN:
queue_append("update", fqu, resp['transaction_hash'],
@@ -2265,7 +2289,7 @@ def async_update(fqu, zonefile_data, profile, owner_privkey_info, payment_privke
owner_address=owner_address,
transfer_address=name_data.get('transfer_address'),
config_path=config_path,
path=queue_path)
path=queue_path, **additionals)
resp['zonefile_hash'] = zonefile_hash
return resp

View File

@@ -317,7 +317,9 @@ def in_queue( queue_id, fqu, path=DEFAULT_QUEUE_PATH ):
def queue_append(queue_id, fqu, tx_hash, payment_address=None,
owner_address=None, transfer_address=None,
config_path=CONFIG_PATH, block_height=None,
zonefile_data=None, profile=None, zonefile_hash=None, path=DEFAULT_QUEUE_PATH):
zonefile_data=None, profile=None, zonefile_hash=None,
aggressive_registration = None, confirmations_needed = None,
path=DEFAULT_QUEUE_PATH):
"""
Append a processing name operation to the named queue for the given name.
@@ -340,6 +342,11 @@ def queue_append(queue_id, fqu, tx_hash, payment_address=None,
new_entry['owner_address'] = owner_address
new_entry['transfer_address'] = transfer_address
if aggressive_registration is not None:
new_entry['aggressive_registration'] = aggressive_registration
if confirmations_needed is not None:
new_entry['confirmations_needed'] = confirmations_needed
if zonefile_data is not None:
new_entry['zonefile_b64'] = base64.b64encode(zonefile_data)
@@ -380,7 +387,13 @@ def is_entry_accepted( entry, config_path=CONFIG_PATH ):
Return True if so.
Return False on error.
"""
return is_tx_accepted( entry['tx_hash'], config_path=config_path )
if 'confirmations_needed' in entry:
log.debug('Custom confirmations check on {} with {}'.format(
entry['tx_hash'], entry['confirmations_needed']))
return is_tx_accepted( entry['tx_hash'], num_needed = entry['confirmations_needed'],
config_path=config_path )
else:
return is_tx_accepted( entry['tx_hash'], config_path=config_path )
def is_preorder_expired( entry, config_path=CONFIG_PATH ):
@@ -447,7 +460,6 @@ def queue_findall( queue_id, limit=None, path=DEFAULT_QUEUE_PATH ):
"""
return get_queue_state( queue_id, limit=limit, path=path )
def queue_removeall( entries, path=DEFAULT_QUEUE_PATH ):
"""
Remove all given entries form their given queues

View File

@@ -56,6 +56,7 @@ from ..storage import put_mutable_data, get_zonefile_data_hash
from ..data import set_profile_timestamp
from ..constants import CONFIG_PATH, DEFAULT_QUEUE_PATH, BLOCKSTACK_DEBUG, BLOCKSTACK_TEST, TX_MIN_CONFIRMATIONS
from ..constants import PREORDER_CONFIRMATIONS
from ..config import get_config
from ..utils import url_to_host_port
from ..logger import get_logger
@@ -1136,7 +1137,7 @@ def get_wallet(config_path=None, proxy=None):
# RPC method: backend_preorder
def preorder(fqu, cost_satoshis, zonefile_data, profile, transfer_address, min_payment_confs, proxy=None, config_path=CONFIG_PATH):
def preorder(fqu, cost_satoshis, zonefile_data, profile, transfer_address, min_payment_confs, proxy=None, config_path=CONFIG_PATH, aggressive_registration = False):
"""
Send preorder transaction and enter it in queue.
Queue up additional state so we can update and transfer it as well.
@@ -1148,6 +1149,8 @@ def preorder(fqu, cost_satoshis, zonefile_data, profile, transfer_address, min_p
state, config_path, proxy = get_registrar_state(config_path=config_path, proxy=proxy)
data = {}
if aggressive_registration:
log.debug('Aggressive registration of {}'.format(fqu))
if min_payment_confs is None:
min_payment_confs = TX_MIN_CONFIRMATIONS
@@ -1174,7 +1177,11 @@ def preorder(fqu, cost_satoshis, zonefile_data, profile, transfer_address, min_p
'zonefile': zonefile_data,
'profile': profile,
}
if aggressive_registration:
name_data['confirmations_needed'] = PREORDER_CONFIRMATIONS
name_data['aggressive_registration'] = True
log.debug("async_preorder({}, zonefile_data={}, profile={}, transfer_address={})".format(fqu, zonefile_data, profile, transfer_address))
resp = async_preorder(fqu, payment_privkey_info, owner_privkey_info, cost_satoshis,
name_data=name_data, min_payment_confs=min_payment_confs,