Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

[WIP] Feat/oracle cache #64

Closed
wants to merge 19 commits into from
Closed

[WIP] Feat/oracle cache #64

wants to merge 19 commits into from

Conversation

naterush
Copy link

Work started on this issue: #59

Other tests are passing, so it appears I haven't broken anything too badly. The code could use some serious testing and cleanup though :)

@djrtwo would love to talk about architecture trade-offs here. Also, would love to get some stats about performance improvements :)


# if it is a free block
if message.sequence_number > seq_number:
# NOTE: preferably, would not do this for all new messages - rather just latest free block?
Copy link
Author

@naterush naterush Oct 18, 2017

Choose a reason for hiding this comment

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

This could add some significant efficiency gains - I think. Will take a crack at this tomorrow (not too hard I don't think, just storing new messages in a dict + list, I think).

@naterush
Copy link
Author

Ok, so the root of the bug above is (I'm 95% sure) the fact that I don't search through messages later than last_checked_messages even when I add a new estimate.

The issue here is that there are very likely viewables here that I am missing because of this (massive oversight - I know!). There should be an easy fixup tomorrow (and should fix the remaining bugs in all the oracles that result from these missing viewables).

@djrtwo
Copy link
Contributor

djrtwo commented Oct 19, 2017

Where the tests at brah?
I wanna see the bug but I guess it's from manual testing

Holler if you need another set of eyes. Going to leave it to you until you say otherwise for review/help

@naterush
Copy link
Author

Yep, manual testing and many assert statements. Will be able to get some tests up tonight with the fixes hopefully :~)

Interestingly, though this is horribly bugged, none of our previous test cases catch it :) We need to bulk up on some safety oracle tests.

@djrtwo
Copy link
Contributor

djrtwo commented Oct 19, 2017 via email

@naterush
Copy link
Author

@djrtwo good call. Will do.

Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

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

Looks good! A few things

  • I'd like to see oracle_class passed into OracleManager. This will open up more easily testing against the Oracles. Consider getting some of the tests to run against multiple Oracles when you add this.
  • Break down some of the big functions in OracleManager to readability.
  • Use a linting tool. Either integrate something into your editor that warns you or run pylint from the commandline. We're working on getting the entire repo linted up and once we do, having no linting errors will be part of CircleCI passing.
  • testing
    • Minimum unit tests doing at least some sanity checking on OracleManager initialization and basic functions. I know safety tests with testlang cover the heavy stuff. I want some test somewhere to at least break if we change the OracleManager API.
    • Run safety tests against each Oracle.

self.last_checked_messages = dict()


def update_viewables(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see this broken into sub methods (prefixed with "_") -- something like _track_new_viewables, _remove_outdated_viewables, and _update_last_checked_messages

I want to be able to look at update_viewables, read the two or three submethods it calls and know exactly what is going on from a high level just by reading those method names.


class OracleManager:

def __init__(self, view, validator_set, safety_threshold):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably take a param oracle_class so the user can pass in CliqueOracle, TuranOracle, etc for the manager to use.

Copy link
Contributor

Choose a reason for hiding this comment

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

One fun thing from this would be the ability to instantiate different validators with different oracles...

Copy link
Author

Choose a reason for hiding this comment

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

Good call. Also, the ability for validators to have different safety_thesholds now :)


def test_cache_checks_all_possible_viewables(test_lang_runner):
test_string = ''
for i in range(100):
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a comment or something. Very unreadable

test_string += 'U' + str(j) + '-' + str(i) + ' ' + 'U' + str(j) + '-' + str(i + 100) + ' '
test_string = test_string[:-1]

weights = {0: 10, 1: 9.5, 2: 8.32, 3: 7.123, 4: 6.02245}
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 explanation on these weights? are they important to the test? The complexity of the test_string leaves me unsure.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the weights don't matter, consider doing a "parameters" header on this with 2 to 3 different weights defs

@@ -0,0 +1,141 @@
from casper.safety_oracles.clique_oracle import CliqueOracle
Copy link
Contributor

Choose a reason for hiding this comment

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

If you pass in oracle_calss to __init__, you won't need to do any of these imports here.

@djrtwo
Copy link
Contributor

djrtwo commented Oct 23, 2017

@naterush Merged in simulationrunner changes

@@ -14,17 +14,17 @@ def __init__(self, view, validator_set, safety_threshold):
def update_viewables(self):
"""For each estimate being tracked, finds new and removes old viewables based on view"""
# finds all new viewables, for each validator, for each estimate we are keeping track of
self._track_new_viewables()
val_with_new_messages = self._track_new_viewables()
Copy link
Author

Choose a reason for hiding this comment

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

Returning this from the track new viewables function is hack-y and unnecessary. The clean-up I was going to start on just breaks these into functions that do what they say they do.

For example, it might be better to have the for estimate in self.viewables_for_estimate: loop in the update_viewables function - and then pass in the estimate to each of the respective functions. It's not a hard change either way but would love to hear your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very much agree. Yeah, that makes sense. Do everything that needs to be done for a given estimate and then move on to the next estimate

@naterush
Copy link
Author

Once we settle on the best oracle_manager design, I think the best option is probably too close this PR, rebase onto a new branch, and then restart. Either that or clean up the commit history, b/c things are quite messy :)

@naterush
Copy link
Author

Closing this for now. Not a priority for devcon - and it's in a state of disrepair as of now. Will reopen when after.

@naterush naterush closed this Oct 26, 2017
@naterush naterush deleted the feat/oracle_cache branch February 14, 2018 02:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants