Exemple #1
0
tuple<ImportRoute, bool, unsigned> BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max)
{
//	_bq.tick(*this);

	VerifiedBlocks blocks;
	_bq.drain(blocks, _max);

	h256s fresh;
	h256s dead;
	h256s badBlocks;
	Transactions goodTransactions;
	unsigned count = 0;
	for (VerifiedBlock const& block: blocks)
	{
		do {
			try
			{
				// Nonce & uncle nonces already verified in verification thread at this point.
				ImportRoute r;
				DEV_TIMED_ABOVE("Block import " + toString(block.verified.info.number()), 500)
					r = import(block.verified, _stateDB, (ImportRequirements::Everything & ~ImportRequirements::ValidSeal & ~ImportRequirements::CheckUncles) != 0);
				fresh += r.liveBlocks;
				dead += r.deadBlocks;
				goodTransactions.reserve(goodTransactions.size() + r.goodTranactions.size());
				std::move(std::begin(r.goodTranactions), std::end(r.goodTranactions), std::back_inserter(goodTransactions));
				++count;
			}
			catch (dev::eth::UnknownParent)
			{
				cwarn << "ODD: Import queue contains block with unknown parent.";// << LogTag::Error << boost::current_exception_diagnostic_information();
				// NOTE: don't reimport since the queue should guarantee everything in the right order.
				// Can't continue - chain bad.
				badBlocks.push_back(block.verified.info.hash());
			}
			catch (dev::eth::FutureTime)
			{
				cwarn << "ODD: Import queue contains a block with future time.";
				this_thread::sleep_for(chrono::seconds(1));
				continue;
			}
			catch (dev::eth::TransientError)
			{
				this_thread::sleep_for(chrono::milliseconds(100));
				continue;
			}
			catch (Exception& ex)
			{
//				cnote << "Exception while importing block. Someone (Jeff? That you?) seems to be giving us dodgy blocks!";// << LogTag::Error << diagnostic_information(ex);
				if (m_onBad)
					m_onBad(ex);
				// NOTE: don't reimport since the queue should guarantee everything in the right order.
				// Can't continue - chain  bad.
				badBlocks.push_back(block.verified.info.hash());
			}
		} while (false);
	}
	return make_tuple(ImportRoute{dead, fresh, goodTransactions}, _bq.doneDrain(badBlocks), count);
}
Exemple #2
0
Json::Value toJson(dev::eth::BlockInfo const& _bi, BlockDetails const& _bd, UncleHashes const& _us, Transactions const& _ts)
{
    Json::Value res = toJson(_bi);
    if (_bi)
    {
        res["totalDifficulty"] = toJS(_bd.totalDifficulty);
        res["uncles"] = Json::Value(Json::arrayValue);
        for (h256 h: _us)
            res["uncles"].append(toJS(h));
        res["transactions"] = Json::Value(Json::arrayValue);
        for (unsigned i = 0; i < _ts.size(); i++)
            res["transactions"].append(toJson(_ts[i], std::make_pair(_bi.hash(), i), (BlockNumber)_bi.number));
    }
    return res;
}