-
Notifications
You must be signed in to change notification settings - Fork 44
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
Feat/genesis #119
Feat/genesis #119
Conversation
excited by how small this PR looks! |
I think we need to figure out a solution that does not require I think all validators of all protocols should get a genesis block. They can get it from An individual validator's view is pass in There might be a detail I missed, but I think the above plan will allow us to have most of the code protocol agnostic and be more modular in allowing us to define the genesis block at a protocol level. |
@djrtwo there was a version of this PR where the genesis was defined in the Protocol. The issue I had with this was that it later makes it much harder to have a weakly subjective deal where validators start with different genesis blocks - but for it might make sense to not worry about that. I totally agree that having As far as each protocol having a genesis message, I need to think about it for a bit. We would have to have a function called This might be a bit messier than we want, as I'm not sure every protocol deserves a genesis message. For example, in the case of binary, it's not really a genesis message (in the "shared" sense), just a new place to generate each validators initial message. It might make more sense to just define a genesis_message in a view... Need to think about it more |
I'm cool with a function For Blockchain, it would be the genesis block initially, but could later be the most recent finalized block when the validator signs on. I guess it would just be the most recent finalized block where most recent finalized starts as the genesis. (initially though, it would just be coded to return genesis. it being dynamic would come in later PR). For Binary, would be some random initialization. We should talk it out. |
point merge to |
@djrtwo check it. Still need to fix/remove the random_initialization function (going to remove it and move work to network initialization). That being said, not totally with happy with moving this message generation to Protocol. Let me know what you think so far. |
changed to base to feat/hash_linking |
@djrtwo should be good to review. Removed a fair bit of technical debt in the testing as a result of usually having 5 messages generated at the start of some execution. The one change I made that I'm not totally comfortable with is that the simulation runner will make the validator generate new messages if it does not already have one. That being said, I don't think it's that bad - it just makes the analyzer tests a bit less precise. Looking forward to hearing your thoughts :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some little things. Looks great in general.
I put a note about the extra check for sim runner generating a new message if validator doesn't have one. Don't all validators start with a message now??
casper/network.py
Outdated
@@ -34,7 +38,10 @@ def view_initialization(self, view): | |||
for validator in self.validator_set: | |||
validator.receive_messages(messages) | |||
|
|||
def random_initialization(self): | |||
"""Generates starting messages for all validators with None as an estiamte.""" | |||
def collect_initial_messages(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should likely be prefixed with _
. Maybe could use a name change. The name is a bit misleading because if the network moves forward in time, this will no longer collect the initial messages.
@@ -18,6 +16,9 @@ def __init__(self, messages=None): | |||
|
|||
self.latest_messages = dict() # validator => message | |||
|
|||
self.add_messages(messages) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one line between methods in a class
tests/simulations/test_analyzer.py
Outdated
@@ -30,11 +30,11 @@ def test_num_messages(validator_set, mode, messages_generated_per_round): | |||
analyzer = Analyzer(simulation_runner) | |||
|
|||
# due to random_initialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment
tests/simulations/test_analyzer.py
Outdated
|
||
for i in range(10): | ||
simulation_runner.step() | ||
assert analyzer.num_messages() == \ | ||
assert analyzer.num_messages() <= \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be ==
and remove len(validator_set) +
from the assertion.
was there from the initial messages
@@ -107,9 +107,12 @@ def test_simulation_runner_send_messages( | |||
False | |||
) | |||
|
|||
assert len(simulation_runner.network.global_view.justified_messages) == len(validator_set) | |||
if protocol == BlockchainProtocol: | |||
assert len(simulation_runner.network.global_view.justified_messages) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 0? shouldn't the genesis block be justified?
|
||
for i in range(10): | ||
simulation_runner.step() | ||
assert len(simulation_runner.network.global_view.justified_messages) == \ | ||
(i + 1) * messages_generated_per_round + len(validator_set) | ||
assert len(simulation_runner.network.global_view.justified_messages) <= \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capture the initial length of the justified_messages
, plug it into where len(validator_set)
is below, and use ==
for sender, receiver in message_paths: | ||
message = sender.my_latest_message() | ||
last_message = sender.my_latest_message() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't all validator's have a latest message when they are initialized now? Do we need this check?
@naterush I'm going to address my notes and merge |
…ssage to messages
[WIP] Feat/genesis message change
Adds a genesis block. Not sure if we should add a default genesis block to
BlockchainProtocol
, where all validators who don't get a genesis block sent to them choose this as their genesis.The benefit of this is that we have to stop worrying about a number of edge cases. For example, I'd like to move the block's estimate to be hash linked. As a result, I want the
estimate()
function for the blockchain view to return a hash - and it would be much cleaner to not have to worry aboutNone
(addresses #56)