Skip to content

Commit

Permalink
Merge pull request #769 from CounterpartyXCP/develop
Browse files Browse the repository at this point in the history
v9.51.2
  • Loading branch information
Ouziel Slama committed Apr 23, 2015
2 parents 13fadf7 + 182c63a commit 35a827c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## Client Versions ##
* v9.51.2 (2015-04-23)
* miscellaneous bug fixes
* dramatically reduced default batch size (from 5000 to 20)
* renamed repository to `counterparty-lib`
* v9.51.1 (2015-04-20)
* rename `server.api.log` to `server.access.log`
* add `requests_timeout` parameter
Expand Down
18 changes: 12 additions & 6 deletions counterpartylib/lib/backend/addrindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def getrawtransaction_batch(txhash_list, verbose=False):
tx_hash_call_id = {}
call_id = 0
payload = []
# payload for transactions not in cache
for tx_hash in txhash_list:
if tx_hash not in RAW_TRANSACTIONS_CACHE:
payload.append({
Expand All @@ -180,28 +181,33 @@ def getrawtransaction_batch(txhash_list, verbose=False):
tx_hash_call_id[call_id] = tx_hash
call_id += 1

# populate cache
if len(payload) > 0:
batch_responses = rpc_batch(payload)
for response in batch_responses:
if 'error' not in response or response['error'] is None:
tx_hex = response['result']
tx_hash = tx_hash_call_id[response['id']]
RAW_TRANSACTIONS_CACHE[tx_hash] = tx_hex
RAW_TRANSACTIONS_CACHE_KEYS.append(tx_hash)
while len(RAW_TRANSACTIONS_CACHE_KEYS) > RAW_TRANSACTIONS_CACHE_SIZE:
first_hash = RAW_TRANSACTIONS_CACHE_KEYS[0]
del(RAW_TRANSACTIONS_CACHE[first_hash])
RAW_TRANSACTIONS_CACHE_KEYS.pop(0)
if tx_hash not in RAW_TRANSACTIONS_CACHE:
RAW_TRANSACTIONS_CACHE[tx_hash] = tx_hex
RAW_TRANSACTIONS_CACHE_KEYS.append(tx_hash)
else:
raise BackendRPCError('{}'.format(response['error']))

# get transactions from cache
result = {}
for tx_hash in txhash_list:
if verbose:
result[tx_hash] = RAW_TRANSACTIONS_CACHE[tx_hash]
else:
result[tx_hash] = RAW_TRANSACTIONS_CACHE[tx_hash]['hex']

# remove oldest hashes from cache
while len(RAW_TRANSACTIONS_CACHE_KEYS) > RAW_TRANSACTIONS_CACHE_SIZE:
first_hash = RAW_TRANSACTIONS_CACHE_KEYS[0]
del(RAW_TRANSACTIONS_CACHE[first_hash])
RAW_TRANSACTIONS_CACHE_KEYS.pop(0)

return result

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
20 changes: 13 additions & 7 deletions counterpartylib/lib/backend/btcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def searchrawtransactions(address, unconfirmed=False):
logger.debug('Searching raw transactions.')

try:
rawtransactions = rpc('searchrawtransactions', [address, True, 0, 9999999])
rawtransactions = rpc('searchrawtransactions', [address, 1, 0, 9999999])
except BackendRPCError as e:
raise BackendRPCError(str(e))

Expand Down Expand Up @@ -120,6 +120,7 @@ def getrawtransaction_batch(txhash_list, verbose=False):
tx_hash_call_id = {}
call_id = 0
payload = []
# payload for transactions not in cache
for tx_hash in txhash_list:
if tx_hash not in RAW_TRANSACTIONS_CACHE:
payload.append({
Expand All @@ -131,24 +132,29 @@ def getrawtransaction_batch(txhash_list, verbose=False):
tx_hash_call_id[call_id] = tx_hash
call_id += 1

# populate cache
if len(payload) > 0:
batch_responses = rpc_batch(payload)
for tx_hex in batch_responses:
tx_hash = tx_hex['txid']
RAW_TRANSACTIONS_CACHE[tx_hash] = tx_hex
RAW_TRANSACTIONS_CACHE_KEYS.append(tx_hash)
while len(RAW_TRANSACTIONS_CACHE_KEYS) > RAW_TRANSACTIONS_CACHE_SIZE:
first_hash = RAW_TRANSACTIONS_CACHE_KEYS[0]
del(RAW_TRANSACTIONS_CACHE[first_hash])
RAW_TRANSACTIONS_CACHE_KEYS.pop(0)
if tx_hash not in RAW_TRANSACTIONS_CACHE:
RAW_TRANSACTIONS_CACHE[tx_hash] = tx_hex
RAW_TRANSACTIONS_CACHE_KEYS.append(tx_hash)

# get transactions from cache
result = {}
for tx_hash in txhash_list:
if verbose:
result[tx_hash] = RAW_TRANSACTIONS_CACHE[tx_hash]
else:
result[tx_hash] = RAW_TRANSACTIONS_CACHE[tx_hash]['hex']

# remove oldest hashes from cache
while len(RAW_TRANSACTIONS_CACHE_KEYS) > RAW_TRANSACTIONS_CACHE_SIZE:
first_hash = RAW_TRANSACTIONS_CACHE_KEYS[0]
del(RAW_TRANSACTIONS_CACHE[first_hash])
RAW_TRANSACTIONS_CACHE_KEYS.pop(0)

return result

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
4 changes: 2 additions & 2 deletions counterpartylib/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Versions
VERSION_MAJOR = 9
VERSION_MINOR = 51
VERSION_REVISION = 1
VERSION_REVISION = 2
VERSION_STRING = str(VERSION_MAJOR) + '.' + str(VERSION_MINOR) + '.' + str(VERSION_REVISION)


Expand Down Expand Up @@ -90,7 +90,7 @@


DEFAULT_REQUESTS_TIMEOUT = 20 # 20 seconds
DEFAULT_RPC_BATCH_SIZE = 5000 # A 1 MB block can hold about 4200 transactions.
DEFAULT_RPC_BATCH_SIZE = 20 # A 1 MB block can hold about 4200 transactions.

# Custom exit codes
EXITCODE_UPDATE_REQUIRED = 5
Expand Down

0 comments on commit 35a827c

Please sign in to comment.