better logging and arrangement for vote verification

This commit is contained in:
Scott Sadler 2016-11-25 11:26:04 +01:00
parent c43bf10151
commit ef5f3ddd28

View File

@ -1,5 +1,11 @@
import logging
from bigchaindb.util import verify_vote_signature from bigchaindb.util import verify_vote_signature
from bigchaindb.common.schema import validate_vote_schema, SchemaValidationError from bigchaindb.common.schema import SchemaValidationError, \
validate_vote_schema
logger = logging.getLogger(__name__)
class BaseConsensusRules(): class BaseConsensusRules():
@ -26,10 +32,12 @@ class BaseConsensusRules():
Refer to the documentation of Refer to the documentation of
:func:`bigchaindb.util.verify_signature`. :func:`bigchaindb.util.verify_signature`.
""" """
try: if verify_vote_signature(voters, signed_vote):
validate_vote_schema(signed_vote) try:
except SchemaValidationError: validate_vote_schema(signed_vote)
# TODO: log this. return True
return False except SchemaValidationError as exc:
else: logger.warning(exc)
return verify_vote_signature(voters, signed_vote) logger.warning("Vote failed signature verification: "
"%s with voters: %s", signed_vote, voters)
return False