diff options
author | Alex Morcos <morcos@chaincode.com> | 2014-07-29 00:09:57 -0400 |
---|---|---|
committer | Alex Morcos <morcos@chaincode.com> | 2014-07-29 13:58:08 -0400 |
commit | e59441f0863d20c6f205c4854a37507267183863 (patch) | |
tree | f965485719127f07219f9fe7bf3398662360c6b4 | |
parent | 961ae93c85cee96c5dca3d44fbfb829243607f65 (diff) |
Process fee estimate file into temporary vector first to let sanity checking complete.
-rw-r--r-- | src/txmempool.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp index a06de7a947..29924fff09 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -206,7 +206,7 @@ public: } if ((delta-1) >= (int)history.size()) delta = history.size(); // Last bucket is catch-all - entriesByConfirmations[delta-1].push_back(&entry); + entriesByConfirmations.at(delta-1).push_back(&entry); } for (size_t i = 0; i < entriesByConfirmations.size(); i++) { @@ -319,16 +319,27 @@ public: void Read(CAutoFile& filein, const CFeeRate& minRelayFee) { - filein >> nBestSeenHeight; + int nFileBestSeenHeight; + filein >> nFileBestSeenHeight; size_t numEntries; filein >> numEntries; - history.clear(); + if (numEntries <= 0 || numEntries > 10000) + throw runtime_error("Corrupt estimates file. Must have between 1 and 10k entires."); + + std::vector<CBlockAverage> fileHistory; + for (size_t i = 0; i < numEntries; i++) { CBlockAverage entry; entry.Read(filein, minRelayFee); - history.push_back(entry); + fileHistory.push_back(entry); } + + //Now that we've processed the entire fee estimate data file and not + //thrown any errors, we can copy it to our history + nBestSeenHeight = nFileBestSeenHeight; + history = fileHistory; + assert(history.size() > 0); } }; |