-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[INDY-1642] Discarded field to bitmask #895
[INDY-1642] Discarded field to bitmask #895
Conversation
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
@@ -141,7 +141,7 @@ class PrePrepare(MessageBase): | |||
(f.PP_TIME.nm, TimestampField()), | |||
(f.REQ_IDR.nm, IterableField(LimitedLengthStringField( | |||
max_length=DIGEST_FIELD_LIMIT))), | |||
(f.DISCARDED.nm, NonNegativeNumberField()), | |||
(f.DISCARDED.nm, SerializedValueField()), | |||
(f.DIGEST.nm, LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT)), | |||
(f.LEDGER_ID.nm, LedgerIdField()), | |||
(f.STATE_ROOT.nm, MerkleRootField(nullable=True)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the fields Sergey K. asked about for future PrePrepare enhancements?
plenum/server/replica.py
Outdated
ledger_id, self.viewNo, | ||
pp_seq_no) | ||
if not (validReqs or inValidReqs): | ||
if discarded_mask.length() == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check for emptiness of reqs
?
plenum/server/replica.py
Outdated
|
||
def _pack_discarded_mask(self, value): | ||
discarded_mask = bitarray() | ||
discarded_mask.pack(b''.fromhex(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not bytes.fromhex
?
plenum/server/replica.py
Outdated
@@ -809,7 +820,7 @@ def create3PCBatch(self, ledger_id): | |||
pp_seq_no, | |||
tm, | |||
[req.digest for req in reqs], | |||
len(validReqs), | |||
self._unpack_discarded_mask(discarded_mask), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do an optimization so that if there are no discarded requests (all passed dynamic validation), then we just use an empty (None or zero) mask.
@@ -50,7 +50,7 @@ | |||
'six==1.11.0', 'psutil==5.4.3', 'intervaltree==2.1.0', | |||
'msgpack-python==0.4.6', 'indy-crypto==0.4.3', | |||
'python-rocksdb==0.6.9', 'python-dateutil==2.6.1', | |||
'pympler==0.5'], | |||
'pympler==0.5', 'bitarray==0.8.1'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to have a deb package as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there is python3-bitarray=0.8.1 package in the xenial repo
replica.requests.set_finalised(req) | ||
replica.last_accepted_pre_prepare_time = int(time.time()) | ||
pp = replica.create3PCBatch(DOMAIN_LEDGER_ID) | ||
assert pp.reqIdr == [res.key for res in reqs] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the discarded value as well. Maybe we should make dynamic validation deterministic here, so that we can deterministically check discarded value?
plenum/server/replica.py
Outdated
@@ -1749,9 +1771,11 @@ def order_3pc_key(self, key): | |||
) | |||
|
|||
self.addToOrdered(*key) | |||
valid_reqs, invalid_reqs = self._apply_bitmask_to_list(pp.reqIdr, | |||
self._pack_discarded_mask(pp.discarded)) | |||
ordered = Ordered(self.instId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to have invalid reqs in Ordered msg to pass them to the monitor
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
@@ -141,7 +141,7 @@ class PrePrepare(MessageBase): | |||
(f.PP_TIME.nm, TimestampField()), | |||
(f.REQ_IDR.nm, IterableField(LimitedLengthStringField( | |||
max_length=DIGEST_FIELD_LIMIT))), | |||
(f.DISCARDED.nm, NonNegativeNumberField()), | |||
(f.DISCARDED.nm, SerializedValueField()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix Input validation tests test_pre_prepare_message
plenum/server/replica.py
Outdated
finally: | ||
reqs.append(req) | ||
|
||
def _pack_discarded_mask(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit tests for this 2 methods. Should we make the methods static, and maybe even move to some utils?
plenum/server/replica.py
Outdated
@@ -1738,6 +1749,17 @@ def doOrder(self, commit: Commit): | |||
self.logger.debug("{} ordering COMMIT {}".format(self, key)) | |||
return self.order_3pc_key(key) | |||
|
|||
def _apply_bitmask_to_list(self, reqIdrs: List, mask: bitarray): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make the methods static, and maybe even move to some utils?
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
…EPREPARE message Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
@@ -2427,6 +2427,10 @@ def processOrdered(self, ordered: Ordered): | |||
'does not exist'.format(self, ordered.instId)) | |||
return False | |||
|
|||
valid_reqs = [self.requests[request_id].finalised |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not valid requests, this is both valid and invalid ones.
plenum/server/replica.py
Outdated
@@ -1749,14 +1808,17 @@ def order_3pc_key(self, key): | |||
) | |||
|
|||
self.addToOrdered(*key) | |||
valid_reqs, invalid_reqs = self._apply_bitmask_to_list(pp.reqIdr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we call it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, if use this info in logging further, then probably pass valid_reqs and invalid_reqs to Ordered msg to avoid the same calculation in node.py?
plenum/server/replica.py
Outdated
finally: | ||
reqs.append(req) | ||
|
||
def _pack_discarded_mask(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pack_discarded_mask, unpack_discarded_mask, drop_discarded_mask, apply_bitmask_to_list, get_valid_reqs, get_invalid_reqs, get_invalid_count needs to be moved to a separate utility class (not in Replica)
assert len(reqs_count) == 1 | ||
|
||
|
||
def test_invalid_reqs(looper, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the test more predictable:
send 1 valid and 2 invalid reqs, and check that numOrderedRequests
in monitor is equal to 3.
sdk_send_random_and_check(...., 1)
<patch dynamic validation ot always return false>
with pytest,raises(RequestRejectedException)
sdk_send_random_and_check(...., 1)
with pytest,raises(RequestRejectedException)
sdk_send_random_and_check(...., 1)
check_count_reqs(nodes, 3)
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
Signed-off-by: Andrew Nikitin andrew.nikitin@dsr-corporation.com