From 06ea94070773d533693060aaab4df520cf8db016 Mon Sep 17 00:00:00 2001 From: z-bowen Date: Mon, 10 Sep 2018 10:47:40 +0200 Subject: [PATCH] Problem: `Election.validate` uses an inefficient query to check that the tx is in the db Solution: use `is_committed` instead of `get_transaction` --- bigchaindb/elections/election.py | 2 +- tests/upsert_validator/test_upsert_validator_vote.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bigchaindb/elections/election.py b/bigchaindb/elections/election.py index f2856274..4587bf5e 100644 --- a/bigchaindb/elections/election.py +++ b/bigchaindb/elections/election.py @@ -106,7 +106,7 @@ class Election(Transaction): input_conditions = [] duplicates = any(txn for txn in current_transactions if txn.id == self.id) - if bigchain.get_transaction(self.id) or duplicates: + if bigchain.is_committed(self.id) or duplicates: raise DuplicateTransaction('transaction `{}` already exists' .format(self.id)) diff --git a/tests/upsert_validator/test_upsert_validator_vote.py b/tests/upsert_validator/test_upsert_validator_vote.py index cf05e780..39480903 100644 --- a/tests/upsert_validator/test_upsert_validator_vote.py +++ b/tests/upsert_validator/test_upsert_validator_vote.py @@ -303,18 +303,15 @@ def test_get_validator_update(b, node_keys, node_key, ed25519_node_keys): assert not ValidatorElection.approved_update(b, 4, [tx_vote0, tx_vote1]) update = ValidatorElection.approved_update(b, 4, [tx_vote0, tx_vote1, tx_vote2]) - update_public_key = None - if update: - update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n') assert update + update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n') assert update_public_key == public_key64 b.store_bulk_transactions([tx_vote0, tx_vote1]) update = ValidatorElection.approved_update(b, 4, [tx_vote2]) - if update: - update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n') assert update + update_public_key = codecs.encode(update.pub_key.data, 'base64').decode().rstrip('\n') assert update_public_key == public_key64 # remove validator