From 775c2ea25ce11f72b55dd26c2039190ef6839b63 Mon Sep 17 00:00:00 2001 From: Robby Dermody Date: Tue, 2 Feb 2016 09:50:16 -0500 Subject: [PATCH 1/5] execute post install tasks when called via `pip` closes #833 pip is odd, hopefully this won't cause side effects. --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index db1bea0c9e..682b7d27c1 100644 --- a/setup.py +++ b/setup.py @@ -172,7 +172,9 @@ def _called_from_setup(run_frame): def run(self): # Explicit request for old-style install? Just do it if self.old_and_unmanageable or self.single_version_externally_managed: - return _install.run(self) + _install.run(self) + self.execute(post_install, (self, False), msg="Running post install tasks") + return if not self._called_from_setup(inspect.currentframe()): # Run in backward-compatibility mode to support bdist_* commands. From a0da5bb0507c57e28053825642c2814831d0dcf7 Mon Sep 17 00:00:00 2001 From: Adam Krellenstein Date: Sat, 5 Mar 2016 11:46:40 -0500 Subject: [PATCH 2/5] Whitespace --- counterpartylib/lib/blocks.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/counterpartylib/lib/blocks.py b/counterpartylib/lib/blocks.py index 47f3cfbc8f..414d2ed683 100644 --- a/counterpartylib/lib/blocks.py +++ b/counterpartylib/lib/blocks.py @@ -149,7 +149,7 @@ def parse_block(db, block_index, block_time, assert block_index == util.CURRENT_BLOCK_INDEX - # Remove undolog records for any block older than we should be tracking + # Remove undolog records for any block older than we should be tracking undolog_oldest_block_index = block_index - config.UNDOLOG_MAX_PAST_BLOCKS first_undo_index = list(undolog_cursor.execute('''SELECT first_undo_index FROM undolog_block WHERE block_index == ?''', (undolog_oldest_block_index,))) @@ -715,7 +715,7 @@ def reinitialise(db, block_index=None): if block_index: cursor.execute('''DELETE FROM transactions WHERE block_index > ?''', (block_index,)) cursor.execute('''DELETE FROM blocks WHERE block_index > ?''', (block_index,)) - + cursor.close() def reparse(db, block_index=None, quiet=False): @@ -723,7 +723,7 @@ def reparse(db, block_index=None, quiet=False): to the end of that block. """ def reparse_from_undolog(db, block_index, quiet): - """speedy reparse method that utilizes the undolog. + """speedy reparse method that utilizes the undolog. if fails, fallback to the full reparse method""" if not block_index: return False # Can't reparse from undolog @@ -746,7 +746,7 @@ def get_block_index_for_undo_index(undo_indexes, undo_index): undo_indexes = collections.OrderedDict() for result in results: undo_indexes[result[0]] = result[1] - + undo_start_block_index = block_index + 1 if undo_start_block_index not in undo_indexes: @@ -776,7 +776,7 @@ def get_block_index_for_undo_index(undo_indexes, undo_index): undolog_cursor.close() return True - + if block_index: logger.info('Rolling back transactions to block {}.'.format(block_index)) else: @@ -788,7 +788,7 @@ def get_block_index_for_undo_index(undo_indexes, undo_index): reparsed = reparse_from_undolog(db, block_index, quiet) cursor = db.cursor() - + if not reparsed: if block_index: logger.info("Could not roll back from undolog. Performing full reparse instead...") @@ -952,7 +952,7 @@ def kickstart(db, bitcoind_dir): tx_chunks = [transactions[i:i+90] for i in range(0, len(transactions), 90)] for tx_chunk in tx_chunks: sql = '''INSERT INTO transactions - (tx_index, tx_hash, block_index, block_hash, block_time, source, destination, btc_amount, fee, data) + (tx_index, tx_hash, block_index, block_hash, block_time, source, destination, btc_amount, fee, data) VALUES ''' bindings = () bindings_place = [] @@ -1047,7 +1047,7 @@ def follow(db): not_supported_sorted = collections.deque() # ^ Entries in form of (block_index, tx_hash), oldest first. Allows for easy removal of past, unncessary entries cursor = db.cursor() - + # a reorg can happen without the block count increasing, or even for that # matter, with the block count decreasing. This should only delay # processing of the new blocks a bit. @@ -1143,7 +1143,7 @@ def follow(db): for tx_hash in txhash_list: tx_hex = raw_transactions[tx_hash] tx_index = list_tx(db, block_hash, block_index, block_time, tx_hash, tx_index, tx_hex) - + # Parse the transactions in the block. new_ledger_hash, new_txlist_hash, new_messages_hash, found_messages_hash = parse_block(db, block_index, block_time) @@ -1161,7 +1161,7 @@ def follow(db): str(block_index), "{:.2f}".format(time.time() - start_time, 3), new_ledger_hash[-5:], new_txlist_hash[-5:], new_messages_hash[-5:], (' [overwrote %s]' % found_messages_hash) if found_messages_hash and found_messages_hash != new_messages_hash else '')) - + # Increment block index. block_count = backend.getblockcount() block_index += 1 @@ -1266,7 +1266,7 @@ def follow(db): tx_hash, new_message = message new_message['tx_hash'] = tx_hash cursor.execute('''INSERT INTO mempool VALUES(:tx_hash, :command, :category, :bindings, :timestamp)''', new_message) - + refresh_start_time = time.time() # let the backend refresh it's mempool stored data # Sometimes the transactions can’t be found: `{'code': -5, 'message': 'No information available about transaction'}` From 3ccaff7334ff687b966ae7859273c8bc5299eed5 Mon Sep 17 00:00:00 2001 From: Adam Krellenstein Date: Sat, 5 Mar 2016 14:28:17 -0500 Subject: [PATCH 3/5] HOTFIX: Max Free Fraction of 1; Invalid Broadcasts --- ChangeLog.md | 3 +++ counterpartylib/lib/config.py | 2 +- counterpartylib/lib/messages/broadcast.py | 8 ++++++++ counterpartylib/protocol_changes.json | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index c70c808211..18d82d42b0 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,4 +1,7 @@ ## Library Versions ## +* v9.54.0 (2016-03-05) + * Max fee fraction of 1 + * Don't handle bet matches for invalid broadcast. * v9.53.0 (2016-01-18) * Remove `messages` table from being covered by "undolog" functionality added in `v9.52.0`. * Add `min_message_index` to `get_blocks` API call. diff --git a/counterpartylib/lib/config.py b/counterpartylib/lib/config.py index 71a0d66894..64c349ca70 100644 --- a/counterpartylib/lib/config.py +++ b/counterpartylib/lib/config.py @@ -6,7 +6,7 @@ # Versions VERSION_MAJOR = 9 -VERSION_MINOR = 53 +VERSION_MINOR = 54 VERSION_REVISION = 0 VERSION_STRING = str(VERSION_MAJOR) + '.' + str(VERSION_MINOR) + '.' + str(VERSION_REVISION) diff --git a/counterpartylib/lib/messages/broadcast.py b/counterpartylib/lib/messages/broadcast.py index 007cdfe664..e345e6f41e 100644 --- a/counterpartylib/lib/messages/broadcast.py +++ b/counterpartylib/lib/messages/broadcast.py @@ -73,6 +73,10 @@ def validate (db, source, timestamp, value, fee_fraction_int, text, block_index) if fee_fraction_int > 4294967295: problems.append('fee fraction greater than 42.94967295') + if util.enabled('max_fee_fraction'): + if fee_fraction_int >= 1: + problems.append('fee fraction greater than or equal to 1') + if timestamp < 0: problems.append('negative timestamp') if not source: @@ -188,6 +192,10 @@ def parse (db, tx, message): ORDER BY tx1_index ASC, tx0_index ASC''', ('pending', tx['source'])) for bet_match in cursor.fetchall(): + if util.enabled('max_fee_fraction'): + if status != 'valid': + break + broadcast_bet_match_cursor = db.cursor() bet_match_id = util.make_id(bet_match['tx0_hash'], bet_match['tx1_hash']) bet_match_status = None diff --git a/counterpartylib/protocol_changes.json b/counterpartylib/protocol_changes.json index d2a9c64db7..76da994eeb 100644 --- a/counterpartylib/protocol_changes.json +++ b/counterpartylib/protocol_changes.json @@ -52,5 +52,11 @@ "minimum_version_minor": 51, "minimum_version_revision": 0, "block_index": 352000 + }, + "max_fee_fraction": { + "minimum_version_major": 9, + "minimum_version_minor": 54, + "minimum_version_revision": 0, + "block_index": 401278 } } From ab71bb25f4796604225cb0083e6d9afc165f9f29 Mon Sep 17 00:00:00 2001 From: ouziel-slama Date: Sat, 5 Mar 2016 21:11:33 +0100 Subject: [PATCH 4/5] Fix tests --- counterpartylib/lib/messages/broadcast.py | 8 ++++---- counterpartylib/test/fixtures/vectors.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/counterpartylib/lib/messages/broadcast.py b/counterpartylib/lib/messages/broadcast.py index e345e6f41e..1b7203f35d 100644 --- a/counterpartylib/lib/messages/broadcast.py +++ b/counterpartylib/lib/messages/broadcast.py @@ -70,12 +70,12 @@ def initialise(db): def validate (db, source, timestamp, value, fee_fraction_int, text, block_index): problems = [] - if fee_fraction_int > 4294967295: - problems.append('fee fraction greater than 42.94967295') - if util.enabled('max_fee_fraction'): - if fee_fraction_int >= 1: + if fee_fraction_int >= config.UNIT: problems.append('fee fraction greater than or equal to 1') + else: + if fee_fraction_int > 4294967295: + problems.append('fee fraction greater than 42.94967295') if timestamp < 0: problems.append('negative timestamp') diff --git a/counterpartylib/test/fixtures/vectors.py b/counterpartylib/test/fixtures/vectors.py index 818ef782b1..4905fc9cb7 100644 --- a/counterpartylib/test/fixtures/vectors.py +++ b/counterpartylib/test/fixtures/vectors.py @@ -386,7 +386,7 @@ 'out': (['locked feed']) }, { 'in': (ADDR[0], 1588000000, 1, 4294967296, 'Unit Test', DP['default_block']), - 'out': (['fee fraction greater than 42.94967295']) + 'out': (['fee fraction greater than or equal to 1']) }, { 'in': (ADDR[0], -1388000000, 1, DP['fee_multiplier'], 'Unit Test', DP['default_block']), 'out': (['negative timestamp', 'feed timestamps not monotonically increasing']) From f12c68e16666daa08d218a1300be7a09135b6ed4 Mon Sep 17 00:00:00 2001 From: ouziel-slama Date: Sat, 5 Mar 2016 23:55:29 +0100 Subject: [PATCH 5/5] Update `ChangeLog.md`; Fix `.gitignore` --- .gitignore | 2 +- ChangeLog.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ace5714f5f..b730dd1283 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ profile.txt *.pyc # files generated by py.test -test/fixtures/scenarios/*.new.* +/counterpartylib/test/fixtures/scenarios/*.new.* .coverage # Compiled python modules. diff --git a/ChangeLog.md b/ChangeLog.md index 18d82d42b0..0b71b417c6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,6 @@ ## Library Versions ## * v9.54.0 (2016-03-05) + * Execute post install tasks when called via `pip` * Max fee fraction of 1 * Don't handle bet matches for invalid broadcast. * v9.53.0 (2016-01-18)