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

(WIP) feat/heuristic-clique-oracle #150

Closed
wants to merge 1 commit into from

Conversation

seanavery
Copy link

@seanavery seanavery commented Dec 5, 2017

Heuristic Clique Oracle

Right now, the functionality is appended to the CliqueOracle class. For testing, the oracle is being called from the blockchain view.

To run: python casper.py rand --validators 10 --rounds 100 Check console output to see it in action.

This oracle does a greedy search in attempt to find a large clique quickly. It iterates through the graph favoring vertices with the largest degree until it can reduce a clique.

The current implementation does not take into account weight, which I plan on adding in.

The greedy algorithm can also be extended beyond a simple lookup to do a full search on the graph space.

For more details see #134

Copy link
Collaborator

@naterush naterush left a comment

Choose a reason for hiding this comment

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

This looks cool! I'm having some trouble getting it running (not sure if it's an issue on my end, or an issue resulting from some merge conflicts).

I'd love to see some profiling against the other oracles we have :-)

def find_max_degree_node(self, graph, nodes):
"""Returns greatest degree node out of list"""
max_degree_node = None
for node in nodes:
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use python built-ins here. They are more readable and also faster! Something like:

max_degree_node = max(nodes, key=lambda node: graph.degree(node))

Not sure the above will work b/c I can't get this code running for some reason, but something similar should work :)

# base case: find largest degree node in graph
max_degree_node = self.find_max_degree_node(graph, nodes)
if not max_degree_node:
raise Exception("### Did not find a node in the graph, no common estimates")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this ever trigger? It seems like if we have any nodes (as nodes are "inferred" from edges), we should have some node with a max degree.

Copy link
Author

Choose a reason for hiding this comment

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

No it does not really ever get triggered. More just a check in case of empty graph-- But I already check before starting the search so I can safely remove this :)

return heuristic_min_clique

# remove neighbors that are not adjacent to the new max degree vertex
for node in max_degree_neighbors:
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can change this to a Python built-in. Something like difference_update

Read more here: https://docs.python.org/2/library/sets.html

Copy link
Author

Choose a reason for hiding this comment

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

Oh cool. Yeah for sure, will refactor to use built-ins. Starting to get this whole python thing.. lol.

nodes = graph.nodes()

# if graph is empty, break out of function
if not nodes:
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe, if not any(nodes):

@naterush
Copy link
Collaborator

@seanavery Much like the Turan's oracle, I think this might be mildly "attackable." If I'm an attacker that controls some portion of the network w/ low weight validators, they can construct a high-degree connected node (that would be first chosen in the greedy search), that ends up not contributing to safety very much b/c of it's low weight.

This disappears once you add in weight considerations!

@seanavery
Copy link
Author

seanavery commented Dec 20, 2017

@naterush Completely agree on vulnerability to attacks. i.e. A big hub and spoke resulting in a clique size of 2! Taking into account weight will make it much more expensive to perform such an attack. Still brainstorming on how to properly perform the greedy search w/ weight but i have some ideas. Going to work on rebasing this oracle-- cleaning up code and weight integration.

@seanavery seanavery closed this Jan 15, 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