zathras-crypto / omnicore

mastercore info

Home Page:mastercoin.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initialization: out of order blocks

dexX7 opened this issue · comments

commented

To pick up the discussion of b1827eb and mastercoin-MSC#286:

With Bitcoin Core 0.10 there is a chance that blocks are stored out of order which can create unexpected behavior or crashes.

We are able to detect out of order stored blocks, but it is still not sure where this check should be done.

#40 moves the check and I tested it with empty datadir as well as a datadir with blocks, but a second test can't hurt.

One point I'm not sure about:

bool CheckForOutOfOrderBlockStorage()
{
    AssertLockHeld(cs_main);
    // ...
}

Is this lock usage correct? I tested it once with LOCK(cs_main); instead and it worked, but it's over my head.

AssertLockHeld by using an assert will terminate the code (via abort()) if the lock can't be held - I'm not 100% on the correct usage either, the assert usage was the approach used in printBlockTree (the original inspiration for CheckForOutOfOrderBlockStorage())

commented

Ah perfect. I was basically wondering where the lock is initially set, but PrintBlockTree() is called on the same level as our order detection, so this should probably be fine.

commented

Argh.. sorry. Even though I tested several times that it works (as of: throws no errors around), I did not check whether it actually fails. Turns out #40 basically does nothing, because the chain is still empty at this point.

The chain only appears to be fully loaded at the point where the detection was done earlier. The issues mentioned in discussions linked above are thus not solved at this point.

Shoot - I also tested this against a 0.9 blockchain :(

commented

After thinking more about it, we could either do a major surgery of the whole initialization, or just stick to how it's handled right now. I favor the later, since we're dealing with edge cases, and everything is properly guarded.