mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
fixed rollback after crash
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
3187adb350
commit
ca0496555c
@ -33,4 +33,5 @@ RUN mkdir -p /usr/src/app
|
||||
COPY . /usr/src/app/
|
||||
WORKDIR /usr/src/app
|
||||
RUN pip install -e .[dev]
|
||||
RUN pip install flask-cors
|
||||
RUN pip install flask-cors
|
||||
RUN pip install planetmint-transactions@git+https://git@github.com/planetmint/transactions.git@cybnon/adapt-class-access-to-new-schema
|
||||
@ -116,7 +116,7 @@ class Output:
|
||||
@staticmethod
|
||||
def from_dict(output_dict: dict, index: int, transaction_id: str) -> Output:
|
||||
return Output(
|
||||
id="placeholder",
|
||||
id=output_dict["id"] if "id" in output_dict else "placeholder",
|
||||
amount=int(output_dict["amount"]),
|
||||
public_keys=output_dict["public_keys"],
|
||||
condition=Condition.from_dict(output_dict["condition"]),
|
||||
|
||||
@ -90,6 +90,12 @@ function init()
|
||||
{ field = 'assets[*].id', type = 'string', is_nullable = true }
|
||||
}
|
||||
})
|
||||
governance:create_index('spending_governance_by_id_and_output_index', {
|
||||
if_not_exists = true,
|
||||
parts = {
|
||||
{ field = 'inputs[*].fulfills["transaction_id"]', type = 'string', is_nullable = true },
|
||||
{ field = 'inputs[*].fulfills["output_index"]', type = 'unsigned', is_nullable = true }
|
||||
}})
|
||||
|
||||
-- Outputs
|
||||
outputs = box.schema.create_space('outputs', { if_not_exists = true })
|
||||
|
||||
@ -42,7 +42,9 @@ register_query = module_dispatch_registrar(query)
|
||||
def get_complete_transactions_by_ids(connection, txids: list, table=TARANT_TABLE_TRANSACTION) -> list[DbTransaction]:
|
||||
_transactions = []
|
||||
for txid in txids:
|
||||
tx = get_transaction_by_id(connection, txid, table)
|
||||
tx = get_transaction_by_id(connection, txid, TARANT_TABLE_TRANSACTION)
|
||||
if tx is None:
|
||||
tx = get_transaction_by_id(connection, txid, TARANT_TABLE_GOVERNANCE)
|
||||
if tx is None:
|
||||
continue
|
||||
outputs = get_outputs_by_tx_id(connection, txid)
|
||||
@ -354,6 +356,7 @@ def delete_transactions(connection, txn_ids: list):
|
||||
connection.connect().call("delete_output", (_outputs[x].id))
|
||||
for _id in txn_ids:
|
||||
connection.run(connection.space(TARANT_TABLE_TRANSACTION).delete(_id), only_data=False)
|
||||
connection.run(connection.space(TARANT_TABLE_GOVERNANCE).delete(_id), only_data=False)
|
||||
except Exception as e:
|
||||
logger.info(f"Could not insert unspent output: {e}")
|
||||
raise OperationDataInsertionError()
|
||||
@ -446,9 +449,9 @@ def store_validator_set(conn, validators_update: dict):
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
def delete_validator_set(connection, height: int):
|
||||
_validators = connection.run(connection.space("validators").select(height, index="height_search"))
|
||||
_validators = connection.run(connection.space("validator_sets").select(height, index="height"))
|
||||
for _valid in _validators:
|
||||
connection.run(connection.space("validators").delete(_valid[0]), only_data=False)
|
||||
connection.run(connection.space("validator_sets").delete(_valid[0]), only_data=False)
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
@ -548,7 +551,9 @@ def store_abci_chain(connection, height: int, chain_id: str, is_synced: bool = T
|
||||
@register_query(TarantoolDBConnection)
|
||||
def delete_abci_chain(connection, height: int):
|
||||
hash_id_primarykey = sha256(json.dumps(obj={"height": height}).encode()).hexdigest()
|
||||
connection.run(connection.space("abci_chains").delete(hash_id_primarykey), only_data=False)
|
||||
# connection.run(connection.space("abci_chains").delete(hash_id_primarykey), only_data=False)
|
||||
chains = connection.run(connection.space("abci_chains").select(height, index="height"), only_data=False)
|
||||
connection.run(connection.space("abci_chains").delete(chains[0][0], index="id"), only_data=False)
|
||||
|
||||
|
||||
@register_query(TarantoolDBConnection)
|
||||
|
||||
@ -899,6 +899,8 @@ class Planetmint(object):
|
||||
self.delete_elections(new_height)
|
||||
|
||||
txns = [self.get_transaction(tx_id) for tx_id in txn_ids]
|
||||
|
||||
txns = [Transaction.from_dict(tx.to_dict()) for tx in txns]
|
||||
|
||||
elections = self._get_votes(txns)
|
||||
for election_id in elections:
|
||||
|
||||
2
setup.py
2
setup.py
@ -130,7 +130,7 @@ install_requires = [
|
||||
"planetmint-ipld>=0.0.3",
|
||||
"pyasn1>=0.4.8",
|
||||
"python-decouple",
|
||||
"planetmint-transactions>=0.2.2",
|
||||
# "planetmint-transactions>=0.2.2",
|
||||
]
|
||||
|
||||
setup(
|
||||
|
||||
@ -22,6 +22,7 @@ from planetmint.lib import Block
|
||||
from planetmint.tendermint_utils import new_validator_set
|
||||
from planetmint.tendermint_utils import public_key_to_base64
|
||||
from planetmint.version import __tm_supported_versions__
|
||||
from planetmint.backend.tarantool.const import TARANT_TABLE_GOVERNANCE
|
||||
from tests.utils import generate_election, generate_validators
|
||||
|
||||
pytestmark = pytest.mark.bdb
|
||||
@ -410,7 +411,7 @@ def test_rollback_pre_commit_state_after_crash(b):
|
||||
rollback(b)
|
||||
|
||||
for tx in txs:
|
||||
assert b.get_transaction(tx.id)
|
||||
assert b.get_transaction(tx.id, TARANT_TABLE_GOVERNANCE)
|
||||
assert b.get_latest_abci_chain()
|
||||
assert len(b.get_validator_set()["validators"]) == 1
|
||||
assert b.get_election(migration_election.id)
|
||||
@ -421,7 +422,7 @@ def test_rollback_pre_commit_state_after_crash(b):
|
||||
rollback(b)
|
||||
|
||||
for tx in txs:
|
||||
assert not b.get_transaction(tx.id)
|
||||
assert not b.get_transaction(tx.id, TARANT_TABLE_GOVERNANCE)
|
||||
assert not b.get_latest_abci_chain()
|
||||
assert len(b.get_validator_set()["validators"]) == 4
|
||||
assert len(b.get_validator_set(2)["validators"]) == 4
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user