-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
I recommend opening |
needs a rebase. also it's quite big - i presume no logic has been added in this PR? |
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)); |
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.
this probably shouldn't panic.
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.
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.
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.
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.
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.
I see. I will fix it in next prs.
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). |
There should be a test that checks if the blockchain cache has been updated correctly after a fork |
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.
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. |
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? |
Started working on sweeping panics in the other branch. Does |
changes:
block_to_extras_update
function into 6 smaller functions. Code is cleaner, more maintainable and readable.blockchain.rs
into few separate files. This file was becoming a behemoth.