mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
added raiing CriticialDoubleSpend Exception for governance and transactions
fixed search space issue with election / voting commit lookup Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
d8d9e2e75d
commit
c90e4fcc27
@ -14,6 +14,7 @@ from operator import itemgetter
|
||||
from planetmint.backend import query
|
||||
from planetmint.backend.models.dbtransaction import DbTransaction
|
||||
from planetmint.backend.exceptions import OperationDataInsertionError
|
||||
from planetmint.exceptions import CriticalDoubleSpend
|
||||
from planetmint.backend.tarantool.const import (
|
||||
TARANT_TABLE_META_DATA,
|
||||
TARANT_TABLE_ASSETS,
|
||||
@ -133,6 +134,9 @@ def store_transaction(connection, transaction):
|
||||
connection.run(connection.space(TARANT_TABLE_TRANSACTION).insert(tx), only_data=False)
|
||||
except Exception as e:
|
||||
logger.info(f"Could not insert transactions: {e}")
|
||||
if e.args[0] == 3 and e.args[1].startswith('Duplicate key exists in'):
|
||||
raise CriticalDoubleSpend()
|
||||
else:
|
||||
raise OperationDataInsertionError()
|
||||
|
||||
|
||||
@ -163,7 +167,9 @@ def store_governance_transaction(connection, transaction):
|
||||
try:
|
||||
connection.run(connection.space(TARANT_TABLE_GOVERNANCE).insert(tx), only_data=False)
|
||||
except Exception as e:
|
||||
logger.info(f"Could not insert governance transaction: {e}")
|
||||
if e.args[0] == 3 and e.args[1].startswith('Duplicate key exists in'):
|
||||
raise CriticalDoubleSpend()
|
||||
else:
|
||||
raise OperationDataInsertionError()
|
||||
|
||||
|
||||
|
||||
@ -245,8 +245,8 @@ class Planetmint(object):
|
||||
if unspent_outputs:
|
||||
return backend.query.delete_unspent_outputs(self.connection, *unspent_outputs)
|
||||
|
||||
def is_committed(self, transaction_id):
|
||||
transaction = backend.query.get_transaction_by_id(self.connection, transaction_id)
|
||||
def is_committed(self, transaction_id, table=TARANT_TABLE_TRANSACTION):
|
||||
transaction = backend.query.get_transaction_by_id(self.connection, transaction_id, table)
|
||||
return bool(transaction)
|
||||
|
||||
def get_transaction(self, transaction_id, table=TARANT_TABLE_TRANSACTION):
|
||||
@ -614,7 +614,7 @@ class Planetmint(object):
|
||||
"""
|
||||
|
||||
duplicates = any(txn for txn in current_transactions if txn.id == transaction.id)
|
||||
if self.is_committed(transaction.id) or duplicates:
|
||||
if self.is_committed(transaction.id, TARANT_TABLE_GOVERNANCE) or duplicates:
|
||||
raise DuplicateTransaction("transaction `{}` already exists".format(transaction.id))
|
||||
|
||||
current_validators = self.get_validators_dict()
|
||||
|
||||
@ -18,6 +18,7 @@ from transactions.types.assets.transfer import Transfer
|
||||
|
||||
|
||||
from planetmint.backend.models import Output
|
||||
from planetmint.exceptions import CriticalDoubleSpend
|
||||
|
||||
pytestmark = pytest.mark.bdb
|
||||
|
||||
@ -46,10 +47,9 @@ class TestBigchainApi(object):
|
||||
with pytest.raises(DoubleSpend):
|
||||
b.validate_transaction(transfer_tx2)
|
||||
|
||||
with pytest.raises(CriticalDoubleSpend):
|
||||
b.store_bulk_transactions([transfer_tx2])
|
||||
|
||||
with pytest.raises(CriticalDoubleSpend):
|
||||
b.get_spent(tx.id, 0)
|
||||
|
||||
def test_double_inclusion(self, b, alice):
|
||||
from tarantool.error import DatabaseError
|
||||
@ -62,7 +62,7 @@ class TestBigchainApi(object):
|
||||
|
||||
b.store_bulk_transactions([tx])
|
||||
if isinstance(b.connection, TarantoolDBConnection):
|
||||
with pytest.raises(DatabaseError):
|
||||
with pytest.raises(CriticalDoubleSpend):
|
||||
b.store_bulk_transactions([tx])
|
||||
else:
|
||||
with pytest.raises(OperationError):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user