Skip to content

Even lazier node instantiation.#1868

Merged
KPrasch merged 11 commits intomasterfrom
nodes
Apr 20, 2020
Merged

Even lazier node instantiation.#1868
KPrasch merged 11 commits intomasterfrom
nodes

Conversation

@jMyles
Copy link
Contributor

@jMyles jMyles commented Apr 9, 2020

A precursor to #1881, this PR integrates the changes in nucypher/bytestringSplitter#27.

@jMyles jMyles changed the title Evolving Node validity and domain separation. [WIP] Evolving Node validity and domain separation. Apr 9, 2020
@jMyles jMyles changed the title [WIP] Evolving Node validity and domain separation. Even lazier node instantiation. Apr 15, 2020
@KPrasch KPrasch added Dependencies 😈 Dependency compatibility, updates, and relocks Enhancement New or improved features not-premature labels Apr 15, 2020
def __init__(self, node_metadata):
super().__init__(node_metadata)
self.checksum_address = to_checksum_address(node_metadata['public_address'][0])
self.checksum_address = to_checksum_address(self.public_address)
Copy link
Member

Choose a reason for hiding this comment

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

🎉 - Looking excellent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...and much more optimal. Saves a keccak and other smaller cpu-bound operations compared to the previous method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Really nice

Copy link
Contributor

Choose a reason for hiding this comment

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

With other changes too, readability is certainly improved!

…a bit of compatibility logic in the tests here.
Comment on lines +462 to +471
if eager:
node.mature()
stranger_certificate = node.certificate
except AttributeError:
# Probably a sprout.
try:
if grow_node_sprout_into_node:
node.mature()
stranger_certificate = node.certificate
else:
# TODO: Well, why? What about eagerness, popping listeners, etc? We not doing that stuff? NRN
return node
except Exception as e:
# Whoops, we got an Alice, Bob, or something totally wrong...
raise self.NotATeacher(f"{node.__class__.__name__} does not have a certificate and cannot be remembered.")

# Store node's certificate - It has been seen.
certificate_filepath = self.node_storage.store_node_certificate(certificate=stranger_certificate)
# Store node's certificate - It has been seen.
certificate_filepath = self.node_storage.store_node_certificate(certificate=stranger_certificate)

# In some cases (seed nodes or other temp stored certs),
# this will update the filepath from the temp location to this one.
node.certificate_filepath = certificate_filepath
# In some cases (seed nodes or other temp stored certs),
# this will update the filepath from the temp location to this one.
node.certificate_filepath = certificate_filepath
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole thing is looking really nice now.

verifying_keys_match = sprout.verifying_key == self.public_keys(SigningPower)
encrypting_keys_match = sprout.encrypting_key == self.public_keys(DecryptingPower)
addresses_match = sprout.public_address == self.canonical_public_address
evidence_matches = sprout.decentralized_identity_evidence == self.__decentralized_identity_evidence
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀

Copy link
Contributor

@tuxxy tuxxy left a comment

Choose a reason for hiding this comment

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

Really liking these changes.

assert len(all_known_nodes) == len(all_stored_nodes)
assert all_stored_nodes == all_known_nodes

known_checksums = sorted([n.checksum_address for n in all_known_nodes])
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, [ and ] are not necessary here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed; good catch. I will include this change in #1881.


# However, it learned about *all* of the nodes in its own domain.
assert set(first_domain_learners).intersection(set(new_first_domain_learner.known_nodes)) == first_domain_learners
assert set(first_domain_learners).intersection(set(n.mature() for n in new_first_domain_learner.known_nodes)) == first_domain_learners
Copy link
Contributor

Choose a reason for hiding this comment

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

Curiously, it works as .intersection(n.mature() for n in new_first_domain_learner.known_nodes), too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting - that's unexpected. But very nice. I will also include this in #1881.

Copy link
Contributor

@michwill michwill left a comment

Choose a reason for hiding this comment

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

Was a pleasure to read

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

🎸 - nice cleanup!

@KPrasch KPrasch merged commit 95cc147 into master Apr 20, 2020
@jMyles jMyles deleted the nodes branch April 24, 2020 15:11
cygnusv pushed a commit to cygnusv/nucypher that referenced this pull request Sep 8, 2020
cygnusv pushed a commit to cygnusv/nucypher that referenced this pull request Sep 14, 2020
cygnusv pushed a commit to cygnusv/nucypher that referenced this pull request Sep 16, 2020
cygnusv pushed a commit to cygnusv/nucypher that referenced this pull request Sep 20, 2020
KPrasch pushed a commit to KPrasch/nucypher that referenced this pull request Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dependencies 😈 Dependency compatibility, updates, and relocks Enhancement New or improved features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants