mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: We need to store the election_id as part of the validator_update so we can efficiently check which election was resposible for the change
Solution: Added the parameter to `store_validator_set` and aligned the tests
This commit is contained in:
parent
7a0b474d11
commit
4c64b6c52c
@ -54,7 +54,7 @@ class App(BaseApplication):
|
||||
validator_set = [vutils.decode_validator(v) for v in genesis.validators]
|
||||
block = Block(app_hash='', height=0, transactions=[])
|
||||
self.bigchaindb.store_block(block._asdict())
|
||||
self.bigchaindb.store_validator_set(1, validator_set)
|
||||
self.bigchaindb.store_validator_set(1, validator_set, '')
|
||||
return ResponseInitChain()
|
||||
|
||||
def info(self, request):
|
||||
|
||||
@ -432,13 +432,14 @@ 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):
|
||||
def store_validator_set(self, height, validators, election_id):
|
||||
"""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})
|
||||
'validators': validators,
|
||||
'election_id': election_id})
|
||||
|
||||
|
||||
Block = namedtuple('Block', ('app_hash', 'height', 'transactions'))
|
||||
|
||||
@ -227,7 +227,7 @@ class ValidatorElection(Transaction):
|
||||
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)
|
||||
bigchain.store_validator_set(new_height+1, updated_validator_set, election.id)
|
||||
return [encode_validator(election.asset['data'])]
|
||||
return []
|
||||
|
||||
|
||||
@ -237,7 +237,7 @@ def test_new_validator_set(b):
|
||||
|
||||
validators = [node1]
|
||||
updates = [node1_new_power, node2]
|
||||
b.store_validator_set(1, validators)
|
||||
b.store_validator_set(1, validators, 'election_id')
|
||||
updated_validator_set = new_validator_set(b.get_validators(1), updates)
|
||||
|
||||
updated_validators = []
|
||||
|
||||
@ -71,7 +71,8 @@ def inconclusive_election(b, concluded_election, new_validator):
|
||||
validators = b.get_validators(height=1)
|
||||
validators[0]['voting_power'] = 15
|
||||
validator_update = {'validators': validators,
|
||||
'height': 3}
|
||||
'height': 3,
|
||||
'election_id': 'some_other_election'}
|
||||
|
||||
query.store_validator_set(b.connection, validator_update)
|
||||
return concluded_election
|
||||
|
||||
@ -368,4 +368,4 @@ def reset_validator_set(b, node_keys, height):
|
||||
validators.append({'pub_key': {'type': 'ed25519',
|
||||
'data': node_pub},
|
||||
'voting_power': 10})
|
||||
b.store_validator_set(height, validators)
|
||||
b.store_validator_set(height, validators, 'election_id')
|
||||
|
||||
@ -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)
|
||||
b.store_validator_set(23, validator_set, 'election_id')
|
||||
|
||||
res = client.get(VALIDATORS_ENDPOINT)
|
||||
assert is_validator(res.json[0])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user