mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
moved topology check to planetmint
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
a4a08c64ae
commit
20b9a08f7f
@ -670,7 +670,7 @@ class Planetmint(object):
|
|||||||
raise InvalidProposer("Public key is not a part of the validator set")
|
raise InvalidProposer("Public key is not a part of the validator set")
|
||||||
|
|
||||||
# NOTE: Check if all validators have been assigned votes equal to their voting power
|
# NOTE: Check if all validators have been assigned votes equal to their voting power
|
||||||
if not transaction.is_same_topology(current_validators, transaction.outputs):
|
if not self.is_same_topology(current_validators, transaction.outputs):
|
||||||
raise UnequalValidatorSet("Validator set much be exactly same to the outputs of election")
|
raise UnequalValidatorSet("Validator set much be exactly same to the outputs of election")
|
||||||
|
|
||||||
if transaction.operation == VALIDATOR_ELECTION:
|
if transaction.operation == VALIDATOR_ELECTION:
|
||||||
@ -778,4 +778,18 @@ class Planetmint(object):
|
|||||||
status += f"\nvalidators={json.dumps(validators, indent=4)}"
|
status += f"\nvalidators={json.dumps(validators, indent=4)}"
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
def is_same_topology(cls, current_topology, election_topology):
|
||||||
|
voters = {}
|
||||||
|
for voter in election_topology:
|
||||||
|
if len(voter.public_keys) > 1:
|
||||||
|
return False
|
||||||
|
|
||||||
|
[public_key] = voter.public_keys
|
||||||
|
voting_power = voter.amount
|
||||||
|
voters[public_key] = voting_power
|
||||||
|
|
||||||
|
# Check whether the voters and their votes is same to that of the
|
||||||
|
# validators and their voting power in the network
|
||||||
|
return current_topology == voters
|
||||||
|
|
||||||
Block = namedtuple("Block", ("app_hash", "height", "transactions"))
|
Block = namedtuple("Block", ("app_hash", "height", "transactions"))
|
||||||
|
|||||||
@ -34,21 +34,6 @@ class Election(Transaction):
|
|||||||
# Vote ratio to approve an election
|
# Vote ratio to approve an election
|
||||||
ELECTION_THRESHOLD = 2 / 3
|
ELECTION_THRESHOLD = 2 / 3
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def is_same_topology(cls, current_topology, election_topology): # TODO: move somewhere else
|
|
||||||
voters = {}
|
|
||||||
for voter in election_topology:
|
|
||||||
if len(voter.public_keys) > 1:
|
|
||||||
return False
|
|
||||||
|
|
||||||
[public_key] = voter.public_keys
|
|
||||||
voting_power = voter.amount
|
|
||||||
voters[public_key] = voting_power
|
|
||||||
|
|
||||||
# Check whether the voters and their votes is same to that of the
|
|
||||||
# validators and their voting power in the network
|
|
||||||
return current_topology == voters
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_election(self, tx_signers, recipients, asset, metadata):
|
def validate_election(self, tx_signers, recipients, asset, metadata):
|
||||||
if not isinstance(tx_signers, list):
|
if not isinstance(tx_signers, list):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user