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

protection from adding empty traces && assertion in traces db #1994

Merged
merged 2 commits into from
Aug 24, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ethcore/src/trace/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
/// Traces of import request's enacted blocks are expected to be already in database
/// or to be the currently inserted trace.
fn import(&self, batch: &DBTransaction, request: ImportRequest) {
// valid (canon): retracted 0, enacted 1 => false, true,
// valid (branch): retracted 0, enacted 0 => false, false,
// valid (bbcc): retracted 1, enacted 1 => true, true,
// invalid: retracted 1, enacted 0 => true, false,
let ret = request.retracted != 0;
let ena = !request.enacted.is_empty();
assert!((!ret && ena) || (ret == ena));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't assert!(!(ret && !ena)); work and be more in-line to what is written in comment?
(if I understand correctly there is only one invalid case - ret == true && ena == false - so negation will cover all valid cases)

I'm I missing something?

// fast return if tracing is disabled
if !self.tracing_enabled() {
return;
Expand All @@ -278,7 +285,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
}

// now let's rebuild the blooms
{
if !request.enacted.is_empty() {
let range_start = request.block_number as Number + 1 - request.enacted.len();
let range_end = range_start + request.retracted;
let replaced_range = range_start..range_end;
Expand Down