class NewView(MessageBase): typename = NEW_VIEW schema = ( (f.VIEW_NO.nm, NonNegativeNumberField()), (f.VIEW_CHANGES.nm, IterableField(ViewChangeField())), # list of tuples (node_name, view_change_digest) (f.CHECKPOINT.nm, AnyField()), # Checkpoint to be selected as stable (TODO: or tuple?) (f.BATCHES.nm, IterableField(BatchIDField())) # list of tuples (view_no, pp_view_no, pp_seq_no, pp_digest) # that should get into new view ) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if isinstance(self.checkpoint, dict): self.checkpoint = Checkpoint(**self.checkpoint) # The field `batches` can to be a list of BatchIDs or of dicts. # If it's not a list of dicts then we don't need to deserialize it. if not self.batches or not isinstance(self.batches[0], dict): return self.batches = [BatchID(**bid) for bid in self.batches if isinstance(bid, dict)] def _asdict(self): result = super()._asdict() chk = self.checkpoint if not isinstance(chk, dict): result[f.CHECKPOINT.nm] = chk._asdict() # The field `batches` can to be a list of BatchIDs or of dicts. # If its a list of dicts then we don't need to serialize it. if not self.batches or not isinstance(self.batches[0], BatchID): return result result[f.BATCHES.nm] = [bid._asdict() for bid in self.batches] return result
def test_min_max_checks(): validator = IterableField(NonNegativeNumberField(), min_length=3, max_length=10) assert validator.validate(list(range(2))) for i in range(3, 11): assert not validator.validate(list(range(i))) assert validator.validate(list(range(12)))
class ViewChange(MessageBase): typename = VIEW_CHANGE schema = ( (f.VIEW_NO.nm, NonNegativeNumberField()), (f.STABLE_CHECKPOINT.nm, NonNegativeNumberField()), (f.PREPARED.nm, IterableField(AnyField())), # list of PrePrepare (f.PREPREPARED.nm, IterableField(AnyField())), # list of PrePrepare (f.CHECKPOINTS.nm, IterableField(AnyField())) # list of Checkpoint )
class NewView(MessageBase): typename = NEW_VIEW schema = ( (f.VIEW_NO.nm, NonNegativeNumberField()), (f.VIEW_CHANGES.nm, IterableField(ViewChangeField())), # list of tuples (node_name, view_change_digest) (f.CHECKPOINT.nm, AnyField()), # Checkpoint to be selected as stable (TODO: or tuple?) (f.BATCHES.nm, IterableField(BatchIDField())) # list of tuples (view_no, pp_seq_no, pp_digest) # that should get into new view )
class ViewChange(MessageBase): typename = VIEW_CHANGE schema = ( (f.VIEW_NO.nm, NonNegativeNumberField()), (f.STABLE_CHECKPOINT.nm, NonNegativeNumberField()), (f.PREPARED.nm, IterableField(BatchIDField())), # list of tuples (view_no, pp_seq_no, pp_digest) (f.PREPREPARED.nm, IterableField(BatchIDField())), # list of tuples (view_no, pp_seq_no, pp_digest) (f.CHECKPOINTS.nm, IterableField(AnyField())) # list of Checkpoints TODO: should we change to tuples? )
class NewView(MessageBase): typename = NEW_VIEW schema = ( (f.VIEW_NO.nm, NonNegativeNumberField()), (f.VIEW_CHANGES.nm, IterableField( AnyField())), # list of tuples (node_name, view_change_digest) (f.CHECKPOINT.nm, AnyField()), # Checkpoint to be selected as stable (f.PREPREPARES.nm, IterableField(AnyField()) ) # list of PrePrepares that should get into new view )
class SetContextField(MessageValidator): context = ( (CONTEXT_NAME, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT)), (CONTEXT_VERSION, VersionField(version_cls=ContextVersion)), (CONTEXT_CONTEXT_ARRAY, IterableField( LimitedLengthStringField(max_length=NAME_FIELD_LIMIT), min_length=1, max_length=CONTEXT_ATTRIBUTES_LIMIT)), )
class Ordered(MessageBase): typename = ORDERED schema = ( (f.INST_ID.nm, NonNegativeNumberField()), (f.VIEW_NO.nm, NonNegativeNumberField()), (f.REQ_IDR.nm, IterableField(RequestIdentifierField())), (f.PP_SEQ_NO.nm, NonNegativeNumberField()), (f.PP_TIME.nm, TimestampField()), (f.LEDGER_ID.nm, LedgerIdField()), (f.STATE_ROOT.nm, MerkleRootField(nullable=True)), (f.TXN_ROOT.nm, MerkleRootField(nullable=True)), )
class PrePrepare(MessageBase): typename = PREPREPARE schema = ( (f.INST_ID.nm, NonNegativeNumberField()), (f.VIEW_NO.nm, NonNegativeNumberField()), (f.PP_SEQ_NO.nm, NonNegativeNumberField()), (f.PP_TIME.nm, TimestampField()), (f.REQ_IDR.nm, IterableField(RequestIdentifierField())), (f.DISCARDED.nm, NonNegativeNumberField()), (f.DIGEST.nm, LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT)), (f.LEDGER_ID.nm, LedgerIdField()), (f.STATE_ROOT.nm, MerkleRootField(nullable=True)), (f.TXN_ROOT.nm, MerkleRootField(nullable=True)), )
def test_valid_inner_type(): validator = IterableField(NonNegativeNumberField()) assert not validator.validate([1, 2, 3]) assert validator.validate([1, 2, -3])