Skip to content

Commit

Permalink
Merge pull request #1742 from skalenetwork/bug/1199-eth-syncing
Browse files Browse the repository at this point in the history
1199 eth syncing
  • Loading branch information
DmytroNazarenko authored Dec 8, 2023
2 parents 1c975d5 + 1af8e4d commit 2fcb104
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
7 changes: 3 additions & 4 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,9 @@ Transactions Client::pending() const {
}

SyncStatus Client::syncStatus() const {
// TODO implement this when syncing will be needed
SyncStatus s;
s.startBlockNumber = s.currentBlockNumber = s.highestBlockNumber = 0;
return s;
if ( !m_skaleHost )
BOOST_THROW_EXCEPTION( std::runtime_error( "SkaleHost was not initialized" ) );
return m_skaleHost->syncStatus();
}

TransactionSkeleton Client::populateTransactionWithDefaults( TransactionSkeleton const& _t ) const {
Expand Down
15 changes: 15 additions & 0 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,21 @@ u256 SkaleHost::getBlockRandom() const {
return m_consensus->getRandomForBlockId( m_client.number() );
}

dev::eth::SyncStatus SkaleHost::syncStatus() const {
if ( !m_consensus )
BOOST_THROW_EXCEPTION( std::runtime_error( "Consensus was not initialized" ) );
auto syncInfo = m_consensus->getSyncInfo();
dev::eth::SyncStatus syncStatus;
// SKALE: catchup downloads blocks with transactions, then the node executes them
// we don't download state changes separately
syncStatus.state = syncInfo.isSyncing ? dev::eth::SyncState::Blocks : dev::eth::SyncState::Idle;
syncStatus.startBlockNumber = syncInfo.startingBlock;
syncStatus.currentBlockNumber = syncInfo.currentBlock;
syncStatus.highestBlockNumber = syncInfo.highestBlock;
syncStatus.majorSyncing = syncInfo.isSyncing;
return syncStatus;
}

std::map< std::string, uint64_t > SkaleHost::getConsensusDbUsage() const {
return m_consensus->getConsensusDbUsage();
}
Expand Down
2 changes: 2 additions & 0 deletions libethereum/SkaleHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

namespace dev {
namespace eth {
struct SyncStatus;
class Client;
class TransactionQueue;
class BlockHeader;
Expand Down Expand Up @@ -123,6 +124,7 @@ class SkaleHost {

dev::u256 getGasPrice() const;
dev::u256 getBlockRandom() const;
dev::eth::SyncStatus syncStatus() const;
std::map< std::string, uint64_t > getConsensusDbUsage() const;
std::array< std::string, 4 > getIMABLSPublicKey() const;

Expand Down
27 changes: 18 additions & 9 deletions libweb3jsonrpc/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,24 @@ Json::Value Eth::eth_getWork() {
}

Json::Value Eth::eth_syncing() {
dev::eth::SyncStatus sync = client()->syncStatus();
if ( sync.state == SyncState::Idle || !sync.majorSyncing )
return Json::Value( false );

Json::Value info( Json::objectValue );
info["startingBlock"] = sync.startBlockNumber;
info["highestBlock"] = sync.highestBlockNumber;
info["currentBlock"] = sync.currentBlockNumber;
return info;
try {
auto client = this->client();
if ( !client )
BOOST_THROW_EXCEPTION( std::runtime_error( "Client was not initialized" ) );

// ask consensus whether the node is in catchup mode
dev::eth::SyncStatus sync = client->syncStatus();
if ( !sync.majorSyncing )
return Json::Value( false );

Json::Value info( Json::objectValue );
info["startingBlock"] = sync.startBlockNumber;
info["highestBlock"] = sync.highestBlockNumber;
info["currentBlock"] = sync.currentBlockNumber;
return info;
} catch ( const Exception& e ) {
BOOST_THROW_EXCEPTION( jsonrpc::JsonRpcException( e.what() ) );
}
}

string Eth::eth_chainId() {
Expand Down

0 comments on commit 2fcb104

Please sign in to comment.