Predicate Validator
A general-purpose DHT validator that delegates all validation logic to a custom predicate.
This is a minimal validator that can enforce any condition on the entire DHTRecord, time conditions, etc. Useful for filtering keys, expiration time, value content, accessing the blockchain, or any combination thereof.
The predicate validator can enforce a maximum expiration time for all records, functioning similarly to pruning mechanisms in blockchains. Specifically, by default in the mock predicate validator, each peer heartbeat has a default maximum expiration of one epoch. This ensures that heartbeat records expire after one epoch period, requiring peers to submit fresh heartbeats in each subsequent epoch to maintain their active status.
Hypertensor Predicate Validator
Similar to the Predicate Validator, but instead the callable takes in the current epoch data as:
This is useful for having conditions based on time, such as for commit-reveal schemes that should be synced with the Hypertensor blockchain clock.
class HypertensorPredicateValidator(RecordValidatorBase):
def __init__(self, record_predicate: Callable[[DHTRecord, DHTRecordRequestType], bool]):
self.record_predicate = record_predicate
@classmethod
def from_predicate_class(
cls,
predicate_cls: type,
*args,
**kwargs
) -> "HypertensorPredicateValidator":
"""
Example:
HypertensorPredicateValidator.from_predicate_class(
HypertensorConsensusPredicate, hypertensor, subnet_id
)
"""
predicate = predicate_cls(*args, **kwargs)
return cls(record_predicate=predicate)
def validate(self, record: DHTRecord, type: DHTRecordRequestType) -> bool:
return self.record_predicate(record, type)
def sign_value(self, record: DHTRecord) -> bytes:
return record.value
def strip_value(self, record: DHTRecord) -> bytes:
return record.value
def merge_with(self, other: RecordValidatorBase) -> bool:
if not isinstance(other, HypertensorPredicateValidator):
return False
# Ignore another KeyValidator instance (it doesn't make sense to have several
# instances of this class) and report successful merge
return True
@property
def priority(self) -> int:
# Priority is less than SignatureValidator
return 9Usage
In the following example, the Hypertensor Predicate Validator is used for a commit-reveal schema and general conditions to ensure only specific keys can be stored, when keys can be stored (based on epoch progression, i.e., the percentage completion of an epoch), and how long they can be stored for (maximum expiration).
Heartbeat
Nodes make periodic updates to the database to show they are still running the node with a maximum expiration time, and can only be stored under the "node" key up to 100 stores per epoch.
Commit-Reveal Scheme
Each commit-reveal key is specified on the current epoch. A node cannot copy other nodes after the commit phase, nodes cannot submit data on previous or future epochs, and nodes can only commit and reveal in the specific phases of an epoch.
Note
To use this in production, a Pydantic validator should be used to ensure peers are storing the correct values.
If a node attempts to store data that doesn't abide by these conditions, it will not be stored.
Last updated