Exemplo n.º 1
0
def run_election_new_upsert_validator(args, bigchain):
    """Initiates an election to add/update/remove a validator to an existing BigchainDB network

    :param args: dict
        args = {
        'public_key': the public key of the proposed peer, (str)
        'power': the proposed validator power for the new peer, (str)
        'node_id': the node_id of the new peer (str)
        'sk': the path to the private key of the node calling the election (str)
        }
    :param bigchain: an instance of BigchainDB
    :return: election_id or `False` in case of failure
    """

    new_validator = {
        'public_key': {
            'value': public_key_from_base64(args.public_key),
            'type': 'ed25519-base16'
        },
        'power': args.power,
        'node_id': args.node_id
    }

    return create_new_election(args.sk, bigchain, ValidatorElection,
                               new_validator)
Exemplo n.º 2
0
def test_public_key_encoding_decoding():
    from bigchaindb.tendermint_utils import (public_key_from_base64,
                                             public_key_to_base64)

    public_key = public_key_from_base64(SAMPLE_PUBLIC_KEY['pub_key']['value'])
    base64_public_key = public_key_to_base64(public_key)

    assert base64_public_key == SAMPLE_PUBLIC_KEY['pub_key']['value']
Exemplo n.º 3
0
def test_public_key_encoding_decoding():
    from bigchaindb.tendermint_utils import (public_key_from_base64,
                                             public_key_to_base64)

    public_key = public_key_from_base64(SAMPLE_PUBLIC_KEY['pub_key']['value'])
    base64_public_key = public_key_to_base64(public_key)

    assert base64_public_key == SAMPLE_PUBLIC_KEY['pub_key']['value']
Exemplo n.º 4
0
def run_upsert_validator_new(args, bigchain):
    """Initiates an election to add/update/remove a validator to an existing BigchainDB network

    :param args: dict
        args = {
        'public_key': the public key of the proposed peer, (str)
        'power': the proposed validator power for the new peer, (str)
        'node_id': the node_id of the new peer (str)
        'sk': the path to the private key of the node calling the election (str)
        }
    :param bigchain: an instance of BigchainDB
    :return: election_id or `False` in case of failure
    """

    new_validator = {
        'public_key': {
            'value': public_key_from_base64(args.public_key),
            'type': 'ed25519-base16'
        },
        'power': args.power,
        'node_id': args.node_id
    }

    try:
        key = load_node_key(args.sk)
        voters = ValidatorElection.recipients(bigchain)
        election = ValidatorElection.generate([key.public_key], voters,
                                              new_validator,
                                              None).sign([key.private_key])
        election.validate(bigchain)
    except ValidationError as e:
        logger.error(e)
        return False
    except FileNotFoundError as fd_404:
        logger.error(fd_404)
        return False

    resp = bigchain.write_transaction(election, 'broadcast_tx_commit')
    if resp == (202, ''):
        logger.info('[SUCCESS] Submitted proposal with id: {}'.format(
            election.id))
        return election.id
    else:
        logger.error('Failed to commit election proposal')
        return False
Exemplo n.º 5
0
def run_election_new_upsert_validator(args, bigchain):
    """Initiates an election to add/update/remove a validator to an existing BigchainDB network

    :param args: dict
        args = {
        'public_key': the public key of the proposed peer, (str)
        'power': the proposed validator power for the new peer, (str)
        'node_id': the node_id of the new peer (str)
        'sk': the path to the private key of the node calling the election (str)
        }
    :param bigchain: an instance of BigchainDB
    :return: election_id or `False` in case of failure
    """

    new_validator = {
        'public_key': {'value': public_key_from_base64(args.public_key),
                       'type': 'ed25519-base16'},
        'power': args.power,
        'node_id': args.node_id
    }

    try:
        key = load_node_key(args.sk)
        voters = ValidatorElection.recipients(bigchain)
        election = ValidatorElection.generate([key.public_key],
                                              voters,
                                              new_validator, None).sign([key.private_key])
        election.validate(bigchain)
    except ValidationError as e:
        logger.error(e)
        return False
    except FileNotFoundError as fd_404:
        logger.error(fd_404)
        return False

    resp = bigchain.write_transaction(election, 'broadcast_tx_commit')
    if resp == (202, ''):
        logger.info('[SUCCESS] Submitted proposal with id: {}'.format(election.id))
        return election.id
    else:
        logger.error('Failed to commit election proposal')
        return False
Exemplo n.º 6
0
def run_upsert_validator(args):
    """Store validators which should be synced with Tendermint"""

    b = bigchaindb.BigchainDB()
    public_key = public_key_from_base64(args.public_key)
    validator = {
        'pub_key': {
            'type': 'ed25519',
            'data': public_key
        },
        'power': args.power
    }
    validator_update = {
        'validator': validator,
        'update_id': VALIDATOR_UPDATE_ID
    }
    try:
        query.store_validator_update(b.connection, validator_update)
    except MultipleValidatorOperationError:
        logger.error('A validator update is pending to be applied. '
                     'Please re-try after the current update has '
                     'been processed.')
Exemplo n.º 7
0
def run_election_new_upsert_validator(args, bigchain):
    """Initiates an election to add/update/remove a validator to an existing BigchainDB network

    :param args: dict
        args = {
        'public_key': the public key of the proposed peer, (str)
        'power': the proposed validator power for the new peer, (str)
        'node_id': the node_id of the new peer (str)
        'sk': the path to the private key of the node calling the election (str)
        }
    :param bigchain: an instance of BigchainDB
    :return: election_id or `False` in case of failure
    """

    new_validator = {
        'public_key': {'value': public_key_from_base64(args.public_key),
                       'type': 'ed25519-base16'},
        'power': args.power,
        'node_id': args.node_id
    }

    return create_new_election(args.sk, bigchain, ValidatorElection, new_validator)