diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-11-07 02:38:35 -0800 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-11-24 15:15:40 +0100 |
commit | 51ce901aa3ca8326bc3fa96e6cc95453c695d4d6 (patch) | |
tree | 96bb50b6b9ff19cd4c3ad64de004008707201234 /src/main.h | |
parent | f24bcce2ac3e049142ff077c0de5e40a52e59b5e (diff) |
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.
Diffstat (limited to 'src/main.h')
-rw-r--r-- | src/main.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/main.h b/src/main.h index b49f0a06eb..c0d6412528 100644 --- a/src/main.h +++ b/src/main.h @@ -94,6 +94,8 @@ static const unsigned int MAX_HEADERS_RESULTS = 2000; * degree of disordering of blocks on disk (which make reindexing and in the future perhaps pruning * harder). We'll probably want to make this a per-peer adaptive value at some point. */ static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024; +/** Time to wait (in seconds) between writing blockchain state to disk. */ +static const unsigned int DATABASE_WRITE_INTERVAL = 3600; /** "reject" message codes **/ static const unsigned char REJECT_MALFORMED = 0x01; @@ -201,6 +203,8 @@ bool AbortNode(const std::string &msg, const std::string &userMessage=""); bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats); /** Increase a node's misbehavior score. */ void Misbehaving(NodeId nodeid, int howmuch); +/** Flush all state, indexes and buffers to disk. */ +void FlushStateToDisk(); /** (try to) add transaction to memory pool **/ |