moved topology check to planetmint

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2022-09-29 16:50:54 +02:00
parent a4a08c64ae
commit 20b9a08f7f
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
2 changed files with 15 additions and 16 deletions

View File

@ -670,7 +670,7 @@ class Planetmint(object):
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
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")
if transaction.operation == VALIDATOR_ELECTION:
@ -778,4 +778,18 @@ class Planetmint(object):
status += f"\nvalidators={json.dumps(validators, indent=4)}"
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"))

View File

@ -34,21 +34,6 @@ class Election(Transaction):
# Vote ratio to approve an election
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
def validate_election(self, tx_signers, recipients, asset, metadata):
if not isinstance(tx_signers, list):