Skip to content

Commit

Permalink
disabled make_best_redundancy_free, removed some profiles, and increa…
Browse files Browse the repository at this point in the history
…sed the validator count
  • Loading branch information
vladzamfir committed Mar 31, 2017
1 parent e2ed62d commit 1446772
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 29 deletions.
2 changes: 0 additions & 2 deletions adversary.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ def __init__(self, view, victim_estimate, latest_observed_bets, vicarious_latest
self.operations_log = []

# this method updates the attack delta using the Adversary's record of the victim and target estimate weights...
@profile
def update_attack_delta(self):
self.attack_delta = self.weight_of_victim_estimate - self.weight_of_target_estimate

# ...and this one returns "True" if the attack delta is less than or equal to zero
# (indicating target weight >= victim weight)...
# ...and it returns "False" otherwise...
@profile
def is_attack_complete(self):
if self.attack_delta <= 0:
return True
Expand Down
3 changes: 0 additions & 3 deletions bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Bet:
# ...these things are not very conceptually important...

# constructor!
@profile
def __init__(self, estimate, justification, sender):

# be safe. type check!...
Expand All @@ -35,7 +34,6 @@ def __init__(self, estimate, justification, sender):
bet_number += 1

# equality check
@profile
def __eq__(self, B):

# the empty set is not a bet!
Expand All @@ -58,7 +56,6 @@ def __eq__(self, B):

# this is not an efficient serialization, because bets are included redundantly
# but this does serialize bets nicely, like this: "(1, {(1, {}, 0)}, 1)"...!
@profile
def __str__(self):
string = "("
string += str(self.estimate) + ", {"
Expand Down
3 changes: 0 additions & 3 deletions model_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Model_Validator:
my_latest_bet_value_error = """...expected dictionary latest_observed_bets to only contain values
of a bet or the empty set"""

@profile
def __init__(self, model_of_validator, my_latest_bet, my_latest_observed_bets, viewable, target_estimate):

# be safe, type check!
Expand All @@ -43,7 +42,6 @@ def __init__(self, model_of_validator, my_latest_bet, my_latest_observed_bets, v
self.latest_observed_bets = my_latest_observed_bets

# model validators use their view at my_latest_bet to calculate an estimate, returns set() on failure
@profile
def my_estimate(self):

# otherwise we compute the max score byzantine free estimate
Expand Down Expand Up @@ -75,7 +73,6 @@ def my_estimate(self):
# It will only succeed if:
# * the latest bet from the sender in its dependency
# * or we haven't heard from the sender before
@profile
def make_viewable(self, bet):

# be safe, type check.
Expand Down
6 changes: 0 additions & 6 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Network:
@profile
def __init__(self):
self.validators = dict()
for v in VALIDATOR_NAMES:
Expand All @@ -18,7 +17,6 @@ def propagate_bet_to_validator(self, bet, validator_name):
assert bet in self.global_view, "...expected only to propagate bets from the global view"
self.validators[validator_name].show_single_bet(bet)

@profile
def get_bet_from_validator(self, validator_name):
assert validator_name in VALIDATOR_NAMES, "...expected a known validator"

Expand All @@ -29,7 +27,6 @@ def get_bet_from_validator(self, validator_name):
self.global_view.add(new_bet)
return new_bet

@profile
def random_propagation_and_bet(self):

destination = r.choice(tuple(VALIDATOR_NAMES))
Expand All @@ -42,7 +39,6 @@ def random_propagation_and_bet(self):

# def let_validator_push

@profile
def view_initialization(self, view):
assert isinstance(view, View)
self.global_view = view.bets
Expand All @@ -52,11 +48,9 @@ def view_initialization(self, view):
for v in latest:
self.validators[v].my_latest_bet = latest[v]

@profile
def random_initialization(self):
for v in VALIDATOR_NAMES:
self.get_bet_from_validator(v)

@profile
def report(self, safe_bets):
View(self.global_view).plot_view(safe_bets)
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
r.seed()

# the size of the validator set is assumed to be known in advance
NUM_VALIDATORS = 5
NUM_VALIDATORS = 75

# we will refer to them by names in this set
VALIDATOR_NAMES = set(range(NUM_VALIDATORS))
Expand Down
7 changes: 1 addition & 6 deletions validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def __init__(self, name):
self.my_latest_bet = None
self.my_latest_estimate = None

@profile
def get_latest_estimate(self):
scores = dict.fromkeys(ESTIMATE_SPACE, 0)
for v in VALIDATOR_NAMES:
Expand Down Expand Up @@ -134,8 +133,6 @@ def decide_if_safe(self):
self.decided = not unsafe
return not unsafe


@profile
def make_bet_with_null_justification(self, estimate):
assert (len(self.view.bets) == 0 and
self.my_latest_bet is None), "...cannot make null justification on a non-empty view"
Expand All @@ -144,7 +141,6 @@ def make_bet_with_null_justification(self, estimate):
self.latest_observed_bets[self.name] = self.my_latest_bet
return self.my_latest_bet

@profile
def make_new_latest_bet(self):

if len(self.view.bets) == 0 and self.my_latest_bet is None:
Expand Down Expand Up @@ -176,7 +172,7 @@ def make_new_latest_bet(self):
sender = self.name

self.my_latest_bet = Bet(estimate, justification, sender)
self.my_latest_bet.make_redundancy_free()
# self.my_latest_bet.make_redundancy_free()
self.my_latest_estimate = estimate
self.view.add_bet(self.my_latest_bet)
self.latest_observed_bets[self.name] = self.my_latest_bet
Expand Down Expand Up @@ -246,7 +242,6 @@ def show_single_bet(self, bet):
else:
print "unable to show bet to decided node"

@profile
def show_set_of_bets(self, bets):
if not self.decided:
for bet in bets:
Expand Down
8 changes: 0 additions & 8 deletions view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class View:
@profile
def __init__(self, bets):
# be safe, type check!
for b in bets:
Expand All @@ -31,14 +30,12 @@ def __init__(self, bets):
# (1, {(1, {}, 0)}, 1)
# (0, {}, 0)

@profile
def __str__(self):
s = "View: \n"
for b in self.bets:
s += str(b) + "\n"
return s

@profile
def add_bet(self, bet):
self.recompute_extension = True
self.recompute_latest_bets = True
Expand All @@ -49,12 +46,10 @@ def add_bet(self, bet):
# ...and finally, add the bet!
self.bets.add(bet)

@profile
def add_view(self, view):
for b in view.bets:
self.add_bet(b)

@profile
def remove_bets(self, bets_to_remove_from_view):
self.recompute_extension = True
self.bets.difference_update(bets_to_remove_from_view)
Expand Down Expand Up @@ -94,7 +89,6 @@ def get_extension(self):
# this algorithm encodes a map from validators to their lates bets, in a particular view...
# ...it returns a Python dictionary of the most recent bets, indexed by validator...
# ...and it stores empty set to handle key exceptions!
@profile
def get_latest_bets(self):
if not self.recompute_latest_bets:
return self.latest_bets
Expand Down Expand Up @@ -140,7 +134,6 @@ def get_latest_bets(self):
return latest_bets

# this computes the maximum weight estimate from the latest bets in the view
@profile
def canonical_estimate(self):

# first, grab the latest bets...
Expand Down Expand Up @@ -169,7 +162,6 @@ def canonical_estimate(self):
else:
raise Exception("...expected a non-empty view")

@profile
def plot_view(self, coloured_bets, colour='green'):

G = nx.DiGraph()
Expand Down

0 comments on commit 1446772

Please sign in to comment.