diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-09-08 12:51:43 -0400 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2011-12-01 23:20:32 -0500 |
commit | 5d901f1ba0b2f4444e484b9cb3db8d86c428af3f (patch) | |
tree | 4e4a49112ebe6ba6f2cfcc8442de1e410a13732a /src/checkpoints.cpp | |
parent | 0e6425da4a29d6944e7edce85535725e1f963e2c (diff) | |
download | bitcoin-5d901f1ba0b2f4444e484b9cb3db8d86c428af3f.tar.xz |
Orphan block fill-up-memory attack prevention
Diffstat (limited to 'src/checkpoints.cpp')
-rw-r--r-- | src/checkpoints.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 4419a06c83..c7e054df37 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -2,16 +2,23 @@ // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. -#include "checkpoints.h" -#include "uint256.h" -#include "util.h" - #include <boost/assign/list_of.hpp> // for 'map_list_of()' +#include <boost/foreach.hpp> + +#include "headers.h" +#include "checkpoints.h" namespace Checkpoints { typedef std::map<int, uint256> MapCheckpoints; + // + // What makes a good checkpoint block? + // + Is surrounded by blocks with reasonable timestamps + // (no blocks before with a timestamp after, none after with + // timestamp before) + // + Contains no strange transactions + // static MapCheckpoints mapCheckpoints = boost::assign::map_list_of ( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) @@ -36,8 +43,23 @@ namespace Checkpoints int GetTotalBlocksEstimate() { - if (fTestNet) return 0; // Testnet has no checkpoints + if (fTestNet) return 0; return mapCheckpoints.rbegin()->first; } + + CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex) + { + if (fTestNet) return NULL; + + int64 nResult; + BOOST_REVERSE_FOREACH(const MapCheckpoints::value_type& i, mapCheckpoints) + { + const uint256& hash = i.second; + std::map<uint256, CBlockIndex*>::const_iterator t = mapBlockIndex.find(hash); + if (t != mapBlockIndex.end()) + return t->second; + } + return NULL; + } } |