forked from Shyran-Systems/bigchaindb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: Node operator cannot vote on a ValidatorElection (bigchaindb…
…#2428) * Problem: Node operator cannot vote on a ValidatorElection Solution: Implement validator election voting spec * Problem: Incorrent code comments Solution: Update comments with correct context * Problem: Delegated vote not casted back to election Solution: Update test to cast votes back to election id and assert their validity
- Loading branch information
Showing
11 changed files
with
294 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
bigchaindb/common/schema/transaction_validator_election_vote_v2.0.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
"$schema": "http://json-schema.org/draft-04/schema#" | ||
type: object | ||
title: Validator Election Vote Schema - Vote on a validator set change | ||
required: | ||
- operation | ||
- outputs | ||
properties: | ||
operation: "VALIDATOR_ELECTION_VOTE" | ||
outputs: | ||
type: array | ||
items: | ||
"$ref": "#/definitions/output" | ||
definitions: | ||
output: | ||
type: object | ||
properties: | ||
condition: | ||
type: object | ||
required: | ||
- uri | ||
properties: | ||
uri: | ||
type: string | ||
pattern: "^ni:///sha-256;([a-zA-Z0-9_-]{0,86})[?]\ | ||
(fpt=ed25519-sha-256(&)?|cost=[0-9]+(&)?|\ | ||
subtypes=ed25519-sha-256(&)?){2,3}$" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
|
||
from bigchaindb.upsert_validator.validator_election import ValidatorElection # noqa | ||
from bigchaindb.upsert_validator.validator_election_vote import ValidatorElectionVote # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import base58 | ||
|
||
from bigchaindb.common.transaction import Transaction | ||
from bigchaindb.common.schema import (_validate_schema, | ||
TX_SCHEMA_COMMON, | ||
TX_SCHEMA_TRANSFER, | ||
TX_SCHEMA_VALIDATOR_ELECTION_VOTE) | ||
|
||
|
||
class ValidatorElectionVote(Transaction): | ||
|
||
VALIDATOR_ELECTION_VOTE = 'VALIDATOR_ELECTION_VOTE' | ||
# NOTE: This class inherits TRANSFER txn type. The `TRANSFER` property is | ||
# overriden to re-use methods from parent class | ||
TRANSFER = VALIDATOR_ELECTION_VOTE | ||
ALLOWED_OPERATIONS = (VALIDATOR_ELECTION_VOTE,) | ||
|
||
def validate(self, bigchain, current_transactions=[]): | ||
"""Validate election vote transaction | ||
NOTE: There are no additional validity conditions on casting votes i.e. | ||
a vote is just a valid TRANFER transaction | ||
For more details refer BEP-21: https://github.com/bigchaindb/BEPs/tree/master/21 | ||
Args: | ||
bigchain (BigchainDB): an instantiated bigchaindb.lib.BigchainDB object. | ||
Returns: | ||
`True` if the election vote is valid | ||
Raises: | ||
ValidationError: If the election vote is invalid | ||
""" | ||
self.validate_transfer_inputs(bigchain, current_transactions) | ||
return self | ||
|
||
@classmethod | ||
def to_public_key(cls, election_id): | ||
return base58.b58encode(bytes.fromhex(election_id)) | ||
|
||
@classmethod | ||
def generate(cls, inputs, recipients, election_id, metadata=None): | ||
(inputs, outputs) = cls.validate_transfer(inputs, recipients, election_id, metadata) | ||
election_vote = cls(cls.VALIDATOR_ELECTION_VOTE, {'id': election_id}, inputs, outputs, metadata) | ||
cls.validate_schema(election_vote.to_dict(), skip_id=True) | ||
return election_vote | ||
|
||
@classmethod | ||
def validate_schema(cls, tx, skip_id=False): | ||
"""Validate the validator election vote transaction. Since `VALIDATOR_ELECTION_VOTE` extends `TRANFER` | ||
transaction, all the validations for `CREATE` transaction should be inherited | ||
""" | ||
if not skip_id: | ||
cls.validate_id(tx) | ||
_validate_schema(TX_SCHEMA_COMMON, tx) | ||
_validate_schema(TX_SCHEMA_TRANSFER, tx) | ||
_validate_schema(TX_SCHEMA_VALIDATOR_ELECTION_VOTE, tx) | ||
|
||
@classmethod | ||
def create(cls, tx_signers, recipients, metadata=None, asset=None): | ||
raise NotImplementedError | ||
|
||
@classmethod | ||
def transfer(cls, tx_signers, recipients, metadata=None, asset=None): | ||
raise NotImplementedError |
Oops, something went wrong.