From 52caaa6fc883a1e84aaa27bf4f440f1cea0fa68a Mon Sep 17 00:00:00 2001 From: z-bowen Date: Fri, 7 Sep 2018 15:29:26 +0200 Subject: [PATCH] Problem: Decided to no longer include the `election_id` when storing a `validator_set` Solution: Removed the code to store the `election_id` and aligned the tests --- bigchaindb/core.py | 2 +- bigchaindb/lib.py | 5 ++--- bigchaindb/upsert_validator/validator_election.py | 2 +- tests/tendermint/test_core.py | 2 +- tests/upsert_validator/test_upsert_validator_vote.py | 4 ++-- tests/web/test_validators.py | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 83212b67..62bc6ec3 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -100,7 +100,7 @@ class App(BaseApplication): block = Block(app_hash=app_hash, height=height, transactions=[]) self.bigchaindb.store_block(block._asdict()) - self.bigchaindb.store_validator_set(height + 1, validator_set, None) + self.bigchaindb.store_validator_set(height + 1, validator_set) abci_chain_height = 0 if known_chain is None else known_chain['height'] self.bigchaindb.store_abci_chain(abci_chain_height, genesis.chain_id, True) diff --git a/bigchaindb/lib.py b/bigchaindb/lib.py index 1015e88e..f6761aa6 100644 --- a/bigchaindb/lib.py +++ b/bigchaindb/lib.py @@ -435,14 +435,13 @@ class BigchainDB(object): def store_pre_commit_state(self, state): return backend.query.store_pre_commit_state(self.connection, state) - def store_validator_set(self, height, validators, election_id): + def store_validator_set(self, height, validators): """Store validator set at a given `height`. NOTE: If the validator set already exists at that `height` then an exception will be raised. """ return backend.query.store_validator_set(self.connection, {'height': height, - 'validators': validators, - 'election_id': election_id}) + 'validators': validators}) def store_abci_chain(self, height, chain_id, is_synced=True): return backend.query.store_abci_chain(self.connection, height, diff --git a/bigchaindb/upsert_validator/validator_election.py b/bigchaindb/upsert_validator/validator_election.py index 8834abc4..7cb10fae 100644 --- a/bigchaindb/upsert_validator/validator_election.py +++ b/bigchaindb/upsert_validator/validator_election.py @@ -45,5 +45,5 @@ class ValidatorElection(Election): validator_updates) updated_validator_set = [v for v in updated_validator_set if v['voting_power'] > 0] - bigchain.store_validator_set(new_height+1, updated_validator_set, election.id) + bigchain.store_validator_set(new_height+1, updated_validator_set) return encode_validator(election.asset['data']) diff --git a/tests/tendermint/test_core.py b/tests/tendermint/test_core.py index 2b246fa8..75588c51 100644 --- a/tests/tendermint/test_core.py +++ b/tests/tendermint/test_core.py @@ -427,7 +427,7 @@ def test_new_validator_set(b): validators = [node1] updates = [node1_new_power, node2] - b.store_validator_set(1, validators, 'election_id') + b.store_validator_set(1, validators) updated_validator_set = new_validator_set(b.get_validators(1), updates) updated_validators = [] diff --git a/tests/upsert_validator/test_upsert_validator_vote.py b/tests/upsert_validator/test_upsert_validator_vote.py index f20b2be1..cf05e780 100644 --- a/tests/upsert_validator/test_upsert_validator_vote.py +++ b/tests/upsert_validator/test_upsert_validator_vote.py @@ -234,7 +234,7 @@ def test_upsert_validator(b, node_key, node_keys, ed25519_node_keys): latest_block = b.get_latest_block() # reset the validator set - b.store_validator_set(latest_block['height'], validators, 'previous_election_id') + b.store_validator_set(latest_block['height'], validators) power = 1 public_key = '9B3119650DF82B9A5D8A12E38953EA47475C09F0C48A4E6A0ECE182944B24403' @@ -372,4 +372,4 @@ def reset_validator_set(b, node_keys, height): validators.append({'public_key': {'type': 'ed25519-base64', 'value': node_pub}, 'voting_power': 10}) - b.store_validator_set(height, validators, 'election_id') + b.store_validator_set(height, validators) diff --git a/tests/web/test_validators.py b/tests/web/test_validators.py index 52420828..714ceee4 100644 --- a/tests/web/test_validators.py +++ b/tests/web/test_validators.py @@ -14,7 +14,7 @@ def test_get_validators_endpoint(b, client): 'pub_key': {'data': '4E2685D9016126864733225BE00F005515200727FBAB1312FC78C8B76831255A', 'type': 'ed25519'}, 'voting_power': 10}] - b.store_validator_set(23, validator_set, 'election_id') + b.store_validator_set(23, validator_set) res = client.get(VALIDATORS_ENDPOINT) assert is_validator(res.json[0])