예제 #1
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})
예제 #2
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)
예제 #3
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)