Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

spec loading cleanup #858

Merged
merged 14 commits into from Apr 9, 2016
Merged

spec loading cleanup #858

merged 14 commits into from Apr 9, 2016

Conversation

debris
Copy link
Collaborator

@debris debris commented Mar 30, 2016

the goal of this pr is to cleanup loading spec and get rid of all unwraps (or at least as many as possible).

changes:

  • in json spec files:
    • replaced engineName with engine
    • moved engine specific params to engine field
    • seal fields are grouped together
  • completely removed usages of FromJson trait from ethcore
  • removed toEngine method from spec. engine is now a spec property
  • spec is no longer a property of engine
  • engine params are no longer decoded from rlp.

This pr is so big mostly because I had to change a lot of test functions...

todo:

  • update spec wiki

@debris debris added the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Mar 30, 2016
@debris debris added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Mar 31, 2016
@debris debris changed the title spec loading cleanup in progress spec loading cleanup Mar 31, 2016
@NikVolf NikVolf added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Apr 1, 2016
@NikVolf
Copy link
Contributor

NikVolf commented Apr 1, 2016

looks great

ChainEra::Homestead => ethereum::new_homestead_test(),
}.to_engine().unwrap();
ChainEra::Frontier => ethereum::new_mainnet_like().engine,
ChainEra::Homestead => ethereum::new_homestead_test().engine
Copy link
Contributor

Choose a reason for hiding this comment

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

trailing comma missing.

@gavofyork gavofyork added A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Apr 1, 2016
@gavofyork
Copy link
Contributor

this is a rather disstressing change.

the engine factory was a temporary place-holder for a dynamically-loaded plugin architecture; this change doesn't help achieve that goal.

it rearchitects the Spec/Engine ownership relationship, reducing Engine to a second-class utility type unable to be used without an owning Spec. at best, the name(s) need changing. at worst there are unforseen consequences of the design alteration (e.g. can we have an Engine in test code without needing a JSON description or using the placeholder Engine factory?) - keeping the design centred around Engine (which actually does the work) and not a JSON deserialisation type was an important design consideration. there is no clear addressing of the consequences of the design alteration.

@gavofyork
Copy link
Contributor

removing unwraps is great and all, but what happens if the data of the json is in incorrect format? there's really only three possibilities:

  • panic (no better than unwrap);
  • bubble-up error on call stack (i don't see any try!s);
  • silently give default value (probably just bad).

@debris
Copy link
Collaborator Author

debris commented Apr 1, 2016

I will try address all questions and concerns here:

removing unwraps is great and all, but what happens if the data of the json is in incorrect format?

Currently there is no single place where whole json spec is validated. we have multiple unwraps in spec, builtin and verification. Besides that, there are try in client constructor. In my pr, the whole json spec is validated deserialized in a single place.

Spec is a specification that describes the consensus engine. It was not designed to be used as a parent instance.

This may be my misunderstanding... I see spec as a chain specification. And engine as a chain property.

Refactoring it in this way probably has unforseen consequences. Engine is meant to be the parent type to be passed around.

I had the same concerns, but then I noticed that the only spec function that we use* (excluding Engine) is ensure_db_good. And it's used only just after spec is loaded.

it rearchitects the Spec/Engine ownership relationship, reducing Engine to a second-class utility type unable to be used without an owning Spec.

I think it's the other way around. On master branch, it's very difficult to create Ethash engine without loading json spec. Now it's trivial.

at best, the name(s) need changing. at worst there are unforseen consequences of the design alteration (e.g. can we have an Engine in test code without needing a JSON description or using the placeholder Engine factory?) - keeping the design centred around Engine (which actually does the work) and not a JSON deserialisation type was an important design consideration. there is no clear addressing of the consequences of the design alteration.

Using JSON is completely optional and nothing relies on it now.

the engine factory was a temporary place-holder for a dynamically-loaded plugin architecture; this change doesn't help achieve that goal.

I'm aware of that. And there is the same issue with genesis seal. That's true that this pr doesn't help achieve that goal, but imo it does not make it more difficult.

@debris
Copy link
Collaborator Author

debris commented Apr 1, 2016

I understand that this pr introduces two things that could be done separately (deserialization && object ownership refactoring), but it was just much easier to do this things together.

@gavofyork
Copy link
Contributor

Engine certainly isn't a chain property. It's an auxiliary, used for much of the chain mechanics which may be defined (and thus constructed) by a portion of the chain Spec.

@@ -27,33 +27,6 @@ use substate::*;
use tests::helpers::*;
use ethjson;

struct TestEngineFrontier {
Copy link
Contributor

Choose a reason for hiding this comment

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

why removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly the same structure was defined in ethcore/src/tests/helpers.rs

@gavofyork
Copy link
Contributor

probably good to go in, but i'd reconsider the naming in light of the architecture alteration.

@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. labels Apr 3, 2016
@debris
Copy link
Collaborator Author

debris commented Apr 4, 2016

Do you have any suggestions?

@gavofyork
Copy link
Contributor

Having thought about it Chain or ChainSpec is the only thing I can think of which sounds as though it "owns" Engine. But I don't really like double-barrel names and just "Chain" doesn't seem much better than "Spec".

@gavofyork gavofyork added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Apr 9, 2016
@gavofyork gavofyork merged commit 373284c into master Apr 9, 2016
@gavofyork gavofyork deleted the spec_loading_cleanup branch April 9, 2016 17:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants