Beispiel #1
0
def _update_validator_state(context, validator_id, anti_sybil_id,
                            validator_info):

    validator_map = _get_validator_map(context)
    updated_map = ValidatorMap()
    # Clean out old entries in ValidatorInfo and ValidatorMap
    # Protobuf doesn't offer delete item for ValidatorMap so create a new list
    # Use the validator map to find all occurrences of an anti_sybil_id
    # Use any such entry to find the associated validator id.
    # Use that validator id as the key to remove the ValidatorInfo from the
    # registry
    for entry in validator_map.entries:
        if anti_sybil_id == entry.key:
            validator_info_address = _get_address(entry.value)
            _delete_address(context, validator_info_address)
        else:
            updated_map.entries.add(key=entry.key, value=entry.value)

    # Add new state entries to ValidatorMap and ValidatorInfo
    updated_map.entries.add(key=anti_sybil_id, value=validator_id)
    validator_map_address = _get_address('validator_map')
    _set_data(context, validator_map_address, updated_map.SerializeToString())

    validator_info_address = _get_address(validator_id)
    _set_data(context, validator_info_address, validator_info)
    LOGGER.info("Validator id %s was added to the validator_map and set.",
                validator_id)
Beispiel #2
0
 def create_set_request_validator_map(self):
     address = self._key_to_address("validator_map")
     validator_map = ValidatorMap()
     validator_map.entries.add(key=self.public_key_hash,
                               value=self.public_key)
     data = validator_map.SerializeToString()
     return self._factory.create_set_request({address: data})
Beispiel #3
0
def _get_validator_state(state, validator_id=None):
    if validator_id is None:
        address = _get_address('validator_map')
        validator_state = ValidatorMap()
    else:
        validator_state = ValidatorInfo()
        address = _get_address(validator_id)
    try:
        entries_list = state.get([address], timeout=STATE_TIMEOUT_SEC)
    except FutureTimeoutError:
        LOGGER.warning('Timeout occured on state.get([%s])', address)
        raise InternalError('Unable to get {}'.format(address))

    if len(entries_list) != 0:
        validator_state.ParseFromString(entries_list[0].data)

    return validator_state
Beispiel #4
0
def test_create_set_request(benchmark):
    battleshipMessage = MessageFactory(
        "battleship", "1.0",
        MessageFactory.sha512("battleship".encode("utf-8"))[0:6], None)
    context = create_context("secp256k1")
    publicKey = battleshipMessage.get_public_key()
    address = battleshipMessage.namespaces[0] + MessageFactory.sha256(
        publicKey.encode("utf-8"))
    data = ValidatorMap().SerializeToString()
    benchmark(MessageFactory.create_set_request, battleshipMessage,
              {address: data})
    return
Beispiel #5
0
def _update_validator_state(state, validator_id, anti_sybil_id,
                            validator_info):

    validator_map = _get_validator_state(state)
    updated_map = ValidatorMap()
    # Clean out old entries in ValidatorInfo and ValidatorMap
    # Protobuf doesn't offer delete item for ValidatorMap so create a new list
    for entry in validator_map.entries:
        if anti_sybil_id == entry.key:
            address = _get_address(entry.value)
            _set_data(state, address, b'')
        else:
            updated_map.entries.add(key=entry.key, value=entry.value)

    # Add new state entries to ValidatorMap and ValidatorInfo
    updated_map.entries.add(key=anti_sybil_id, value=validator_id)
    address_map = _get_address('validator_map')
    _set_data(state, address_map, updated_map.SerializeToString())

    address = _get_address(validator_id)
    _set_data(state, address, validator_info)
    LOGGER.info("Validator id %s was added to the validator_map and set.",
                validator_id)
Beispiel #6
0
 def create_get_empty_response_validator_map(self):
     address = self._key_to_address("validator_map")
     data = ValidatorMap().SerializeToString()
     return self._factory.create_get_response({address: data})