Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Fix downloading snapshot in case we don't have already imported snaps…
Browse files Browse the repository at this point in the history
…hot (snapshotStorage is nullptr then)
  • Loading branch information
gumb0 committed Jan 9, 2018
1 parent 6a99eb1 commit 02ff5ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
7 changes: 4 additions & 3 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ void Client::init(p2p::Host* _extNet, fs::path const& _dbPath, fs::path const& _

// create Warp capability if we either download snapshot or can give out snapshot
auto const importedSnapshot = importedSnapshotPath(_dbPath, bc().genesisHash());
if (!_snapshotDownloadPath.empty() || fs::exists(importedSnapshot))
bool const importedSnapshotExists = fs::exists(importedSnapshot);
if (!_snapshotDownloadPath.empty() || importedSnapshotExists)
{
std::shared_ptr<SnapshotStorageFace> snapshotStorage =
createSnapshotStorage(importedSnapshot);
std::shared_ptr<SnapshotStorageFace> snapshotStorage(
importedSnapshotExists ? createSnapshotStorage(importedSnapshot) : nullptr);
m_warpHost = _extNet->registerCapability(make_shared<WarpHostCapability>(
bc(), _networkId, _snapshotDownloadPath, snapshotStorage));
}
Expand Down
1 change: 0 additions & 1 deletion libethereum/WarpHostCapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "WarpHostCapability.h"
#include "BlockChain.h"
#include "SnapshotStorage.h"

#include <boost/fiber/all.hpp>

Expand Down
29 changes: 19 additions & 10 deletions libethereum/WarpPeerCapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,26 @@ void WarpPeerCapability::init(unsigned _hostProtocolVersion, u256 _hostNetworkId
std::shared_ptr<SnapshotStorageFace const> _snapshot,
std::weak_ptr<WarpPeerObserverFace> _observer)
{
assert(_snapshot);
m_snapshot = std::move(_snapshot);

bytes const snapshotManifest(m_snapshot->readManifest());
RLP manifest(snapshotManifest);
if (manifest.itemCount() != 6)
BOOST_THROW_EXCEPTION(InvalidSnapshotManifest());
u256 const snapshotBlockNumber = manifest[4].toInt<u256>(RLP::VeryStrict);
h256 const snapshotBlockHash = manifest[5].toHash<h256>(RLP::VeryStrict);
u256 snapshotBlockNumber;
h256 snapshotBlockHash;
if (_snapshot)
{
m_snapshot = std::move(_snapshot);

bytes const snapshotManifest(m_snapshot->readManifest());
RLP manifest(snapshotManifest);
if (manifest.itemCount() != 6)
BOOST_THROW_EXCEPTION(InvalidSnapshotManifest());
snapshotBlockNumber = manifest[4].toInt<u256>(RLP::VeryStrict);
snapshotBlockHash = manifest[5].toHash<h256>(RLP::VeryStrict);
}

requestStatus(_hostProtocolVersion, _hostNetworkId, _chainTotalDifficulty, _chainCurrentHash,
_chainGenesisHash, snapshotBlockHash, snapshotBlockNumber);
}

bool WarpPeerCapability::interpret(unsigned _id, RLP const& _r)
{
assert(m_snapshot);
std::shared_ptr<WarpPeerObserverFace> observer(m_observer.lock());
if (!observer)
return false;
Expand Down Expand Up @@ -92,13 +95,19 @@ bool WarpPeerCapability::interpret(unsigned _id, RLP const& _r)
}
case GetSnapshotManifest:
{
if (!m_snapshot)
return false;

RLPStream s;
prep(s, SnapshotManifest, 1).appendRaw(m_snapshot->readManifest());
sealAndSend(s);
break;
}
case GetSnapshotData:
{
if (!m_snapshot)
return false;

const h256 chunkHash = _r[0].toHash<h256>(RLP::VeryStrict);

RLPStream s;
Expand Down

0 comments on commit 02ff5ef

Please sign in to comment.