Skip to content

Increasing performance of discovery, verification, metadata validation, and fleet state operations.#1451

Merged
jMyles merged 89 commits intonucypher:masterfrom
jMyles:discovery
Jan 10, 2020
Merged

Increasing performance of discovery, verification, metadata validation, and fleet state operations.#1451
jMyles merged 89 commits intonucypher:masterfrom
jMyles:discovery

Conversation

@jMyles
Copy link
Contributor

@jMyles jMyles commented Nov 10, 2019

New Node Discovery Stuff

The quickest summary is: Node discovery and validation now happens in three phases - nodes are no longer instantiated en mass when discovery first begins. As such, It is no longer possible to accidentally use an unverified node for discovery, arrangement, and service operations, as any unverified nodes are verified at the time they are used. Discovery of 4,000 nodes now takes no longer than 6 seconds; this time is asserted in a test.


federated_only

Mixed operating modes are no longer possible on an automatic basis. It's of course possible to use the Python API to manually construct a Policy using a mixture of operating modes, but it must be done manually. federated_only is removed as a kwarg in many methods.

Introducing NodeSprout

A NodeSprout is a thin wrapper around the dict that is produced when splitting the bytes representing a Node, but without instantiating each constituent object.

Advanced substantially but not quite closed:

Remaining major issues:

Newly opened:

@jMyles jMyles changed the title Increasing performance of discovery, verification, and metadata validation. Increasing performance of discovery, verification, metadata validation, and fleet state operations. Nov 11, 2019
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.

Crazy mocks!

@KPrasch KPrasch changed the title Increasing performance of discovery, verification, metadata validation, and fleet state operations. [WIP] Increasing performance of discovery, verification, metadata validation, and fleet state operations. Nov 12, 2019
@codecov
Copy link

codecov bot commented Nov 12, 2019

Codecov Report

Merging #1451 into master will decrease coverage by 3.74%.
The diff coverage is 61.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1451      +/-   ##
==========================================
- Coverage   84.02%   80.28%   -3.75%     
==========================================
  Files          72       72              
  Lines       11194    11241      +47     
==========================================
- Hits         9406     9025     -381     
- Misses       1788     2216     +428
Impacted Files Coverage Δ
nucypher/utilities/logging.py 63.26% <100%> (+3.26%) ⬆️
nucypher/characters/lawful.py 86.7% <100%> (-2.38%) ⬇️
nucypher/characters/base.py 87.03% <100%> (+0.99%) ⬆️
nucypher/utilities/sandbox/middleware.py 84.94% <100%> (-5.65%) ⬇️
nucypher/network/server.py 84.4% <100%> (-1.19%) ⬇️
nucypher/network/nodes.py 77.47% <53.27%> (-2.77%) ⬇️
nucypher/characters/chaotic.py 25% <0%> (-48.99%) ⬇️
nucypher/cli/characters/felix.py 40.39% <0%> (-39.74%) ⬇️
nucypher/cli/status.py 48.48% <0%> (-34.85%) ⬇️
nucypher/cli/characters/bob.py 66.66% <0%> (-22.5%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ea77a3...b7f2820. Read the comment docs.

@jMyles jMyles force-pushed the discovery branch 2 times, most recently from b20d28e to 294b628 Compare December 23, 2019 22:41
@jMyles jMyles changed the title [WIP] Increasing performance of discovery, verification, metadata validation, and fleet state operations. Increasing performance of discovery, verification, metadata validation, and fleet state operations. Dec 24, 2019
# Whoops, we got an Alice, Bob, or someone...
raise self.NotATeacher(f"{node.__class__.__name__} does not have a certificate and cannot be remembered.")
# Probably a sprout.
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's easier to do it not at try/except but by overriding __getattr__, so that we grow it once we first access the certificate (or maybe something else, too).

Or is it too implicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this occurred to me. I thought it was too dramatic and perhaps a premature optimization. I am trying to be somewhat reserved in this PR. But jeez man, if you thought of it independently, that's pretty solid evidence that it's a good idea.

I think if we do it, let's do it all the way down in the bytestring-splitter project.

# If we're federated only, we assume that all other nodes in our domain are as well.
node_class.set_federated_mode(federated_only)
else:
# What an awful hack. The last convulsions of #466.
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the alternative? Is there an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I'm concerned, #466 is the issue. Do you think there's a need for a distinct one?


def __init__(self,
domains: Set = None,
node_class: object = None,
Copy link
Member

Choose a reason for hiding this comment

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

Might just be personal preference, but this would be clearer to me if it was known_node_class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, yeah.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

filepath = mature_node._cert_store_function(certificate=mature_node.certificate)
mature_node.certificate_filepath = filepath

self.__class__ = mature_node.__class__
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, serious magic!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Too much for you?

I mean, I know that polymorphism and meta programming are often lumped in with more magic techniques, but I think there's something elegant about changing the class of the object in place.

Copy link
Member

Choose a reason for hiding this comment

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

This was called "evolution" in Pokemon
image

network_middleware=network_middleware)

except NodeSeemsToBeDown: # TODO: #355 Also catch InvalidNode here?
except NodeSeemsToBeDown as e: # TODO: #355 Also catch InvalidNode here?
Copy link
Contributor

Choose a reason for hiding this comment

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

That's e for a debugger, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yes. It can go if you want, but it's an awfully useful place to have one if you're using a debugger.

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.

Looked through again

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.

🎸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants