HomePhabricator

Improve chainstate/blockindex disk writing policy
51ce901aa3caUnpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

Improve chainstate/blockindex disk writing policy

There are 3 pieces of data that are maintained on disk. The actual block
and undo data, the block index (which can refer to positions on disk),
and the chainstate (which refers to the best block hash).

Earlier, there was no guarantee that blocks were written to disk before
block index entries referring to them were written. This commit introduces
dirty flags for block index data, and delays writing entries until the actual
block data is flushed.

With this stricter ordering in writes, it is now safe to not always flush
after every block, so there is no need for the IsInitialBlockDownload()
check there - instead we just write whenever enough time has passed or
the cache size grows too large. Also updating the wallet's best known block
is delayed until this is done, otherwise the wallet may end up referring to an
unknown block.

In addition, only do a write inside the block processing loop if necessary
(because of cache size exceeded). Otherwise, move the writing to a point
after processing is done, after relaying.

Details

Provenance
Pieter Wuille <pieter.wuille@gmail.com>Authored on Nov 7 2014, 10:38
deadalnixPushed on May 14 2017, 22:04
Parents
rABCf24bcce2ac3e: Merge pull request #1816
Branches
Unknown
Tags
Unknown

Event Timeline

Pieter Wuille <pieter.wuille@gmail.com> committed rABC51ce901aa3ca: Improve chainstate/blockindex disk writing policy (authored by Pieter Wuille <pieter.wuille@gmail.com>).Nov 24 2014, 14:15