diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index d29a8c6d8..d28474a9d 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -158,7 +158,7 @@ void BlockChain::import(bytes const& _block, Overlay const& _db) // Check block doesn't already exist first! if (details(newHash)) { - clog(BlockChainChat) << newHash << ": Not new."; + clog(BlockChainNote) << newHash << ": Not new."; throw AlreadyHaveBlock(); } @@ -166,11 +166,19 @@ void BlockChain::import(bytes const& _block, Overlay const& _db) auto pd = details(bi.parentHash); if (!pd) { - clog(BlockChainChat) << newHash << ": Unknown parent " << bi.parentHash; + clog(BlockChainNote) << newHash << ": Unknown parent " << bi.parentHash; // We don't know the parent (yet) - discard for now. It'll get resent to us if we find out about its ancestry later on. throw UnknownParent(); } + // Check it's not crazy + if (bi.timestamp > (u256)time(0)) + { + clog(BlockChainNote) << newHash << ": Future time " << bi.timestamp << " (now at " << time(0) << ")"; + // We don't know the parent (yet) - discard for now. It'll get resent to us if we find out about its ancestry later on. + throw FutureTime(); + } + clog(BlockChainNote) << "Attempting import of " << newHash << "..."; u256 td; diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index b295253c7..4c1500b06 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -58,6 +58,7 @@ class Overlay; class AlreadyHaveBlock: public std::exception {}; class UnknownParent: public std::exception {}; +class FutureTime: public std::exception {}; struct BlockChainChat: public LogChannel { static const char* name() { return "-B-"; } static const int verbosity = 7; }; struct BlockChainNote: public LogChannel { static const char* name() { return "=B="; } static const int verbosity = 4; };