fixed pre_commiT-state bug

This commit is contained in:
andrei 2022-04-25 16:22:59 +03:00
parent 148a188f8f
commit af34e25c1b
3 changed files with 5 additions and 13 deletions

View File

@ -367,8 +367,6 @@ def delete_transactions(connection, txn_ids: list):
@register_query(TarantoolDB)
def store_pre_commit_state(connection, state: dict):
space = connection.space("pre_commits")
if not space:
return {}
_precommit = space.select(state["height"], index="height_search", limit=1)
unique_id = token_hex(8) if (len(_precommit.data) == 0) else _precommit.data[0][0]
space.upsert((unique_id, state["height"], state["transactions"]),
@ -380,15 +378,10 @@ def store_pre_commit_state(connection, state: dict):
@register_query(TarantoolDB)
def get_pre_commit_state(connection):
try:
space = connection.space("pre_commits")
_commit = space.select([], index="id_search", limit=1).data
if len(_commit) == 0:
return {}
_commit = _commit[0]
_commit = space.select([], index="id_search").data
_commit = sorted(_commit, key=itemgetter(1), reverse=True)[0]
return {"height": _commit[1], "transactions": _commit[2]}
except:
return {}
@register_query(TarantoolDB)

View File

@ -458,7 +458,6 @@ class Planetmint(object):
return backend.query.get_election(self.connection, election_id)
def get_pre_commit_state(self):
print(f"CONNECTION {self.connection} !!!!!")
return backend.query.get_pre_commit_state(self.connection)
def store_pre_commit_state(self, state):

View File

@ -465,7 +465,7 @@ def test_validator_update(db_conn):
for i in range(1, 100, 10):
value = gen_validator_update(i)
query.store_validator_set(connection=conn, validators_update=value)
query.store_validator_set(conn=conn, validators_update=value)
v1 = query.get_validator_set(connection=conn, height=8)
assert v1['height'] == 1