mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
moved rollback_eleciton to planetmint
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
c3d5b7ef82
commit
7dec1b16ab
@ -265,5 +265,5 @@ def rollback(b):
|
|||||||
|
|
||||||
# NOTE: the pre-commit state is always at most 1 block ahead of the commited state
|
# NOTE: the pre-commit state is always at most 1 block ahead of the commited state
|
||||||
if latest_block["height"] < pre_commit["height"]:
|
if latest_block["height"] < pre_commit["height"]:
|
||||||
Election.rollback(b, pre_commit["height"], pre_commit["transactions"])
|
b.rollback_election(pre_commit["height"], pre_commit["transactions"])
|
||||||
b.delete_transactions(pre_commit["transactions"])
|
b.delete_transactions(pre_commit["transactions"])
|
||||||
|
|||||||
@ -931,4 +931,22 @@ class Planetmint(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def rollback_election(self, new_height, txn_ids): # TODO: move somewhere else
|
||||||
|
"""Looks for election and vote transactions inside the block and
|
||||||
|
cleans up the database artifacts possibly created in `process_blocks`.
|
||||||
|
|
||||||
|
Part of the `end_block`/`commit` crash recovery.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# delete election records for elections initiated at this height and
|
||||||
|
# elections concluded at this height
|
||||||
|
self.delete_elections(new_height)
|
||||||
|
|
||||||
|
txns = [self.get_transaction(tx_id) for tx_id in txn_ids]
|
||||||
|
|
||||||
|
elections = self._get_votes(txns)
|
||||||
|
for election_id in elections:
|
||||||
|
election = self.get_transaction(election_id)
|
||||||
|
election.on_rollback(self, new_height)
|
||||||
|
|
||||||
Block = namedtuple("Block", ("app_hash", "height", "transactions"))
|
Block = namedtuple("Block", ("app_hash", "height", "transactions"))
|
||||||
|
|||||||
@ -67,25 +67,6 @@ class Election(Transaction):
|
|||||||
if cls.TX_SCHEMA_CUSTOM:
|
if cls.TX_SCHEMA_CUSTOM:
|
||||||
_validate_schema(cls.TX_SCHEMA_CUSTOM, tx)
|
_validate_schema(cls.TX_SCHEMA_CUSTOM, tx)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def rollback(cls, planet, new_height, txn_ids): # TODO: move somewhere else
|
|
||||||
"""Looks for election and vote transactions inside the block and
|
|
||||||
cleans up the database artifacts possibly created in `process_blocks`.
|
|
||||||
|
|
||||||
Part of the `end_block`/`commit` crash recovery.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# delete election records for elections initiated at this height and
|
|
||||||
# elections concluded at this height
|
|
||||||
planet.delete_elections(new_height)
|
|
||||||
|
|
||||||
txns = [planet.get_transaction(tx_id) for tx_id in txn_ids]
|
|
||||||
|
|
||||||
elections = planet._get_votes(txns)
|
|
||||||
for election_id in elections:
|
|
||||||
election = planet.get_transaction(election_id)
|
|
||||||
election.on_rollback(planet, new_height)
|
|
||||||
|
|
||||||
def on_approval(self, planet, new_height):
|
def on_approval(self, planet, new_height):
|
||||||
"""Override to update the database state according to the
|
"""Override to update the database state according to the
|
||||||
election rules. Consider the current database state to account for
|
election rules. Consider the current database state to account for
|
||||||
|
|||||||
@ -15,7 +15,7 @@ from planetmint.backend.schema import TABLES, SPACE_NAMES
|
|||||||
from planetmint.transactions.common import crypto
|
from planetmint.transactions.common import crypto
|
||||||
from planetmint.transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
from planetmint.transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
||||||
from planetmint.transactions.types.assets.create import Create
|
from planetmint.transactions.types.assets.create import Create
|
||||||
from planetmint.transactions.types.elections.election import Election, Vote
|
from planetmint.transactions.types.elections.vote import Vote
|
||||||
from planetmint.transactions.types.elections.validator_utils import election_id_to_public_key
|
from planetmint.transactions.types.elections.validator_utils import election_id_to_public_key
|
||||||
from planetmint.tendermint_utils import key_to_base64
|
from planetmint.tendermint_utils import key_to_base64
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user