Skip to content
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

Merged
merged 20 commits into from
Aug 30, 2018

Conversation

lampkin-diet
Copy link

Signed-off-by: Andrew Nikitin andrew.nikitin@dsr-corporation.com

Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
@lampkin-diet lampkin-diet changed the title [INDY-1642] Discarded field to bitmask [WIP][INDY-1642] Discarded field to bitmask Aug 27, 2018
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)),
Copy link
Contributor

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?

ledger_id, self.viewNo,
pp_seq_no)
if not (validReqs or inValidReqs):
if discarded_mask.length() == 0:
Copy link
Contributor

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?


def _pack_discarded_mask(self, value):
discarded_mask = bitarray()
discarded_mask.pack(b''.fromhex(value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not bytes.fromhex?

@@ -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),
Copy link
Contributor

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'],
Copy link
Contributor

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?

Copy link
Author

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]
Copy link
Contributor

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?

@@ -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,
Copy link
Contributor

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()),
Copy link
Contributor

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

finally:
reqs.append(req)

def _pack_discarded_mask(self, value):
Copy link
Contributor

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?

@@ -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):
Copy link
Contributor

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?

Andrew Nikitin added 12 commits August 28, 2018 13:19
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>
@ashcherbakov ashcherbakov changed the title [WIP][INDY-1642] Discarded field to bitmask [INDY-1642] Discarded field to bitmask Aug 29, 2018
@@ -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
Copy link
Contributor

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.

@@ -1749,14 +1808,17 @@ def order_3pc_key(self, key):
)

self.addToOrdered(*key)
valid_reqs, invalid_reqs = self._apply_bitmask_to_list(pp.reqIdr,
Copy link
Contributor

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?

Copy link
Contributor

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?

finally:
reqs.append(req)

def _pack_discarded_mask(self, value):
Copy link
Contributor

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,
Copy link
Contributor

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)

Andrew Nikitin added 5 commits August 29, 2018 18:43
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>
@ashcherbakov ashcherbakov merged commit 5563712 into hyperledger:master Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants