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

Blockchain module cleanup #524

Merged
merged 10 commits into from Feb 29, 2016
Merged

Blockchain module cleanup #524

merged 10 commits into from Feb 29, 2016

Conversation

debris
Copy link
Collaborator

@debris debris commented Feb 27, 2016

changes:

  • split block_to_extras_update function into 6 smaller functions. Code is cleaner, more maintainable and readable.
  • fully separated preparing extas update from applying it to a batch.
  • split blockchain.rs into few separate files. This file was becoming a behemoth.
  • fixed cleaning up blockchain caches.

@debris debris added A0-pleasereview 🤓 Pull request needs code review. A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 27, 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 Feb 27, 2016
@debris
Copy link
Collaborator Author

debris commented Feb 27, 2016

I recommend opening blockchain.rs file in new tab. Git diff is hardly readable.

@gavofyork
Copy link
Contributor

needs a rebase. also it's quite big - i presume no logic has been added in this PR?

@debris
Copy link
Collaborator Author

debris commented Feb 27, 2016

no, I will rebase

let mut to_details = to.0.clone();
let mut current_from = from.1.clone();
let mut current_to = to.1.clone();
let mut from_details = self.block_details(&from).expect(&format!("0. Expected to find details for block {:?}", from));
Copy link
Contributor

Choose a reason for hiding this comment

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

this probably shouldn't panic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually here it should. Missing block details means one of two things:

  • our db is malformed (or not complete).
  • this function is being used incorrectly.

Copy link
Contributor

Choose a reason for hiding this comment

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

asserting on an external factor such as what is or is not in some particular portion of the database is not particularly defensive coding.

the only proper use of panics/assertions in live code is for specifying logical certainties (assert!(1 != 0);) or absolute assertions over the high-level design that are themselves well tested (e.g. TrieDBMut asserts that nodes are in the database, but the trie has comprehensive tests and is written to in only two places in the codebase, with no forseeable alterations, so it's possible to convince oneself that we've structured things so this panic cannot happen; similarly, all data is checked first with UntrustedRLP before it is allowed to be interpreted with the panicking RLP).

it is sometimes reasonable to use them to specify a function's preconditions, this in this case they should be simple enough that it can be done up front in the code prior to the implementation proper, functioning essentially as symbolic documentation (e.g. fn sqrt(x: int) -> int { assert!(x >= 0); ... })

if you cannot point to comprehensive tests and, from the structure of the software's design see that your assertion can never be false, then it should not panic, but rather fail-over at a higher level.

in this case, there is a mere "expectation" that the database happens to have all entries in it that the algorithm decides it needs given the argument of unknown provenance. this is not a trivial precondition and could therefore not function as symbolic documentation.

in short, unless you are willing to bet the farm on this function never being used "improperly" (not to mention any DB manipulation code failing), and can prove that by design it cannot happen now or in the future, then a panic is unacceptable in this position.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. I will fix it in next prs.

@gavofyork
Copy link
Contributor

it's not especially clear that no logic has been added/changed. maybe add a commentary so we know which functions have been moved where?

given that the tests pass, i'm inclined to let it go this time, but i think for complex refactoring, when it's not clear that it is just repotting, either break down the PRs into two or more smaller refactorings or give clear commentary about what's going on in the PR (e.g. line comments seem to work quite well to guide the reviewer).

@arkpar
Copy link
Collaborator

arkpar commented Feb 27, 2016

There should be a test that checks if the blockchain cache has been updated correctly after a fork

@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 27, 2016
@gavofyork
Copy link
Contributor

can "fixed cleaning up blockchain caches" be placed in a separate PR for ease of review? the other 3 changes this PR makes change no logic.

@debris
Copy link
Collaborator Author

debris commented Feb 27, 2016

@gavofyork

it's not especially clear that no logic has been added/changed. maybe add a commentary so we know which functions have been moved where?

  • moved blockchain.rs to blockchain/blockchain.rs
  • added BlockInfo and BlockLocation structs (blockchain/block_info.rs). They replaced unreadable if statements and comments
  • split block_to_extras_update into 6 functions. Each of this functions updates only one extras type.
    • block_info
    • prepare_block_hashes_update
    • prepare_block_details_update
    • prepare_block_receipts_update
    • prepare_transaction_addresses_update
    • prepare_block_blooms_update
  • moved BloomIndexer and it's tests to blockchain/bloom_indexer.rs
  • moved BestBlock to blockchain/best_block.rs
  • moved CacheSize to blockchain/cache.rs
  • moved TreeRoute to blockchain/tree_route.rs`
  • moved ExtrasUpdate to blockchain/update.rs
  • removed tree_route_aux function which was not needed (previously used in block_to_extras_update function)

@gavofyork

can "fixed cleaning up blockchain caches" be placed in a separate PR for ease of review? the other 3 changes this PR makes change no logic.

These are just two lines. block hashes and transaction addresses.

@arkpar

There should be a test that checks if the blockchain cache has been updated correctly after a fork

There are already few tests which check updating block_details && blocks_blooms after a fork. I think it's best to add more test for forking in next prs, cause these tests will make this pr significantly bigger.

@debris debris added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Feb 27, 2016
@gavofyork gavofyork added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 27, 2016
@gavofyork
Copy link
Contributor

ok to merge on my end, though i'd like to see the fork tests and removal of asserts in the not-too-distant future. perhaps introduce an issue to track?

@debris
Copy link
Collaborator Author

debris commented Feb 27, 2016

I've added #529 and #530

@debris
Copy link
Collaborator Author

debris commented Feb 27, 2016

Started working on sweeping panics in the other branch. Does tree_route function look better? ethcore/parity@8c61131#diff-422bab2793f9fb234587f1dadcf690d3R350

@NikVolf NikVolf added A8-looksgood 🦄 Pull request is reviewed well. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Feb 29, 2016
NikVolf added a commit that referenced this pull request Feb 29, 2016
@NikVolf NikVolf merged commit f0c11fa into master Feb 29, 2016
@debris debris deleted the blockchain_cleanup branch March 10, 2016 09:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants