From 17f15678d399275a093be496914c59b463929fe4 Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Fri, 25 Jul 2014 21:21:10 -0400 Subject: Fixed a bug with index bounds checking --- src/txmempool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 164e2741a2..0725441fba 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -299,7 +299,7 @@ public: size_t nPrevSize = 0; for (int i = 0; i < nBlocksToConfirm; i++) nPrevSize += history.at(i).PrioritySamples(); - size_t index = min(nPrevSize + nBucketSize/2, sortedFeeSamples.size()-1); + size_t index = min(nPrevSize + nBucketSize/2, sortedPrioritySamples.size()-1); return sortedPrioritySamples[index]; } -- cgit v1.2.3 From 961ae93c85cee96c5dca3d44fbfb829243607f65 Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Fri, 25 Jul 2014 21:29:54 -0400 Subject: Fix minor bug which only affected log messages. --- src/txmempool.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 0725441fba..a06de7a947 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -225,6 +225,12 @@ public: seenTxConfirm(feeRate, minRelayFee, dPriority, i); } } + + //After new samples are added, we have to clear the sorted lists, + //so they'll be resorted the next time someone asks for an estimate + sortedFeeSamples.clear(); + sortedPrioritySamples.clear(); + for (size_t i = 0; i < history.size(); i++) { if (history[i].FeeSamples() + history[i].PrioritySamples() > 0) LogPrint("estimatefee", "estimates: for confirming within %d blocks based on %d/%d samples, fee=%s, prio=%g\n", @@ -232,8 +238,6 @@ public: history[i].FeeSamples(), history[i].PrioritySamples(), estimateFee(i+1).ToString(), estimatePriority(i+1)); } - sortedFeeSamples.clear(); - sortedPrioritySamples.clear(); } // Can return CFeeRate(0) if we don't have any data for that many blocks back. nBlocksToConfirm is 1 based. -- cgit v1.2.3 From e59441f0863d20c6f205c4854a37507267183863 Mon Sep 17 00:00:00 2001 From: Alex Morcos Date: Tue, 29 Jul 2014 00:09:57 -0400 Subject: Process fee estimate file into temporary vector first to let sanity checking complete. --- src/txmempool.cpp | 19 +++++++++++++++---- 1 file 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 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); } }; -- cgit v1.2.3